Resource { @Nullable public Integer getAsInt() { if (isNumber() && null != getAsNumber()) { return getAsNumber().intValue(); } else if (null != getAsString()) { try { return Integer.parseInt(getAsString()); } catch (NumberFormatException e) { return null; } } 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 testGetAsInt() throws Exception { assertEquals(RESOURCE_BOOLEAN.getAsInt(), null); assertEquals(RESOURCE_STRING.getAsInt(), null); assertEquals(RESOURCE_FLOAT.getAsInt(), Integer.valueOf(2)); assertEquals(RESOURCE_INTEGER.getAsInt(), Integer.valueOf(1)); assertEquals(RESOURCE_ARRAY.getAsInt(), null); assertEquals(new Resource("2").getAsInt(), Integer.valueOf(2)); assertEquals(new Resource("3.0").getAsInt(), null); }