1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.giraph.types; |
19 | |
|
20 | |
import com.google.common.base.MoreObjects; |
21 | |
import org.apache.hadoop.io.BooleanWritable; |
22 | |
import org.apache.hadoop.io.ByteWritable; |
23 | |
import org.apache.hadoop.io.DoubleWritable; |
24 | |
import org.apache.hadoop.io.FloatWritable; |
25 | |
import org.apache.hadoop.io.IntWritable; |
26 | |
import org.apache.hadoop.io.LongWritable; |
27 | |
import org.apache.hadoop.io.Writable; |
28 | |
|
29 | |
import com.google.common.base.Objects; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class JavaWritablePair<W extends Writable, J> { |
38 | |
|
39 | |
public static final JavaWritablePair<BooleanWritable, Boolean> |
40 | 0 | BOOLEAN_BOOLEAN_WRITABLE = create(BooleanWritable.class, Boolean.class); |
41 | |
|
42 | |
public static final JavaWritablePair<ByteWritable, Byte> |
43 | 0 | BYTE_BYTE_WRITABLE = create(ByteWritable.class, Byte.class); |
44 | |
|
45 | |
public static final JavaWritablePair<IntWritable, Byte> |
46 | 0 | BYTE_INT_WRITABLE = create(IntWritable.class, Byte.class); |
47 | |
|
48 | |
public static final JavaWritablePair<LongWritable, Byte> |
49 | 0 | BYTE_LONG_WRITABLE = create(LongWritable.class, Byte.class); |
50 | |
|
51 | |
public static final JavaWritablePair<FloatWritable, Double> |
52 | 0 | DOUBLE_FLOAT_WRITABLE = create(FloatWritable.class, Double.class); |
53 | |
|
54 | |
public static final JavaWritablePair<DoubleWritable, Double> |
55 | 0 | DOUBLE_DOUBLE_WRITABLE = create(DoubleWritable.class, Double.class); |
56 | |
|
57 | |
public static final JavaWritablePair<FloatWritable, Float> |
58 | 0 | FLOAT_FLOAT_WRITABLE = create(FloatWritable.class, Float.class); |
59 | |
|
60 | |
public static final JavaWritablePair<DoubleWritable, Float> |
61 | 0 | FLOAT_DOUBLE_WRITABLE = create(DoubleWritable.class, Float.class); |
62 | |
|
63 | |
public static final JavaWritablePair<ByteWritable, Integer> |
64 | 0 | INT_BYTE_WRITABLE = create(ByteWritable.class, Integer.class); |
65 | |
|
66 | |
public static final JavaWritablePair<IntWritable, Integer> |
67 | 0 | INT_INT_WRITABLE = create(IntWritable.class, Integer.class); |
68 | |
|
69 | |
public static final JavaWritablePair<LongWritable, Integer> |
70 | 0 | INT_LONG_WRITABLE = create(LongWritable.class, Integer.class); |
71 | |
|
72 | |
public static final JavaWritablePair<ByteWritable, Long> |
73 | 0 | LONG_BYTE_WRITABLE = create(ByteWritable.class, Long.class); |
74 | |
|
75 | |
public static final JavaWritablePair<IntWritable, Long> |
76 | 0 | LONG_INT_WRITABLE = create(IntWritable.class, Long.class); |
77 | |
|
78 | |
public static final JavaWritablePair<LongWritable, Long> |
79 | 0 | LONG_LONG_WRITABLE = create(LongWritable.class, Long.class); |
80 | |
|
81 | |
public static final JavaWritablePair<ByteWritable, Short> |
82 | 0 | SHORT_BYTE_WRITABLE = create(ByteWritable.class, Short.class); |
83 | |
|
84 | |
public static final JavaWritablePair<IntWritable, Short> |
85 | 0 | SHORT_INT_WRITABLE = create(IntWritable.class, Short.class); |
86 | |
|
87 | |
public static final JavaWritablePair<LongWritable, Short> |
88 | 0 | SHORT_LONG_WRITABLE = create(LongWritable.class, Short.class); |
89 | |
|
90 | |
|
91 | |
private final Class<J> javaClass; |
92 | |
|
93 | |
private final Class<W> writableClass; |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | 0 | private JavaWritablePair(Class<W> writableClass, Class<J> javaClass) { |
102 | 0 | this.javaClass = javaClass; |
103 | 0 | this.writableClass = writableClass; |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public static <W extends Writable, J> JavaWritablePair<W, J> create( |
116 | |
Class<W> writableClass, Class<J> javaClass) { |
117 | 0 | return new JavaWritablePair<W, J>(writableClass, javaClass); |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public boolean equals(Object obj) { |
122 | 0 | if (this == obj) { |
123 | 0 | return true; |
124 | |
} |
125 | 0 | if (obj instanceof JavaWritablePair) { |
126 | 0 | JavaWritablePair other = (JavaWritablePair) obj; |
127 | 0 | return Objects.equal(javaClass, other.javaClass) && |
128 | 0 | Objects.equal(writableClass, other.writableClass); |
129 | |
} |
130 | 0 | return false; |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public int hashCode() { |
135 | 0 | return Objects.hashCode(javaClass, writableClass); |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public String toString() { |
140 | 0 | return MoreObjects.toStringHelper(this) |
141 | 0 | .add("javaClass", javaClass.getSimpleName()) |
142 | 0 | .add("writableClass", writableClass.getSimpleName()) |
143 | 0 | .toString(); |
144 | |
} |
145 | |
|
146 | |
public Class<J> getJavaClass() { |
147 | 0 | return javaClass; |
148 | |
} |
149 | |
|
150 | |
public Class<W> getWritableClass() { |
151 | 0 | return writableClass; |
152 | |
} |
153 | |
} |