ListConfigValue(SimpleConfigurationNode holder, Object startValue) { super(holder); this.values.set(new ArrayList<>()); SimpleConfigurationNode child = holder.createNode(0); child.attached = true; child.setValue(startValue); this.values.get().add(child); }
ListConfigValue(SimpleConfigurationNode holder, Object startValue) { super(holder); SimpleConfigurationNode child = holder.createNode(0); child.attached = true; child.setValue(startValue); this.values.get().add(child); }
ListConfigValue(SimpleConfigurationNode holder, Object startValue) { super(holder); SimpleConfigurationNode child = holder.createNode(0); child.attached = true; child.setValue(startValue); this.values.get().add(child); }
@Override public SimpleCommentedConfigurationNode setValue(Object value) { if (value instanceof CommentedConfigurationNode && ((CommentedConfigurationNode) value).getComment().isPresent()) { setComment(((CommentedConfigurationNode) value).getComment().get()); } return (SimpleCommentedConfigurationNode)super.setValue(value); }
private <T> T calculateDef(T defValue) { if (defValue != null && getOptions().shouldCopyDefaults()) { setValue(defValue); } return defValue; }
private <T> T storeDefault(TypeToken<T> type, T defValue) throws ObjectMappingException { if (defValue != null && getOptions().shouldCopyDefaults()) { setValue(type, defValue); } return defValue; }
/** * Handles the copying of applied defaults, if enabled. * * @param defValue the default value * @param <T> the value type * @return the same value */ private <T> T storeDefault(T defValue) { if (defValue != null && getOptions().shouldCopyDefaults()) { setValue(defValue); } return defValue; }
/** * Handles the copying of applied defaults, if enabled. * * @param defValue the default value * @param <T> the value type * @return the same value */ private <T> T storeDefault(T defValue) { if (defValue != null && getOptions().shouldCopyDefaults()) { setValue(defValue); } return defValue; }
@NonNull @Override public SimpleCommentedConfigurationNode setValue(@Nullable Object value) { if (value instanceof CommentedConfigurationNode && ((CommentedConfigurationNode) value).getComment().isPresent()) { setComment(((CommentedConfigurationNode) value).getComment().get()); } return (SimpleCommentedConfigurationNode) super.setValue(value); }
@NonNull @Override public SimpleCommentedConfigurationNode setValue(@Nullable Object value) { if (value instanceof CommentedConfigurationNode && ((CommentedConfigurationNode) value).getComment().isPresent()) { setComment(((CommentedConfigurationNode) value).getComment().get()); } return (SimpleCommentedConfigurationNode) super.setValue(value); }
@Test public void testGetSetValueSerialized() throws ObjectMappingException { SimpleConfigurationNode subject = SimpleConfigurationNode.root(); subject.setValue("48"); assertEquals((Object) 48, subject.getValue(TypeToken.of(Integer.class))); UUID testId = UUID.randomUUID(); subject.setValue(TypeToken.of(UUID.class), testId); assertEquals(testId.toString(), subject.getValue()); }
@Test public void testSettingMultipleTimesWorks() { SimpleConfigurationNode subject = SimpleConfigurationNode.root(); subject.setValue(ImmutableMap.of("a", "b", "b", "c", "c", "d")); assertTrue(subject.hasMapChildren()); subject.setValue(ImmutableMap.of("na", "na", "eh", "eh", "bleugh", "bleugh")); assertTrue(subject.hasMapChildren()); }
@NonNull @Override public SimpleAttributedConfigurationNode setValue(@Nullable Object value) { if (value instanceof AttributedConfigurationNode) { AttributedConfigurationNode node = (AttributedConfigurationNode) value; setTagName(node.getTagName()); setAttributes(node.getAttributes()); } return (SimpleAttributedConfigurationNode) super.setValue(value); }
@NonNull @Override public SimpleAttributedConfigurationNode setValue(@Nullable Object value) { if (value instanceof AttributedConfigurationNode) { AttributedConfigurationNode node = (AttributedConfigurationNode) value; setTagName(node.getTagName()); setAttributes(node.getAttributes()); } return (SimpleAttributedConfigurationNode) super.setValue(value); }
@Test public void testTraversingNodeCreation() { SimpleConfigurationNode config = SimpleConfigurationNode.root(); SimpleConfigurationNode nodeOne = config.getNode("uncreated", "step", "node"); SimpleConfigurationNode nodeTwo = config.getNode("uncreated", "step", "color"); nodeOne.setValue("one"); nodeTwo.setValue("lilac"); ConfigurationNode attachedParent = config.getNode("uncreated", "step"); assertEquals(attachedParent, nodeOne.getParentEnsureAttached()); assertEquals(attachedParent, nodeTwo.getParentEnsureAttached()); }
@Test public void testURLSerializer() throws ObjectMappingException, MalformedURLException { final TypeToken<URL> urlType = TypeToken.of(URL.class); final TypeSerializer<URL> urlSerializer = SERIALIZERS.get(urlType); final String urlString = "http://google.com"; final URL testUrl = new URL(urlString); SimpleConfigurationNode node = SimpleConfigurationNode.root().setValue(urlString); assertEquals(testUrl, urlSerializer.deserialize(urlType, node)); urlSerializer.serialize(urlType, testUrl, node); assertEquals(urlString, node.getValue()); }
@Test public void testURISerializer() throws ObjectMappingException { final TypeToken<URI> uriType = TypeToken.of(URI.class); final TypeSerializer<URI> uriSerializer = SERIALIZERS.get(uriType); final String uriString = "http://google.com"; final URI testUri = URI.create(uriString); SimpleConfigurationNode node = SimpleConfigurationNode.root().setValue(uriString); assertEquals(testUri, uriSerializer.deserialize(uriType, node)); uriSerializer.serialize(uriType, testUri, node); assertEquals(uriString, node.getValue()); }
@Test public void testBooleanSerializer() throws ObjectMappingException { final TypeToken<Boolean> booleanType = TypeToken.of(Boolean.class); final TypeSerializer<Boolean> booleanSerializer = SERIALIZERS.get(booleanType); SimpleConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("direct").setValue(true); node.getNode("fromstring").setValue("true"); assertEquals(true, booleanSerializer.deserialize(booleanType, node.getNode("direct"))); assertEquals(true, booleanSerializer.deserialize(booleanType, node.getNode("fromstring"))); }
@Test public void testEnumValueSerializer() throws ObjectMappingException { final TypeToken<TestEnum> enumType = TypeToken.of(TestEnum.class); final TypeSerializer<TestEnum> enumSerializer = SERIALIZERS.get(enumType); SimpleConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("present_val").setValue("first"); node.getNode("another_present_val").setValue("SECOND"); node.getNode(("casematters_val")).setValue("tHiRd"); node.getNode(("casematters_val_lowercase")).setValue("third"); node.getNode("invalid_val").setValue("3rd"); assertEquals(TestEnum.FIRST, enumSerializer.deserialize(enumType, node.getNode("present_val"))); assertEquals(TestEnum.SECOND, enumSerializer.deserialize(enumType, node.getNode("another_present_val"))); assertEquals(TestEnum.Third, enumSerializer.deserialize(enumType, node.getNode("casematters_val"))); assertEquals(TestEnum.third, enumSerializer.deserialize(enumType, node.getNode("casematters_val_lowercase"))); Assertions.assertThrows(ObjectMappingException.class, () -> { enumSerializer.deserialize(enumType, node.getNode("invalid_val")); }); }
@Test public void testStringSerializer() throws ObjectMappingException { final TypeToken<String> stringType = TypeToken.of(String.class); final TypeSerializer<String> stringSerializer = SERIALIZERS.get(stringType); final ConfigurationNode node = SimpleConfigurationNode.root().setValue("foobar"); assertEquals("foobar", stringSerializer.deserialize(stringType, node)); stringSerializer.serialize(stringType, "foobarbaz", node); assertEquals("foobarbaz", node.getString()); }