1 | /* |
2 | * JTiger Unit Testing Framework for J2SE 1.5 |
3 | * Copyright (C) 2005 Tony Morris |
4 | * |
5 | * This software is licenced under the |
6 | * Common Public Licence version 1.0 |
7 | * http://www.opensource.org/licenses/cpl1.0.php |
8 | * |
9 | * You received a copy of this licence with this software. |
10 | */ |
11 | package org.jtiger.assertion; |
12 | |
13 | final class BoxedTypePromoterFactory |
14 | { |
15 | private BoxedTypePromoterFactory() |
16 | { |
17 | |
18 | } |
19 | |
20 | public static BoxedTypePromoter newBoxedTypePromoter() |
21 | { |
22 | return new BoxedTypePromoterImpl(); |
23 | } |
24 | |
25 | private static final class BoxedTypePromoterImpl implements BoxedTypePromoter |
26 | { |
27 | BoxedTypePromoterImpl() |
28 | { |
29 | |
30 | } |
31 | |
32 | public Object promote(final Object o) |
33 | { |
34 | if(o == null) |
35 | { |
36 | return null; |
37 | } |
38 | else if(o instanceof Byte) |
39 | { |
40 | return new Long(((Byte)o).byteValue()); |
41 | } |
42 | else if(o instanceof Short) |
43 | { |
44 | return new Long(((Short)o).shortValue()); |
45 | } |
46 | else if(o instanceof Character) |
47 | { |
48 | return new Long(((Character)o).charValue()); |
49 | } |
50 | else if(o instanceof Integer) |
51 | { |
52 | return new Long(((Integer)o).intValue()); |
53 | } |
54 | else if(o instanceof Float) |
55 | { |
56 | return new Double(((Float)o).floatValue()); |
57 | } |
58 | else |
59 | { |
60 | return o; |
61 | } |
62 | } |
63 | } |
64 | } |