Resource { @Nullable public String getAsString() { if (isNumber() && null != getAsNumber()) { return getAsNumber().toString(); } else if (isBoolean() && null != getAsNonPrimitiveBoolean()) { return getAsNonPrimitiveBoolean().toString(); } else if (isString()) { return (String) 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();  }
@Test public void testGetAsString() throws Exception { assertEquals(RESOURCE_BOOLEAN.getAsString(), "true"); assertEquals(RESOURCE_STRING.getAsString(), "foo"); assertEquals(RESOURCE_FLOAT.getAsString(), "2.0"); assertEquals(RESOURCE_INTEGER.getAsString(), "1"); assertEquals(RESOURCE_ARRAY.getAsString(), null); }