| name | class, % | method, % | block, % | line, % |
|---|
| | | | | |
| class UnknownType$NumberFormat$3 | 100% (1/1) | 50% (1/2) | 67% (6/9) | 50% (1/2) |
| parseValue (String): Object | | 0% (0/1) | 0% (0/3) | 0% (0/1) |
| UnknownType$NumberFormat$3 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| | | | | |
| class UnknownType$NumberFormat$4 | 100% (1/1) | 50% (1/2) | 67% (6/9) | 50% (1/2) |
| parseValue (String): Object | | 0% (0/1) | 0% (0/3) | 0% (0/1) |
| UnknownType$NumberFormat$4 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| | | | | |
| class UnknownType | 100% (1/1) | 90% (9/10) | 83% (63/76) | 81% (17/21) |
| toString (Object): CharSequence | | 0% (0/1) | 0% (0/4) | 0% (0/1) |
| lookupLiteral (String): Object | | 100% (1/1) | 55% (6/11) | 33% (1/3) |
| createInstance (CharSequence, Object): Object | | 100% (1/1) | 80% (16/20) | 83% (5/6) |
| UnknownType (Class): void | | 100% (1/1) | 100% (4/4) | 100% (2/2) |
| getActualType (Object): IndirectType | | 100% (1/1) | 100% (4/4) | 100% (1/1) |
| getClassCastStrategy (): ClassCastStrategy | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| getLiteral (): Literal | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| getReferenceStrategy (): ReferenceStrategy | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| getSymbolSpec (): Symbol | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| parseNumber (String): Object | | 100% (1/1) | 100% (25/25) | 100% (4/4) |
| | | | | |
| class UnknownType$1 | 0% (0/1) | 100% (0/0) | 100% (0/0) | 100% (0/0) |
| | | | | |
| class UnknownType$LiteralConstants | 100% (1/1) | 100% (5/5) | 100% (53/53) | 100% (4/4) |
| <static initializer> | | 100% (1/1) | 100% (34/34) | 100% (4/4) |
| UnknownType$LiteralConstants (String, int): void | | 100% (1/1) | 100% (5/5) | 100% (1/1) |
| UnknownType$LiteralConstants (String, int, UnknownType$1): void | | 100% (1/1) | 100% (5/5) | 100% (1/1) |
| valueOf (String): UnknownType$LiteralConstants | | 100% (1/1) | 100% (5/5) | 100% (1/1) |
| values (): UnknownType$LiteralConstants [] | | 100% (1/1) | 100% (4/4) | 100% (1/1) |
| | | | | |
| class UnknownType$LiteralConstants$1 | 100% (1/1) | 100% (2/2) | 100% (8/8) | 100% (2/2) |
| UnknownType$LiteralConstants$1 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| getObject (): Object | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| | | | | |
| class UnknownType$LiteralConstants$2 | 100% (1/1) | 100% (2/2) | 100% (8/8) | 100% (2/2) |
| UnknownType$LiteralConstants$2 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| getObject (): Object | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| | | | | |
| class UnknownType$LiteralConstants$3 | 100% (1/1) | 100% (2/2) | 100% (8/8) | 100% (2/2) |
| UnknownType$LiteralConstants$3 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| getObject (): Object | | 100% (1/1) | 100% (2/2) | 100% (1/1) |
| | | | | |
| class UnknownType$NumberFormat | 100% (1/1) | 100% (5/5) | 100% (63/63) | 100% (5/5) |
| <static initializer> | | 100% (1/1) | 100% (44/44) | 100% (5/5) |
| UnknownType$NumberFormat (String, int): void | | 100% (1/1) | 100% (5/5) | 100% (1/1) |
| UnknownType$NumberFormat (String, int, UnknownType$1): void | | 100% (1/1) | 100% (5/5) | 100% (1/1) |
| valueOf (String): UnknownType$NumberFormat | | 100% (1/1) | 100% (5/5) | 100% (1/1) |
| values (): UnknownType$NumberFormat [] | | 100% (1/1) | 100% (4/4) | 100% (1/1) |
| | | | | |
| class UnknownType$NumberFormat$1 | 100% (1/1) | 100% (2/2) | 100% (9/9) | 100% (2/2) |
| UnknownType$NumberFormat$1 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| parseValue (String): Object | | 100% (1/1) | 100% (3/3) | 100% (1/1) |
| | | | | |
| class UnknownType$NumberFormat$2 | 100% (1/1) | 100% (2/2) | 100% (9/9) | 100% (2/2) |
| UnknownType$NumberFormat$2 (String, int): void | | 100% (1/1) | 100% (6/6) | 100% (1/1) |
| parseValue (String): Object | | 100% (1/1) | 100% (3/3) | 100% (1/1) |
| 1 | /* |
| 2 | * This file is part of JON. |
| 3 | * |
| 4 | * JON is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation; either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * JON is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Copyright 2007 Michael Doberenz |
| 18 | */ |
| 19 | package org.fuwjax.jon.type; |
| 20 | |
| 21 | import java.util.Locale; |
| 22 | |
| 23 | import org.fuwjax.jon.ClassCastStrategy; |
| 24 | import org.fuwjax.jon.IndirectType; |
| 25 | import org.fuwjax.jon.ObjectAccessException; |
| 26 | import org.fuwjax.jon.ReferenceStrategy; |
| 27 | import org.fuwjax.jon.accessor.Literal; |
| 28 | import org.fuwjax.jon.accessor.LiteralAccessor; |
| 29 | import org.fuwjax.jon.accessor.Symbol; |
| 30 | |
| 31 | /** |
| 32 | * An abstract type to be used only for as long as we don't know the type of the |
| 33 | * object being serialized. It is possible that we won't have any idea what |
| 34 | * we're deserializing when deserializing an identifier. This class must handle |
| 35 | * the possibility of deserializing into a primitive/wrapper, boolean, or null. |
| 36 | * @author michaeldoberenz |
| 37 | */ |
| 38 | public final class UnknownType extends AbstractIndirectType implements LiteralAccessor{ |
| 39 | /** |
| 40 | * The serialized form of new Object(). |
| 41 | */ |
| 42 | public static final String EMPTY_OBJECT = "{}"; //$NON-NLS-1$ |
| 43 | |
| 44 | /** |
| 45 | * The literal constants deserializable when the type is unknown. |
| 46 | * @author michaeldoberenz |
| 47 | */ |
| 48 | private enum LiteralConstants{ |
| 49 | /** |
| 50 | * The constant for null. |
| 51 | */ |
| 52 | NULL{ |
| 53 | @Override |
| 54 | public Object getObject(){ |
| 55 | return null; |
| 56 | } |
| 57 | }, |
| 58 | /** |
| 59 | * The constant for true. |
| 60 | */ |
| 61 | TRUE{ |
| 62 | @Override |
| 63 | public Object getObject(){ |
| 64 | return Boolean.TRUE; |
| 65 | } |
| 66 | }, |
| 67 | /** |
| 68 | * The constant for false. |
| 69 | */ |
| 70 | FALSE{ |
| 71 | @Override |
| 72 | public Object getObject(){ |
| 73 | return Boolean.FALSE; |
| 74 | } |
| 75 | }; |
| 76 | /** |
| 77 | * Returns the object corresponding to this constant. |
| 78 | * @return the object corresponding to this constant |
| 79 | */ |
| 80 | public abstract Object getObject(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * The binary literal specifiers for the numeric primitives. |
| 85 | */ |
| 86 | private enum NumberFormat{ |
| 87 | /** |
| 88 | * Integer. |
| 89 | */ |
| 90 | I{ |
| 91 | @Override |
| 92 | public Object parseValue(final String value){ |
| 93 | return Integer.valueOf(value); |
| 94 | } |
| 95 | }, |
| 96 | /** |
| 97 | * Double. |
| 98 | */ |
| 99 | D{ |
| 100 | @Override |
| 101 | public Object parseValue(final String value){ |
| 102 | return Double.valueOf(value); |
| 103 | } |
| 104 | }, |
| 105 | /** |
| 106 | * Float. |
| 107 | */ |
| 108 | F{ |
| 109 | @Override |
| 110 | public Object parseValue(final String value){ |
| 111 | return Float.valueOf(value); |
| 112 | } |
| 113 | }, |
| 114 | /** |
| 115 | * Long. |
| 116 | */ |
| 117 | L{ |
| 118 | @Override |
| 119 | public Object parseValue(final String value){ |
| 120 | return Long.valueOf(value); |
| 121 | } |
| 122 | }; |
| 123 | /** |
| 124 | * Returns the numeric equivalent of <code>value</code>. |
| 125 | * @param value the value to parse |
| 126 | * @return the numeric value |
| 127 | */ |
| 128 | public abstract Object parseValue(String value); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Creates a new instance. |
| 133 | * @param cls the class wrapped by this indirect type |
| 134 | */ |
| 135 | public UnknownType(final Class<?> cls){ |
| 136 | super(cls); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public IndirectType getActualType(final Object object){ |
| 141 | return getIndirectTypeFor(object); |
| 142 | } |
| 143 | |
| 144 | public ClassCastStrategy getClassCastStrategy(){ |
| 145 | return ClassCastStrategy.AlwaysCast; |
| 146 | } |
| 147 | |
| 148 | public ReferenceStrategy getReferenceStrategy(){ |
| 149 | return ReferenceStrategy.AssignedReference; |
| 150 | } |
| 151 | |
| 152 | public Symbol getSymbolSpec(){ |
| 153 | return Symbol.Literal; |
| 154 | } |
| 155 | |
| 156 | public Literal getLiteral(){ |
| 157 | return Literal.Unknown; |
| 158 | } |
| 159 | |
| 160 | public Object createInstance(final CharSequence literal, final Object source) throws ObjectAccessException{ |
| 161 | final String value = literal.toString(); |
| 162 | if(EMPTY_OBJECT.equals(value)){ |
| 163 | return new Object(); |
| 164 | } |
| 165 | try{ |
| 166 | return parseNumber(value); |
| 167 | }catch(NumberFormatException e){ |
| 168 | return lookupLiteral(value); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | private Object parseNumber(final String value) throws ObjectAccessException{ |
| 173 | final String format = value.substring(value.length() - 1).toUpperCase(Locale.US); |
| 174 | try{ |
| 175 | return NumberFormat.valueOf(format).parseValue(value.substring(0, value.length() - 1)); |
| 176 | }catch(RuntimeException e){ |
| 177 | return NumberFormat.I.parseValue(value); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | private Object lookupLiteral(final String value) throws ObjectAccessException{ |
| 182 | try{ |
| 183 | return LiteralConstants.valueOf(value.toUpperCase(Locale.US)).getObject(); |
| 184 | }catch(IllegalArgumentException e){ |
| 185 | throw ObjectAccessException.Message.InvalidLiteral.exception(e); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | public CharSequence toString(final Object object) throws ObjectAccessException{ |
| 190 | throw new UnsupportedOperationException(); |
| 191 | } |
| 192 | } |