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 org.apache.hadoop.io.Writable; |
21 | |
|
22 | |
import com.google.common.collect.Maps; |
23 | |
|
24 | |
import java.util.Map; |
25 | |
|
26 | |
import static org.apache.giraph.types.JavaWritablePair.BOOLEAN_BOOLEAN_WRITABLE; |
27 | |
import static org.apache.giraph.types.JavaWritablePair.BYTE_BYTE_WRITABLE; |
28 | |
import static org.apache.giraph.types.JavaWritablePair.BYTE_INT_WRITABLE; |
29 | |
import static org.apache.giraph.types.JavaWritablePair.BYTE_LONG_WRITABLE; |
30 | |
import static org.apache.giraph.types.JavaWritablePair.DOUBLE_DOUBLE_WRITABLE; |
31 | |
import static org.apache.giraph.types.JavaWritablePair.FLOAT_DOUBLE_WRITABLE; |
32 | |
import static org.apache.giraph.types.JavaWritablePair.FLOAT_FLOAT_WRITABLE; |
33 | |
import static org.apache.giraph.types.JavaWritablePair.INT_INT_WRITABLE; |
34 | |
import static org.apache.giraph.types.JavaWritablePair.INT_LONG_WRITABLE; |
35 | |
import static org.apache.giraph.types.JavaWritablePair.LONG_LONG_WRITABLE; |
36 | |
import static org.apache.giraph.types.JavaWritablePair.SHORT_INT_WRITABLE; |
37 | |
import static org.apache.giraph.types.JavaWritablePair.SHORT_LONG_WRITABLE; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class WritableWrappers { |
43 | |
|
44 | |
private static final Map<JavaWritablePair, WritableWrapper> MAP; |
45 | |
|
46 | |
static { |
47 | 0 | MAP = Maps.newHashMap(); |
48 | 0 | MAP.put(BOOLEAN_BOOLEAN_WRITABLE, new BooleanToBooleanWritableWrapper()); |
49 | 0 | MAP.put(BYTE_BYTE_WRITABLE, new ByteToByteWritableWrapper()); |
50 | 0 | MAP.put(BYTE_INT_WRITABLE, new ByteToIntWritableWrapper()); |
51 | 0 | MAP.put(BYTE_LONG_WRITABLE, new ByteToLongWritableWrapper()); |
52 | 0 | MAP.put(DOUBLE_DOUBLE_WRITABLE, new DoubleToDoubleWritableWrapper()); |
53 | 0 | MAP.put(FLOAT_DOUBLE_WRITABLE, new FloatToDoubleWritableWrapper()); |
54 | 0 | MAP.put(FLOAT_FLOAT_WRITABLE, new FloatToFloatWritableWrapper()); |
55 | 0 | MAP.put(INT_INT_WRITABLE, new IntToIntWritableWrapper()); |
56 | 0 | MAP.put(INT_LONG_WRITABLE, new IntToLongWritableWrapper()); |
57 | 0 | MAP.put(LONG_LONG_WRITABLE, new LongToLongWritableWrapper()); |
58 | 0 | MAP.put(SHORT_INT_WRITABLE, new ShortToIntWritableWrapper()); |
59 | 0 | MAP.put(SHORT_LONG_WRITABLE, new ShortToLongWritableWrapper()); |
60 | 0 | } |
61 | |
|
62 | |
|
63 | 0 | private WritableWrappers() { } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public static <W extends Writable, J> WritableWrapper<W, J> lookup( |
75 | |
Class<W> writableClass, Class<J> javaClass) { |
76 | 0 | return lookup(JavaWritablePair.create(writableClass, javaClass)); |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public static <W extends Writable, J> WritableWrapper<W, J> lookup( |
88 | |
JavaWritablePair<W, J> classes) { |
89 | 0 | return MAP.get(classes); |
90 | |
} |
91 | |
} |