diff --git a/build.gradle b/build.gradle index 3d25985..8f50cd1 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'io.github.chronosx88' -version '0.2.3' +version '0.2.4' sourceCompatibility = 1.8 diff --git a/src/main/java/io/github/chronosx88/JGUN/PathRef.java b/src/main/java/io/github/chronosx88/JGUN/PathRef.java index da64844..1a0b75e 100644 --- a/src/main/java/io/github/chronosx88/JGUN/PathRef.java +++ b/src/main/java/io/github/chronosx88/JGUN/PathRef.java @@ -97,10 +97,10 @@ public class PathRef { } public void on(NodeChangeListener changeListener) { - dispatcher.addChangeListener(String.join("/", path), changeListener); + dispatcher.addChangeListener(Utils.join("/", path), changeListener); } public void map(NodeChangeListener.ForEach forEachListener) { - dispatcher.addForEachChangeListener(String.join("/", path), forEachListener); + dispatcher.addForEachChangeListener(Utils.join("/", path), forEachListener); } } diff --git a/src/main/java/io/github/chronosx88/JGUN/Utils.java b/src/main/java/io/github/chronosx88/JGUN/Utils.java index 823ef78..ceabdae 100644 --- a/src/main/java/io/github/chronosx88/JGUN/Utils.java +++ b/src/main/java/io/github/chronosx88/JGUN/Utils.java @@ -5,6 +5,7 @@ import io.github.chronosx88.JGUN.storageBackends.StorageBackend; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Iterator; import java.util.concurrent.ConcurrentSkipListSet; public class Utils { @@ -76,7 +77,7 @@ public class Utils { if(value instanceof JSONObject) { path.add(key); String soul = ""; - soul = String.join("/", path); + soul = Utils.join("/", path); Node tmpNode = Utils.newNode(soul, (JSONObject) value); node.values.remove(key); node.values.put(key, new JSONObject().put("#", soul)); @@ -119,4 +120,27 @@ public class Utils { for(node) } }*/ + + /** + * Returns a string containing the tokens joined by delimiters. + * + * @param delimiter a CharSequence that will be inserted between the tokens. If null, the string + * "null" will be used as the delimiter. + * @param tokens an array objects to be joined. Strings will be formed from the objects by + * calling object.toString(). If tokens is null, a NullPointerException will be thrown. If + * tokens is empty, an empty string will be returned. + */ + public static String join(CharSequence delimiter, Iterable tokens) { + final Iterator it = tokens.iterator(); + if (!it.hasNext()) { + return ""; + } + final StringBuilder sb = new StringBuilder(); + sb.append(it.next()); + while (it.hasNext()) { + sb.append(delimiter); + sb.append(it.next()); + } + return sb.toString(); + } }