1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18package org.apache.giraph.conf;
1920import org.apache.giraph.graph.GraphType;
21import org.apache.hadoop.conf.Configuration;
2223/**24 * An enum stored per user graph type25 *26 * @param <T> Enum type27 */28publicclass PerGraphTypeEnum<T extends Enum<T>> {
29/** data for vertex id */30private T vertexId;
31/** data for vertex value */32private T vertexValue;
33/** data for edge value */34private T edgeValue;
35/** data for outgoing message */36private T outgoingMessage;
3738/**39 * Create from options and configuration40 *41 * @param <T> enum type42 * @param options pre user graph type options43 * @param conf configuration44 * @return new object45 */46publicstatic <T extends Enum<T>> PerGraphTypeEnum<T> readFromConf(
47 PerGraphTypeEnumConfOption<T> options, Configuration conf) {
48 PerGraphTypeEnum<T> pgte = new PerGraphTypeEnum<T>();
49 pgte.setFrom(options, conf);
50return pgte;
51 }
5253/**54 * Set data from per user graph type set of options55 *56 * @param options per user graph type options57 * @param conf Configuration58 */59publicvoid setFrom(PerGraphTypeEnumConfOption<T> options,
60 Configuration conf) {
61 setVertexId(options.getVertexId(), conf);
62 setVertexValue(options.getVertexValue(), conf);
63 setEdgeValue(options.getEdgeValue(), conf);
64 setOutgoingMessage(options.getOutgoingMessage(), conf);
65 }
6667/**68 * Set the vertex id data from the option69 *70 * @param option EnumConfOption option to use71 * @param conf Configuration72 */73publicvoid setVertexId(EnumConfOption<T> option, Configuration conf) {
74 vertexId = option.get(conf);
75 }
7677/**78 * Set the vertex value data from the option79 *80 * @param option EnumConfOption option to use81 * @param conf Configuration82 */83publicvoid setVertexValue(EnumConfOption<T> option, Configuration conf) {
84 vertexValue = option.get(conf);
85 }
8687/**88 * Set the edge value data from the option89 *90 * @param option EnumConfOption option to use91 * @param conf Configuration92 */93publicvoid setEdgeValue(EnumConfOption<T> option, Configuration conf) {
94 edgeValue = option.get(conf);
95 }
9697/**98 * Set the outgoing message value data from the option99 *100 * @param option EnumConfOption option to use101 * @param conf Configuration102 */103publicvoid setOutgoingMessage(EnumConfOption<T> option, Configuration conf) {
104 outgoingMessage = option.get(conf);
105 }
106107/**108 * Get data for given GraphType109 *110 * @param graphType GraphType111 * @return data for given graph type112 */113public T get(GraphType graphType) {
114switch (graphType) {
115case VERTEX_ID:
116return vertexId;
117case VERTEX_VALUE:
118return vertexValue;
119case EDGE_VALUE:
120return edgeValue;
121case OUTGOING_MESSAGE_VALUE:
122return outgoingMessage;
123default:
124thrownew IllegalArgumentException(
125"Don't know how to handle GraphType " + graphType);
126 }
127 }
128129public T getEdgeValue() {
130return edgeValue;
131 }
132133public T getOutgoingMessage() {
134return outgoingMessage;
135 }
136137public T getVertexId() {
138return vertexId;
139 }
140141public T getVertexValue() {
142return vertexValue;
143 }
144 }