@Override public SimpleCommentedConfigurationNode mergeValuesFrom(ConfigurationNode other) { if (other instanceof CommentedConfigurationNode) { Optional<String> otherComment = ((CommentedConfigurationNode) other).getComment(); if (otherComment.isPresent()) { comment.compareAndSet(null, otherComment.get()); } } return (SimpleCommentedConfigurationNode) super.mergeValuesFrom(other); }
@NonNull @Override public SimpleCommentedConfigurationNode mergeValuesFrom(@NonNull ConfigurationNode other) { if (other instanceof CommentedConfigurationNode) { Optional<String> otherComment = ((CommentedConfigurationNode) other).getComment(); if (otherComment.isPresent()) { comment.compareAndSet(null, otherComment.get()); } } return (SimpleCommentedConfigurationNode) super.mergeValuesFrom(other); }
@NonNull @Override public SimpleCommentedConfigurationNode mergeValuesFrom(@NonNull ConfigurationNode other) { if (other instanceof CommentedConfigurationNode) { Optional<String> otherComment = ((CommentedConfigurationNode) other).getComment(); if (comment == null && otherComment.isPresent()) { comment = otherComment.get(); } } return (SimpleCommentedConfigurationNode) super.mergeValuesFrom(other); }
@NonNull @Override public SimpleAttributedConfigurationNode mergeValuesFrom(@NonNull ConfigurationNode other) { if (other instanceof AttributedConfigurationNode) { AttributedConfigurationNode node = (AttributedConfigurationNode) other; setTagName(node.getTagName()); for (Map.Entry<String, String> attribute : node.getAttributes().entrySet()) { addAttribute(attribute.getKey(), attribute.getValue()); } } return (SimpleAttributedConfigurationNode) super.mergeValuesFrom(other); }
@NonNull @Override public SimpleAttributedConfigurationNode mergeValuesFrom(@NonNull ConfigurationNode other) { if (other instanceof AttributedConfigurationNode) { AttributedConfigurationNode node = (AttributedConfigurationNode) other; setTagName(node.getTagName()); for (Map.Entry<String, String> attribute : node.getAttributes().entrySet()) { addAttribute(attribute.getKey(), attribute.getValue()); } } return (SimpleAttributedConfigurationNode) super.mergeValuesFrom(other); }
SimpleConfigurationNode existing = newValue.putChildIfAbsent(ent.getKey(), newChild); if (existing != null) { existing.mergeValuesFrom(newChild);
existing.mergeValuesFrom(newChild);
existing.mergeValuesFrom(newChild);
@Test public void testMergeValues() { SimpleConfigurationNode first = SimpleConfigurationNode.root(); SimpleConfigurationNode second = SimpleConfigurationNode.root(); first.getNode("scalar").setValue("one"); first.getNode("absent").setValue("butmerged"); second.getNode("scalar").setValue("two"); ConfigurationNode firstAbsentMap = first.getNode("absent-map"); firstAbsentMap.getNode("a").setValue("one"); firstAbsentMap.getNode("b").setValue("two"); ConfigurationNode firstMergedMap = first.getNode("merged-map"); ConfigurationNode secondMergedMap = second.getNode("merged-map"); firstMergedMap.getNode("source").setValue("first"); secondMergedMap.getNode("source").setValue("second"); firstMergedMap.getNode("first-only").setValue("yeah"); secondMergedMap.getNode("second-only").setValue("yeah"); second.mergeValuesFrom(first); assertEquals("two", second.getNode("scalar").getString()); assertEquals("butmerged", second.getNode("absent").getString()); assertEquals("one", second.getNode("absent-map", "a").getString()); assertEquals("two", second.getNode("absent-map", "b").getString()); assertEquals("second", second.getNode("merged-map", "source").getString()); assertEquals("yeah", second.getNode("merged-map", "first-only").getString()); assertEquals("yeah", second.getNode("merged-map", "second-only").getString()); }