use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testEmptyDataToNode.
@Test
void testEmptyDataToNode() {
final DataContainer source = DataContainer.createNew();
final ConfigurationNode destination = ConfigurateTranslator.instance().translate(source);
assertTrue(destination.empty());
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class HoconDataFormat method writeTo.
private static void writeTo(final Callable<BufferedWriter> sink, final DataView data) throws IOException {
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder().sink(sink).build();
final ConfigurationNode node = loader.createNode();
ConfigurateTranslator.instance().translateDataToNode(node, data);
try {
loader.save(node);
} catch (final ConfigurateException ex) {
throw new IOException(ex);
}
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class FileMovingConfigurationTransformation method apply.
@Override
public void apply(@NonNull final ConfigurationNode oldConfig) throws ConfigurateException {
final ConfigurationNode newConfig = this.destinationLoader.load();
boolean acted = false;
for (final NodePath path : this.paths) {
final ConfigurationNode source = oldConfig.node(path);
if (!source.virtual()) {
acted = true;
if (this.override) {
newConfig.node(path).from(source);
} else {
newConfig.node(path).mergeFrom(source);
}
source.raw(null);
}
}
if (acted) {
this.destinationLoader.save(newConfig);
}
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class DuplicateRemovalVisitor method enterScalarNode.
@Override
@SuppressWarnings("UnnecessaryUnboxing")
public void enterScalarNode(final ConfigurationNode node, final AtomicReference<ConfigurationNode> parent) {
final ConfigurationNode parentNode = this.popParent(parent);
// ignore list values
if (this.isListElement(node)) {
return;
}
// ignore the version key that's a child of the root node
if (Objects.equals(node.key(), "version") && node.parent().parent() == null) {
return;
}
// if the node already exists in the parent config, remove it
if (Objects.equals(node.raw(), parentNode.raw())) {
node.raw(null);
return;
}
// Fix double bug
final Double nodeVal = Scalars.DOUBLE.tryDeserialize(node.raw());
if (nodeVal != null) {
final Double parentVal = Scalars.DOUBLE.tryDeserialize(parentNode.raw());
if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) {
node.raw(null);
}
}
}
use of org.spongepowered.configurate.ConfigurationNode in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testNumber.
@Test
void testNumber() throws IOException {
final DataContainer container = DataContainer.createNew().set(DataQuery.of("double"), 1.0);
final ConfigurationNode node = ConfigurateTranslator.instance().translate(container);
assertEquals(1.0, node.node("double").raw());
final DataContainer dc = ConfigurateTranslator.instance().translate(node);
assertEquals(container, dc);
}
Aggregations