diff --git a/configurate-core/src/main/java/ninja/leaping/configurate/transformation/ConfigurationTransformation.java b/configurate-core/src/main/java/ninja/leaping/configurate/transformation/ConfigurationTransformation.java index 1a325fb3f..c01549f63 100644 --- a/configurate-core/src/main/java/ninja/leaping/configurate/transformation/ConfigurationTransformation.java +++ b/configurate-core/src/main/java/ninja/leaping/configurate/transformation/ConfigurationTransformation.java @@ -16,10 +16,12 @@ */ package ninja.leaping.configurate.transformation; +import com.google.common.collect.Iterators; import ninja.leaping.configurate.ConfigurationNode; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.Arrays; +import java.util.Iterator; import java.util.SortedMap; import java.util.TreeMap; @@ -172,4 +174,36 @@ public ConfigurationTransformation build() { return new VersionedTransformation(versionKey, versions); } } + + /** + * Implementation of {@link ninja.leaping.configurate.transformation.NodePath} used by this class. + */ + // TODO Remove usages of this class in favour of the NodePath interface (breaking change for 4.0) + public static final class NodePath implements ninja.leaping.configurate.transformation.NodePath { + Object[] arr; + + NodePath() { + } + + @Override + public Object get(int i) { + return arr[i]; + } + + @Override + public int size() { + return arr.length; + } + + @Override + public Object[] getArray() { + return Arrays.copyOf(arr, arr.length); + } + + @NonNull + @Override + public Iterator iterator() { + return Iterators.forArray(arr); + } + } } diff --git a/configurate-core/src/main/java/ninja/leaping/configurate/transformation/SingleConfigurationTransformation.java b/configurate-core/src/main/java/ninja/leaping/configurate/transformation/SingleConfigurationTransformation.java index 237a62247..a0e78e13c 100644 --- a/configurate-core/src/main/java/ninja/leaping/configurate/transformation/SingleConfigurationTransformation.java +++ b/configurate-core/src/main/java/ninja/leaping/configurate/transformation/SingleConfigurationTransformation.java @@ -16,12 +16,10 @@ */ package ninja.leaping.configurate.transformation; -import com.google.common.collect.Iterators; import ninja.leaping.configurate.ConfigurationNode; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -35,13 +33,13 @@ class SingleConfigurationTransformation extends ConfigurationTransformation { private final Map actions; /** - * Thread local {@link NodePath} instance - used so we don't have to create lots of NodePath + * Thread local {@link ConfigurationTransformation.NodePath} instance - used so we don't have to create lots of NodePath * instances. * * As such, data within paths is only guaranteed to be the same during a run of * a transform function. */ - private final ThreadLocal sharedPath = ThreadLocal.withInitial(NodePathImpl::new); + private final ThreadLocal sharedPath = ThreadLocal.withInitial(ConfigurationTransformation.NodePath::new); SingleConfigurationTransformation(Map actions, MoveStrategy strategy) { this.actions = actions; @@ -85,7 +83,7 @@ private void applySingleAction(ConfigurationNode start, Object[] path, int start } // apply action - NodePathImpl nodePath = sharedPath.get(); + ConfigurationTransformation.NodePath nodePath = sharedPath.get(); nodePath.arr = path; Object[] transformedPath = action.visitPath(nodePath, node); @@ -94,35 +92,4 @@ private void applySingleAction(ConfigurationNode start, Object[] path, int start node.setValue(null); } } - - /** - * Implementation of {@link NodePath} used by this class. - */ - static class NodePathImpl implements NodePath { - Object[] arr; - - NodePathImpl() { - } - - @Override - public Object get(int i) { - return arr[i]; - } - - @Override - public int size() { - return arr.length; - } - - @Override - public Object[] getArray() { - return Arrays.copyOf(arr, arr.length); - } - - @NonNull - @Override - public Iterator iterator() { - return Iterators.forArray(arr); - } - } } diff --git a/configurate-core/src/main/java/ninja/leaping/configurate/transformation/TransformAction.java b/configurate-core/src/main/java/ninja/leaping/configurate/transformation/TransformAction.java index d4b3a23f9..f49b7e56d 100644 --- a/configurate-core/src/main/java/ninja/leaping/configurate/transformation/TransformAction.java +++ b/configurate-core/src/main/java/ninja/leaping/configurate/transformation/TransformAction.java @@ -37,6 +37,6 @@ public interface TransformAction { * @return A modified path, or null if the path is to stay the same */ @Nullable - Object[] visitPath(@NonNull NodePath inputPath, @NonNull ConfigurationNode valueAtPath); + Object[] visitPath(ConfigurationTransformation.@NonNull NodePath inputPath, @NonNull ConfigurationNode valueAtPath); } diff --git a/configurate-core/src/test/java/ninja/leaping/configurate/transformation/ConfigurationTransformationTest.java b/configurate-core/src/test/java/ninja/leaping/configurate/transformation/ConfigurationTransformationTest.java index eef2b4736..286a7b59c 100644 --- a/configurate-core/src/test/java/ninja/leaping/configurate/transformation/ConfigurationTransformationTest.java +++ b/configurate-core/src/test/java/ninja/leaping/configurate/transformation/ConfigurationTransformationTest.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.SimpleConfigurationNode; +import ninja.leaping.configurate.transformation.ConfigurationTransformation.NodePath; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Test;