@Override public void serialize(TypeToken<?> type, Boolean obj, ConfigurationNode value) { value.setValue(Types.asBoolean(obj)); } }
@Override public SimpleConfigurationNode getChild(Object key) { final List<SimpleConfigurationNode> values = this.values.get(); synchronized (values) { Integer value = Types.asInt(key); if (value == null || value < 0 || value >= values.size()) { return null; } return values.get(value); } }
@Override public Date deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { return Types.asDate(value.getValue()); }
@Override public Instant deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { return Types.asInstant(value.getValue()); }
@Test public void testAsDouble() throws Exception { final double actuallyDouble = 1.45f; final String doubleString = "1.45"; final int integer = 4; assertEquals((Double) actuallyDouble, Types.asDouble(actuallyDouble)); assertEquals((Double) 1.45d, Types.asDouble(doubleString)); assertEquals((Double) 4d, Types.asDouble(integer)); }
@Test public void testAsFloat() throws Exception { final float actuallyFloat = 1.45f; final String floatString = "1.45"; final int integer = 4; assertEquals((Float) actuallyFloat, Types.asFloat(actuallyFloat)); assertEquals((Float) 1.45f, Types.asFloat(floatString)); assertEquals((Float) 4f, Types.asFloat(integer)); }
@Test public void testAsLong() throws Exception { final long actuallyInt = 4934285231847238472L; final String doubleString = "424338492842"; final double integer = 4f; assertEquals((Long) actuallyInt, Types.asLong(actuallyInt)); assertEquals((Long) 424338492842L, Types.asLong(doubleString)); assertEquals((Long) 4L, Types.asLong(integer)); }
@Nullable @Override public SimpleConfigurationNode getChild(@Nullable Object key) { Integer value = Types.asInt(key); if (value == null || value < 0) { return null; } final List<SimpleConfigurationNode> values = this.values.get(); synchronized (values) { if (value >= values.size()) { return null; } return values.get(value); } }
@Test public void testAsBoolean() throws Exception { final boolean actual = true; final String[] trueEvaluating = new String[] {"true", "yes", "1", "t", "y"}, falseEvaluating = new String[] {"false", "no", "0", "f", "n"}; assertEquals(actual, Types.asBoolean(actual)); for (String val : trueEvaluating) { assertEquals(true, Types.asBoolean(val)); } for (String val : falseEvaluating) { assertEquals(false, Types.asBoolean(val)); } }
@Nullable @Override public SimpleConfigurationNode getChild(@Nullable Object key) { Integer value = Types.asInt(key); if (value == null || value < 0) { return null; } final List<SimpleConfigurationNode> values = this.values.get(); synchronized (values) { if (value >= values.size()) { return null; } return values.get(value); } }
@Override public void serialize(@NonNull TypeToken<?> type, @Nullable Boolean obj, @NonNull ConfigurationNode value) { value.setValue(Types.asBoolean(obj)); } }
@Test public void testAsInt() throws Exception { final int actuallyInt = 4; final String doubleString = "42"; final float integer = 4f; assertEquals((Integer) actuallyInt, Types.asInt(actuallyInt)); assertEquals((Integer) 42, Types.asInt(doubleString)); assertEquals((Integer) 4, Types.asInt(integer)); }
@Override public void serialize(@NonNull TypeToken<?> type, @Nullable Boolean obj, @NonNull ConfigurationNode value) { value.setValue(Types.asBoolean(obj)); } }