private void generateArray(JsonGenerator generator, ConfigurationNode node) throws IOException { if (!node.hasListChildren()) { throw new IOException("Node passed to generateArray does not have list children!"); } List<? extends ConfigurationNode> children = node.getChildrenList(); generator.writeStartArray(children.size()); for (ConfigurationNode child : children) { //generateComment(generator, child, true); generateValue(generator, child); } generator.writeEndArray(); } }
private static void generateArray(JsonGenerator generator, ConfigurationNode node) throws IOException { if (!node.hasListChildren()) { throw new IOException("Node passed to generateArray does not have list children!"); } List<? extends ConfigurationNode> children = node.getChildrenList(); generator.writeStartArray(children.size()); for (ConfigurationNode child : children) { //generateComment(generator, child, true); generateValue(generator, child); } generator.writeEndArray(); } }
@Override public CompletableFuture<RankLadder> getRankLadderInternal(String ladder) { return completedFuture(new FixedRankLadder(ladder, ImmutableList.copyOf(Lists.transform(getRankLaddersNode().getNode(ladder.toLowerCase()).getChildrenList(), input -> Util.subjectFromString(input.getString()))))); }
private Element writeNode(Document document, ConfigurationNode node, String forcedTag) { String tag = defaultTagName; Map<String, String> attributes = ImmutableMap.of(); if (node instanceof AttributedConfigurationNode) { AttributedConfigurationNode attributedNode = ((AttributedConfigurationNode) node); tag = attributedNode.getTagName(); attributes = attributedNode.getAttributes(); } Element element = document.createElement(forcedTag == null ? tag : forcedTag); for (Map.Entry<String, String> attribute : attributes.entrySet()) { element.setAttribute(attribute.getKey(), attribute.getValue()); } if (node.hasMapChildren()) { for (Map.Entry<Object, ? extends ConfigurationNode> child : node.getChildrenMap().entrySet()) { element.appendChild(writeNode(document, child.getValue(), child.getKey().toString())); } } else if (node.hasListChildren()) { if (writeExplicitType) { element.setAttribute("configurate-type", "list"); } for (ConfigurationNode child : node.getChildrenList()) { element.appendChild(writeNode(document, child, null)); } } else { element.appendChild(document.createTextNode(node.getValue().toString())); } return element; }
private static void generateArray(JsonWriter generator, ConfigurationNode node) throws IOException { if (!node.hasListChildren()) { throw new IOException("Node passed to generateArray does not have list children!"); } List<? extends ConfigurationNode> children = node.getChildrenList(); generator.beginArray(); for (ConfigurationNode child : children) { generateValue(generator, child); } generator.endArray(); } }
private void generateArray(JsonWriter generator, ConfigurationNode node) throws IOException { if (!node.hasListChildren()) { throw new IOException("Node passed to generateArray does not have list children!"); } List<? extends ConfigurationNode> children = node.getChildrenList(); generator.beginArray(); for (ConfigurationNode child : children) { generateValue(generator, child); } generator.endArray(); } }
private static void generateArray(JsonWriter generator, ConfigurationNode node) throws IOException { if (!node.hasListChildren()) { throw new IOException("Node passed to generateArray does not have list children!"); } List<? extends ConfigurationNode> children = node.getChildrenList(); generator.beginArray(); for (ConfigurationNode child : children) { generateValue(generator, child); } generator.endArray(); } }
void serialize(ConfigurationNode node) throws ObjectMappingException { if (!node.hasListChildren()) { node.setValue(null); } Map<Set<Entry<String, String>>, ConfigurationNode> existingSections = new HashMap<>(); for (ConfigurationNode child : node.getChildrenList()) { existingSections.put(contextsFrom(child), child); } for (Map.Entry<Set<Entry<String, String>>, DataEntry> ent : contexts.entrySet()) { ConfigurationNode contextSection = existingSections.remove(ent.getKey()); if (contextSection == null) { contextSection = node.getAppendedNode(); ConfigurationNode contextsNode = contextSection.getNode(KEY_CONTEXTS); for (Entry<String, String> context : ent.getKey()) { contextsNode.getNode(context.getKey()).setValue(context.getValue()); } } MAPPER.bind(ent.getValue()).serialize(contextSection); } for (ConfigurationNode unused : existingSections.values()) { unused.setValue(null); } }
private static <T extends ConfigurationNode> Iterator<VisitedNodeImpl<T>> getChildren(VisitedNodeImpl<T> from) { T node = from.getNode(); switch (node.getValueType()) { case LIST: { Object[] path = from.getRawPath(); return Iterators.transform(node.getChildrenList().iterator(), child -> { Objects.requireNonNull(child); //noinspection unchecked T castedChild = ((T) child); Object[] childPath = calculatePath(path, child.getKey()); return new VisitedNodeImpl<>(childPath, castedChild); }); } case MAP: { Object[] path = from.getRawPath(); return Iterators.transform(node.getChildrenMap().entrySet().iterator(), child -> { Objects.requireNonNull(child); //noinspection unchecked T castedChild = ((T) child.getValue()); Object[] childPath = calculatePath(path, child.getKey()); return new VisitedNodeImpl<>(childPath, castedChild); }); } default: return Collections.emptyIterator(); } }
static FileSubjectData fromNode(ConfigurationNode node) throws ObjectMappingException, PermissionsLoadingException { ImmutableMap.Builder<Set<Entry<String, String>>, DataEntry> map = ImmutableMap.builder(); if (node.hasListChildren()) { for (ConfigurationNode child : node.getChildrenList()) { if (!child.hasMapChildren()) { throw new PermissionsLoadingException(t("Each context section must be of map type! Check that no duplicate nesting has occurred.")); } Set<Entry<String, String>> contexts = contextsFrom(child); DataEntry value = MAPPER.bindToNew().populate(child); map.put(contexts, value); } } return new FileSubjectData(map.build()); }
@Override public Set<?> deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { TypeToken<?> entryType = type.resolveType(Set.class.getTypeParameters()[0]); TypeSerializer<?> entrySerial = value.getOptions().getSerializers().get(entryType); if (entrySerial == null) { throw new ObjectMappingException("No applicable type serializer for type " + entryType); } if (value.hasListChildren()) { List<? extends ConfigurationNode> values = value.getChildrenList(); Set<Object> ret = new HashSet<>(values.size()); for (ConfigurationNode ent : values) { ret.add(entrySerial.deserialize(entryType, ent)); } return ret; } else { Object unwrappedVal = value.getValue(); if (unwrappedVal != null) { return Sets.newHashSet(entrySerial.deserialize(entryType, value)); } } return new HashSet<>(); }
private ConfigValue fromValue(ConfigurationNode node) { ConfigValue ret; if (node.hasMapChildren()) { Map<String, ConfigValue> children = node.getOptions().getMapFactory().create(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : node.getChildrenMap().entrySet()) { children.put(String.valueOf(ent.getKey()), fromValue(ent.getValue())); } ret = newConfigObject(children); } else if (node.hasListChildren()) { List<ConfigValue> children = new ArrayList<>(); for (ConfigurationNode ent : node.getChildrenList()) { children.add(fromValue(ent)); } ret = newConfigList(children); } else { ret = ConfigValueFactory.fromAnyRef(node.getValue(), "configurate-hocon"); } if (node instanceof CommentedConfigurationNode) { CommentedConfigurationNode commentedNode = ((CommentedConfigurationNode) node); final ConfigValue finalRet = ret; ret = commentedNode.getComment().map(comment -> finalRet.withOrigin(finalRet.origin().withComments(LINE_SPLITTER.splitToList(comment)))).orElse(ret); } return ret; }
@Override public List<?> deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { if (!(type.getType() instanceof ParameterizedType)) { throw new ObjectMappingException("Raw types are not supported for collections"); } TypeToken<?> entryType = type.resolveType(List.class.getTypeParameters()[0]); TypeSerializer entrySerial = value.getOptions().getSerializers().get(entryType); if (entrySerial == null) { throw new ObjectMappingException("No applicable type serializer for type " + entryType); } if (value.hasListChildren()) { List<? extends ConfigurationNode> values = value.getChildrenList(); List<Object> ret = new ArrayList<>(values.size()); for (ConfigurationNode ent : values) { ret.add(entrySerial.deserialize(entryType, ent)); } return ret; } else { Object unwrappedVal = value.getValue(); if (unwrappedVal != null) { return Lists.newArrayList(entrySerial.deserialize(entryType, value)); } } return new ArrayList<>(); }
private static ConfigValue fromValue(ConfigurationNode node) { ConfigValue ret; if (node.hasMapChildren()) { Map<String, ConfigValue> children = node.getOptions().getMapFactory().create(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : node.getChildrenMap().entrySet()) { children.put(String.valueOf(ent.getKey()), fromValue(ent.getValue())); } ret = newConfigObject(children); } else if (node.hasListChildren()) { List<ConfigValue> children = new ArrayList<>(); for (ConfigurationNode ent : node.getChildrenList()) { children.add(fromValue(ent)); } ret = newConfigList(children); } else { ret = ConfigValueFactory.fromAnyRef(node.getValue(), "configurate-hocon"); } if (node instanceof CommentedConfigurationNode) { CommentedConfigurationNode commentedNode = ((CommentedConfigurationNode) node); final ConfigValue finalRet = ret; ret = commentedNode.getComment().map(comment -> finalRet.withOrigin(finalRet.origin().withComments(LINE_SPLITTER.splitToList(comment)))).orElse(ret); } return ret; }
if (path[i] == WILDCARD_OBJECT) { if (node.hasListChildren()) { List<? extends ConfigurationNode> children = node.getChildrenList(); for (int di = 0; di < children.size(); ++di) { path[i] = di;
if (path[i] == WILDCARD_OBJECT) { if (node.hasListChildren()) { List<? extends ConfigurationNode> children = node.getChildrenList(); for (int cI = 0; cI < children.size(); ++cI) { path[i] = cI;
@Override public List<?> deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { if (!(type.getType() instanceof ParameterizedType)) { throw new ObjectMappingException("Raw types are not supported for collections"); } TypeToken<?> entryType = type.resolveType(List.class.getTypeParameters()[0]); TypeSerializer entrySerial = value.getOptions().getSerializers().get(entryType); if (entrySerial == null) { throw new ObjectMappingException("No applicable type serializer for type " + entryType); } if (value.hasListChildren()) { List<? extends ConfigurationNode> values = value.getChildrenList(); List<Object> ret = new ArrayList<>(values.size()); for (ConfigurationNode ent : values) { ret.add(entrySerial.deserialize(entryType, ent)); } return ret; } else { Object unwrappedVal = value.getValue(); if (unwrappedVal != null) { return Lists.newArrayList(entrySerial.deserialize(entryType, value)); } } return new ArrayList<>(); }
@Override public List<?> deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { if (!(type.getType() instanceof ParameterizedType)) { throw new ObjectMappingException("Raw types are not supported for collections"); } TypeToken<?> entryType = type.resolveType(List.class.getTypeParameters()[0]); TypeSerializer entrySerial = value.getOptions().getSerializers().get(entryType); if (entrySerial == null) { throw new ObjectMappingException("No applicable type serializer for type " + entryType); } if (value.hasListChildren()) { List<? extends ConfigurationNode> values = value.getChildrenList(); List<Object> ret = new ArrayList<>(values.size()); for (ConfigurationNode ent : values) { ret.add(entrySerial.deserialize(entryType, ent)); } return ret; } else { Object unwrappedVal = value.getValue(); if (unwrappedVal != null) { return Lists.newArrayList(entrySerial.deserialize(entryType, value)); } } return new ArrayList<>(); }
@Test public void testGetChildrenList() { ConfigurationNode root = SimpleConfigurationNode.root(); ConfigurationNode a = root.getAppendedNode().setValue("one"); ConfigurationNode b = root.getAppendedNode().setValue("two"); assertEquals(ImmutableList.of(a, b), root.getChildrenList()); }
ListConfigValue newList = new ListConfigValue(this); synchronized (newValueAsNode) { newList.setValue(newValueAsNode.getChildrenList());