01: /*
02: * Copyright (c) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 11. October 2006 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.core.util;
12:
13: import java.util.HashMap;
14: import java.util.Map;
15:
16: /**
17: * Utility class for primitives.
18: *
19: * @author Jörg Schaible
20: * @since 1.2.1
21: */
22: public final class Primitives {
23: private final static Map BOX = new HashMap();
24: private final static Map UNBOX = new HashMap();
25:
26: static {
27: final Class[][] boxing = new Class[][] {
28: { byte.class, Byte.class },
29: { char.class, Character.class },
30: { short.class, Short.class },
31: { int.class, Integer.class },
32: { long.class, Long.class },
33: { float.class, Float.class },
34: { double.class, Double.class },
35: { boolean.class, Boolean.class },
36: { void.class, Void.class }, };
37: for (int i = 0; i < boxing.length; i++) {
38: BOX.put(boxing[i][0], boxing[i][1]);
39: UNBOX.put(boxing[i][1], boxing[i][0]);
40: }
41: }
42:
43: static public Class box(final Class type) {
44: return (Class) BOX.get(type);
45: }
46:
47: static public Class unbox(final Class type) {
48: return (Class) UNBOX.get(type);
49: }
50: }
|