private void parseArray(JsonParser parser, ConfigurationNode node) throws IOException { JsonToken token; while ((token = parser.nextToken()) != null) { switch (token) { case END_ARRAY: return; default: parseValue(parser, node.getAppendedNode()); } } throw new JsonParseException("Reached end of stream with unclosed array!", parser.getCurrentLocation()); }
private void parseArray(JsonReader parser, ConfigurationNode node) throws IOException { parser.beginArray(); JsonToken token; while ((token = parser.peek()) != null) { switch (token) { case END_ARRAY: parser.endArray(); return; default: parseValue(parser, node.getAppendedNode()); } } throw new JsonParseException("Reached end of stream with unclosed array at!"); }
private void parseArray(JsonReader parser, ConfigurationNode node) throws IOException { parser.beginArray(); JsonToken token; while ((token = parser.peek()) != null) { switch (token) { case END_ARRAY: parser.endArray(); return; default: parseValue(parser, node.getAppendedNode()); } } throw new JsonParseException("Reached end of stream with unclosed array at!"); }
private void parseArray(JsonReader parser, ConfigurationNode node) throws IOException { parser.beginArray(); JsonToken token; while ((token = parser.peek()) != null) { switch (token) { case END_ARRAY: parser.endArray(); return; default: parseValue(parser, node.getAppendedNode()); } } throw new JsonParseException("Reached end of stream with unclosed array at!"); }
private static void parseArray(JsonParser parser, ConfigurationNode node) throws IOException { JsonToken token; while ((token = parser.nextToken()) != null) { switch (token) { case END_ARRAY: return; default: parseValue(parser, node.getAppendedNode()); } } throw new JsonParseException(parser, "Reached end of stream with unclosed array!", parser.getCurrentLocation()); }
@Override public CompletableFuture<RankLadder> setRankLadderInternal(String identifier, RankLadder ladder) { ConfigurationNode childNode = getRankLaddersNode().getNode(identifier.toLowerCase()); childNode.setValue(null); if (ladder != null) { for (Map.Entry<String, String> rank : ladder.getRanks()) { childNode.getAppendedNode().setValue(Util.subjectToString(rank)); } } dirty.set(true); return save().thenApply(none -> ladder); }
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); } }
@Override public void serialize(TypeToken<?> type, Set<?> obj, 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); } value.setValue(ImmutableSet.of()); for (Object ent : obj) { entrySerial.serialize(entryType, ent, value.getAppendedNode()); } } }
@Test public void testListRawTypes() throws ObjectMappingException { final TypeToken<List> rawType = TypeToken.of(List.class); final TypeSerializer<List> serial = SERIALIZERS.get(rawType); final ConfigurationNode value = SimpleConfigurationNode.root(); value.getAppendedNode().setValue(1); value.getAppendedNode().setValue("dog"); value.getAppendedNode().setValue(2.4); Assertions.assertTrue(Assertions.assertThrows(Exception.class, () -> { serial.deserialize(rawType, value); }).getMessage().startsWith("Raw types")); }
@Override public void serialize(TypeToken<?> type, List<?> obj, 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); } value.setValue(ImmutableList.of()); for (Object ent : obj) { entrySerial.serialize(entryType, ent, value.getAppendedNode()); } } }
@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()); }
ConfigurationNode ladderNode = configurationNode.getNode(FileDataStore.KEY_RANK_LADDERS, ent.getKey()); for (Map.Entry<String, Integer> grp : ent.getValue()) { ladderNode.getAppendedNode().setValue("group:" + grp.getKey());
@Test public void testListPacking() { ConfigurationNode root = SimpleConfigurationNode.root(); root.getAppendedNode().setValue("test1"); root.getAppendedNode().setValue("test2"); assertEquals(TEST_LIST, root.getValue()); }
@Override public void serialize(@NonNull TypeToken<?> type, @Nullable List<?> obj, @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); } value.setValue(ImmutableList.of()); for (Object ent : obj) { entrySerial.serialize(entryType, ent, value.getAppendedNode()); } } }
@Override public void serialize(@NonNull TypeToken<?> type, @Nullable List<?> obj, @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); } value.setValue(ImmutableList.of()); for (Object ent : obj) { entrySerial.serialize(entryType, ent, value.getAppendedNode()); } } }
@Test public void testSingleListConversion() { ConfigurationNode config = SimpleConfigurationNode.root(); ConfigurationNode node = config.getNode("test", "value"); node.setValue("test"); ConfigurationNode secondChild = node.getAppendedNode(); secondChild.setValue("test2"); assertEquals(Arrays.asList("test", "test2"), node.getValue()); }
@Test public void testListSerializer() throws ObjectMappingException { final TypeToken<List<String>> stringListType = new TypeToken<List<String>>() {}; final TypeSerializer<List<String>> stringListSerializer = SERIALIZERS.get(stringListType); final ConfigurationNode value = SimpleConfigurationNode.root(); value.getAppendedNode().setValue("hi"); value.getAppendedNode().setValue("there"); value.getAppendedNode().setValue("beautiful"); value.getAppendedNode().setValue("people"); assertEquals(Arrays.asList("hi", "there", "beautiful", "people"), stringListSerializer.deserialize(stringListType, value)); value.setValue(null); stringListSerializer.serialize(stringListType, Arrays.asList("hi", "there", "lame", "people"), value); assertEquals("hi", value.getNode(0).getString()); assertEquals("there", value.getNode(1).getString()); assertEquals("lame", value.getNode(2).getString()); assertEquals("people", value.getNode(3).getString()); }
Object value = configurationNode.getValue(); configurationNode.setValue(null); configurationNode.getAppendedNode().setValue(value); return null; }) ConfigurationNode entityNode = configurationNode.getParent().getParent(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : configurationNode.getChildrenMap().entrySet()) { entityNode.getAppendedNode().setValue(ent.getValue()) .getNode(FileSubjectData.KEY_CONTEXTS, "world").setValue(ent.getKey()); addToNode = defaultsParent.getAppendedNode(); addToNode.getNode("parents").getAppendedNode().setValue("group:" + valueAtPath.getParent().getKey());
ConfigurationNode itemsNode = node.getNode("items"); for (CachedCrateReward reward : crate.getRewards()) { ConfigurationNode rewardNode = itemsNode.getAppendedNode(); rewardNode.getNode("name").setValue(reward.getName()); if (reward.getDisplayItem() != null) object.saveToNode(rewardsNode.getAppendedNode());
@Test public void testSimpleCopy() { ConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("test").setValue(5); node.getNode("section", "val1").setValue(true); node.getNode("section", "val2").setValue("TEST"); ConfigurationNode list = node.getNode("section2", "alist"); list.getAppendedNode().setValue("value1"); list.getAppendedNode().setValue("value2"); ConfigurationNode copy = node.copy(); assertNotSame(node, copy); assertEquals(node, copy); assertFalse(node.isVirtual()); assertFalse(copy.isVirtual()); assertEquals(5, copy.getNode("test").getValue()); assertEquals(true, copy.getNode("section", "val1").getValue()); assertEquals("TEST", copy.getNode("section", "val2").getValue()); assertEquals(ImmutableList.of("value1", "value2"), copy.getNode("section2", "alist").getValue()); // change value on original node.getNode("section", "val2").setValue("NOT TEST"); // test it's still the same on copy assertEquals("TEST", copy.getNode("section", "val2").getValue()); // change value on copy copy.getNode("section", "val2").setValue("zzz"); // test it's still the same on original assertEquals("NOT TEST", node.getNode("section", "val2").getValue()); }