@Override public CommentedConfigurationNode createEmptyNode(ConfigurationOptions options) { options = options.setAcceptedTypes(ImmutableSet.of(Map.class, List.class, Double.class, Long.class, Integer.class, Boolean.class, String.class, Number.class)); return SimpleCommentedConfigurationNode.root(options); }
@Override public CommentedConfigurationNode createEmptyNode(ConfigurationOptions options) { options = options.setAcceptedTypes(ImmutableSet.of(Map.class, List.class, Double.class, Float.class, Long.class, Integer.class, Boolean.class, String.class, byte[].class)); return SimpleCommentedConfigurationNode.root(options); }
public static SimpleCommentedConfigurationNode root() { return root(ConfigurationOptions.defaults()); }
@NonNull public static SimpleCommentedConfigurationNode root() { return root(ConfigurationOptions.defaults()); }
@NonNull public static SimpleCommentedConfigurationNode root() { return root(ConfigurationOptions.defaults()); }
@NonNull @Override public CommentedConfigurationNode createEmptyNode(@NonNull ConfigurationOptions options) { options = options.setAcceptedTypes(ImmutableSet.of(Map.class, List.class, Double.class, Long.class, Integer.class, Boolean.class, String.class, Number.class)); return SimpleCommentedConfigurationNode.root(options); }
@NonNull @Override public CommentedConfigurationNode createEmptyNode(@NonNull ConfigurationOptions options) { options = options.setAcceptedTypes(ImmutableSet.of(Map.class, List.class, Double.class, Float.class, Long.class, Integer.class, Boolean.class, String.class, byte[].class)); return SimpleCommentedConfigurationNode.root(options); }
typeLength = configValue.getTypeToken().getRawType().getSimpleName().length(); ConfigurationNode node = SimpleCommentedConfigurationNode.root(); configValue.serializeDefault(node); configSection.append(border).append('\n'); for(ConfigValue<?> configValue : provider.getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); configValue.serializeDefault(node);
private void appendModuleConfigurations() { appendHeader("Module Configurations"); LogListBlock log = new LogListBlock(); List<ModuleWrapper> enabledModules = CraftBookPlugin.spongeInst().moduleController.getModules().stream() .filter(ModuleWrapper::isEnabled).collect(Collectors.toList()); for (ModuleWrapper<?> moduleWrapper : enabledModules) { Object module = moduleWrapper.getModule().orElse(null); if (module == null || !(module instanceof DocumentationProvider)) { continue; } LogListBlock configLog = log.putChild(moduleWrapper.getName()); for (ConfigValue config : ((DocumentationProvider) module).getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); config.serializeDefault(node); configLog.put(config.getKey(), node.getString("UNKNOWN")); } } append(log); appendln(); } }
private void appendGlobalConfiguration() { appendHeader("Global Configuration"); LogListBlock log = new LogListBlock(); LogListBlock configLog = log.putChild("Configuration"); for (ConfigValue config : CraftBookPlugin.spongeInst().getConfig().getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); config.serializeDefault(node); configLog.put(config.getKey(), node.getString("UNKNOWN")); } append(log); appendln(); }
@Test public void testWalker() { CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(); node.getNode("l1-1").setValue(1); node.getNode("l1-1", "l2-1").setValue(1); node.getNode("l1-1", "l2-2").setValue(1); node.getNode("l1-1", "l2-3", "l3-1").setValue(1); node.getNode("l1-1", "l2-3", "l3-2").setValue(1); node.getNode("l1-1", "l2-4").setValue(1); node.getNode("l1-2").setValue(1); node.getNode("l1-2", "l2-1").setValue(ImmutableList.of(1, 2, 3)); List<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> breadthFirst = new ArrayList<>(); Iterators.addAll(breadthFirst, ConfigurationNodeWalker.BREADTH_FIRST.walkWithPath(node)); List<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> depthFirstPre = new ArrayList<>(); Iterators.addAll(depthFirstPre, ConfigurationNodeWalker.DEPTH_FIRST_PRE_ORDER.walkWithPath(node)); List<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> depthFirstPost = new ArrayList<>(); Iterators.addAll(depthFirstPost, ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(node)); assertEquals(13, breadthFirst.size()); assertEquals(13, depthFirstPre.size()); assertEquals(13, depthFirstPost.size()); List<String> breadthFirstOrder = breadthFirst.stream().map(PATH_TO_STRING).collect(Collectors.toList()); assertEquals(EXPECTED_BREADTH_FIRST_ORDER, breadthFirstOrder); List<String> depthFirstPreOrder = depthFirstPre.stream().map(PATH_TO_STRING).collect(Collectors.toList()); assertEquals(EXPECTED_DEPTH_FIRST_PRE_ORDER, depthFirstPreOrder); List<String> depthFirstPostOrder = depthFirstPost.stream().map(PATH_TO_STRING).collect(Collectors.toList()); assertEquals(EXPECTED_DEPTH_FIRST_POST_ORDER, depthFirstPostOrder); }
@Test public void testCommentsApplied() throws ObjectMappingException { CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(); ObjectMapper<CommentedObject>.BoundInstance mapper = ObjectMapper.forClass(CommentedObject.class).bindToNew(); CommentedObject obj = mapper.populate(node); obj.color = "fuchsia"; obj.politician = "All of them"; mapper.serialize(node); assertEquals("You look nice today", node.getNode("commented-key").getComment().orElse(null)); assertEquals("fuchsia", node.getNode("commented-key").getString()); assertFalse(node.getNode("no-comment").getComment().isPresent()); }
@Test public void testNestedObjectWithComments() throws ObjectMappingException { CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(); final ObjectMapper<ParentObject>.BoundInstance mapper = ObjectMapper.forObject(new ParentObject()); mapper.populate(node); assertEquals("Comment on parent", node.getNode("inner").getComment().get()); assertTrue(node.getNode("inner").hasMapChildren()); assertEquals("Default value", node.getNode("inner", "test").getString()); assertEquals("Something", node.getNode("inner", "test").getComment().get()); }
@Test public void testCommentsTransferred() { CommentedConfigurationNode subject = SimpleCommentedConfigurationNode.root(); CommentedConfigurationNode firstChild = subject.getNode("first"); firstChild.setValue("test value"); firstChild.setComment("Such comment. Very wow."); CommentedConfigurationNode secondChild = subject.getNode("second"); secondChild.setValue("test value's evil twin"); assertFalse(secondChild.isVirtual()); secondChild.setValue(firstChild); assertEquals("test value", secondChild.getValue()); assertEquals("Such comment. Very wow.", secondChild.getComment().orElse(null)); }
@Test public void testInterfaceSerialization() throws ObjectMappingException { CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root();
@Test public void testCommentsMerged() { CommentedConfigurationNode source = SimpleCommentedConfigurationNode.root(); CommentedConfigurationNode target = SimpleCommentedConfigurationNode.root(); source.getNode("no-value").setValue("a").setComment("yeah"); source.getNode("existing-value-no-comment").setValue("orig").setComment("maybe"); source.getNode("existing-value").setValue("a").setComment("yeah"); source.getNode("no-parent", "child").setValue("x").setComment("always"); target.getNode("existing-value-no-comment").setValue("new"); target.getNode("existing-value").setValue("b").setComment("nope"); target.mergeValuesFrom(source); assertEquals("yeah", target.getNode("no-value").getComment().orElse(null)); assertEquals("maybe", target.getNode("existing-value-no-comment").getComment().orElse(null)); assertEquals("new", target.getNode("existing-value-no-comment").getString()); assertEquals("nope", target.getNode("existing-value").getComment().orElse(null)); assertEquals("always", target.getNode("no-parent", "child").getComment().orElse(null)); } }
@Test public void testNestedCommentsTransferred() { CommentedConfigurationNode subject = SimpleCommentedConfigurationNode.root(); CommentedConfigurationNode firstChild = subject.getNode("first"); CommentedConfigurationNode firstChildChild = firstChild.getNode("child"); firstChildChild.setValue("test value"); firstChildChild.setComment("Such comment. Very wow."); CommentedConfigurationNode secondChild = subject.getNode("second"); secondChild.setValue("test value's evil twin"); assertFalse(secondChild.isVirtual()); secondChild.setValue(firstChild); assertEquals("test value", secondChild.getNode("child").getValue()); assertEquals("Such comment. Very wow.", secondChild.getNode("child").getComment().orElse(null)); }