1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * 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 and
16 * limitations under the License.
17 */
18 package org.apache.giraph.conf;
19
20 import org.apache.giraph.graph.GraphType;
21 import org.apache.hadoop.conf.Configuration;
22
23 /**
24 * An enum stored per user graph type
25 *
26 * @param <T> Enum type
27 */
28 public class PerGraphTypeEnum<T extends Enum<T>> {
29 /** data for vertex id */
30 private T vertexId;
31 /** data for vertex value */
32 private T vertexValue;
33 /** data for edge value */
34 private T edgeValue;
35 /** data for outgoing message */
36 private T outgoingMessage;
37
38 /**
39 * Create from options and configuration
40 *
41 * @param <T> enum type
42 * @param options pre user graph type options
43 * @param conf configuration
44 * @return new object
45 */
46 public static <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);
50 return pgte;
51 }
52
53 /**
54 * Set data from per user graph type set of options
55 *
56 * @param options per user graph type options
57 * @param conf Configuration
58 */
59 public void 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 }
66
67 /**
68 * Set the vertex id data from the option
69 *
70 * @param option EnumConfOption option to use
71 * @param conf Configuration
72 */
73 public void setVertexId(EnumConfOption<T> option, Configuration conf) {
74 vertexId = option.get(conf);
75 }
76
77 /**
78 * Set the vertex value data from the option
79 *
80 * @param option EnumConfOption option to use
81 * @param conf Configuration
82 */
83 public void setVertexValue(EnumConfOption<T> option, Configuration conf) {
84 vertexValue = option.get(conf);
85 }
86
87 /**
88 * Set the edge value data from the option
89 *
90 * @param option EnumConfOption option to use
91 * @param conf Configuration
92 */
93 public void setEdgeValue(EnumConfOption<T> option, Configuration conf) {
94 edgeValue = option.get(conf);
95 }
96
97 /**
98 * Set the outgoing message value data from the option
99 *
100 * @param option EnumConfOption option to use
101 * @param conf Configuration
102 */
103 public void setOutgoingMessage(EnumConfOption<T> option, Configuration conf) {
104 outgoingMessage = option.get(conf);
105 }
106
107 /**
108 * Get data for given GraphType
109 *
110 * @param graphType GraphType
111 * @return data for given graph type
112 */
113 public T get(GraphType graphType) {
114 switch (graphType) {
115 case VERTEX_ID:
116 return vertexId;
117 case VERTEX_VALUE:
118 return vertexValue;
119 case EDGE_VALUE:
120 return edgeValue;
121 case OUTGOING_MESSAGE_VALUE:
122 return outgoingMessage;
123 default:
124 throw new IllegalArgumentException(
125 "Don't know how to handle GraphType " + graphType);
126 }
127 }
128
129 public T getEdgeValue() {
130 return edgeValue;
131 }
132
133 public T getOutgoingMessage() {
134 return outgoingMessage;
135 }
136
137 public T getVertexId() {
138 return vertexId;
139 }
140
141 public T getVertexValue() {
142 return vertexValue;
143 }
144 }