Resource { @Nullable protected Number getAsNumber() { if (isString()) { return new LazilyParsedNumber((String) value); } else if (isNumber()) { return (Number) value; } else { return null; } } Resource(Boolean value);  Resource(Number value);  Resource(String value);  Resource(Resource[] value); boolean isBoolean(); boolean isNumber(); boolean isString(); boolean isArray(); boolean getAsBoolean(); @Nullable String getAsString(); @Nullable Float getAsFloat(); @Nullable Integer getAsInt(); int[] getAsIntegerArray(); @NonNull String[] getAsStringArray();  }
@SuppressWarnings("ConstantConditions") @Test public void testGetAsNumber() throws Exception { assertEquals(RESOURCE_BOOLEAN.getAsNumber(), null); assertEquals(new Resource("1").getAsNumber().intValue(), 1); assertEquals(new Resource("3.1").getAsNumber().floatValue(), 3.1f); assertEquals(RESOURCE_FLOAT.getAsNumber(), 2.0f); assertEquals(RESOURCE_INTEGER.getAsNumber(), 1); assertEquals(RESOURCE_ARRAY.getAsNumber(), null); }