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.DOUBLE_DOUBLE_WRITABLE; |
29 | |
import static org.apache.giraph.types.JavaWritablePair.DOUBLE_FLOAT_WRITABLE; |
30 | |
import static org.apache.giraph.types.JavaWritablePair.FLOAT_FLOAT_WRITABLE; |
31 | |
import static org.apache.giraph.types.JavaWritablePair.INT_BYTE_WRITABLE; |
32 | |
import static org.apache.giraph.types.JavaWritablePair.INT_INT_WRITABLE; |
33 | |
import static org.apache.giraph.types.JavaWritablePair.LONG_BYTE_WRITABLE; |
34 | |
import static org.apache.giraph.types.JavaWritablePair.LONG_INT_WRITABLE; |
35 | |
import static org.apache.giraph.types.JavaWritablePair.LONG_LONG_WRITABLE; |
36 | |
import static org.apache.giraph.types.JavaWritablePair.SHORT_BYTE_WRITABLE; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public class WritableUnwrappers { |
42 | |
|
43 | |
private static final Map<JavaWritablePair, WritableUnwrapper> MAP; |
44 | |
|
45 | |
static { |
46 | 0 | MAP = Maps.newHashMap(); |
47 | 0 | MAP.put(BOOLEAN_BOOLEAN_WRITABLE, new BooleanWritableToBooleanUnwrapper()); |
48 | 0 | MAP.put(BYTE_BYTE_WRITABLE, new ByteWritableToByteUnwrapper()); |
49 | 0 | MAP.put(DOUBLE_DOUBLE_WRITABLE, new DoubleWritableToDoubleUnwrapper()); |
50 | 0 | MAP.put(DOUBLE_FLOAT_WRITABLE, new FloatWritableToDoubleUnwrapper()); |
51 | 0 | MAP.put(FLOAT_FLOAT_WRITABLE, new FloatWritableToFloatUnwrapper()); |
52 | 0 | MAP.put(INT_BYTE_WRITABLE, new ByteWritableToIntUnwrapper()); |
53 | 0 | MAP.put(INT_INT_WRITABLE, new IntWritableToIntUnwrapper()); |
54 | 0 | MAP.put(SHORT_BYTE_WRITABLE, new ByteWritableToShortUnwrapper()); |
55 | 0 | MAP.put(LONG_BYTE_WRITABLE, new ByteWritableToLongUnwrapper()); |
56 | 0 | MAP.put(LONG_INT_WRITABLE, new IntWritableToLongUnwrapper()); |
57 | 0 | MAP.put(LONG_LONG_WRITABLE, new LongWritableToLongUnwrapper()); |
58 | 0 | } |
59 | |
|
60 | |
|
61 | 0 | private WritableUnwrappers() { } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public static <W extends Writable, J> WritableUnwrapper<W, J> lookup( |
73 | |
Class<W> writableClass, Class<J> javaClass) { |
74 | 0 | return lookup(JavaWritablePair.create(writableClass, javaClass)); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public static <W extends Writable, J> WritableUnwrapper<W, J> lookup( |
86 | |
JavaWritablePair<W, J> classes) { |
87 | 0 | return MAP.get(classes); |
88 | |
} |
89 | |
} |