[2/4] curator git commit: CURATOR-166: Reverted to using two overloads in order to keep binary compatibiity and avoid uneeded array allocation.
CURATOR-166: Reverted to using two overloads in order to keep binary compatibiity and avoid uneeded array allocation. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/b387cf09 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/b387cf09 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/b387cf09 Branch: refs/heads/CURATOR-166 Commit: b387cf0963d184c9b2aad88a4947e1bb5ed1275d Parents: 01a23e9 Author: Ricardo Ferreira Authored: Mon Nov 17 23:02:51 2014 + Committer: Ricardo Ferreira Committed: Mon Nov 17 23:02:51 2014 + -- .../java/org/apache/curator/utils/ZKPaths.java | 95 +--- 1 file changed, 61 insertions(+), 34 deletions(-) -- http://git-wip-us.apache.org/repos/asf/curator/blob/b387cf09/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java -- diff --git a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java index 300913b..f485c62 100644 --- a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java +++ b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java @@ -282,18 +282,61 @@ public class ZKPaths Collections.sort(sortedList); return sortedList; } - + /** - * Given a parent path and a list of children nodes, create a combined full path + * Given a parent path and a child node, create a combined full path * * @param parent the parent - * @param children the children + * @param child the child * @return full path */ -public static String makePath(String parent, String... children) +public static String makePath(String parent, String child) { StringBuilder path = new StringBuilder(); +joinPath(path, parent, child); + +return path.toString(); +} + +/** + * Given a parent path and a list of children nodes, create a combined full path + * + * @param parent the parent + * @param firstChild the first children in the path + * @param restChildren the rest of the children in the path + * @return full path + */ +public static String makePath(String parent, String firstChild, String... restChildren) +{ +StringBuilder path = new StringBuilder(); + +joinPath(path, parent, firstChild); + +if ( restChildren == null ) +{ +return path.toString(); +} +else +{ +for ( String child : restChildren ) +{ +joinPath(path, "", child); +} + +return path.toString(); +} +} + +/** + * Given a parent and a child node, join them in the given {@link StringBuilder path} + * + * @param path the {@link StringBuilder} used to make the path + * @param parent the parent + * @param child the child + */ +private static void joinPath(StringBuilder path, String parent, String child) +{ // Add parent piece, with no trailing slash. if ( (parent != null) && (parent.length() > 0) ) { @@ -311,47 +354,31 @@ public class ZKPaths } } -if (children == null || children.length == 0) +if ( (child == null) || (child.length() == 0) || (child.equals(PATH_SEPARATOR)) ) { // Special case, empty parent and child if ( path.length() == 0 ) { -return PATH_SEPARATOR; +path.append(PATH_SEPARATOR); } -return path.toString(); +return; } -for (String child : children) -{ -if ( (child == null) || (child.length() == 0) || (child.equals(PATH_SEPARATOR)) ) -{ -// Special case, empty parent and child -if ( path.length() == 0 ) -{ -path.append(PATH_SEPARATOR); -} +// Now add the separator between parent and child. +path.append(PATH_SEPARATOR); -continue; -} - -// Now add the separator between parent and child. -path.append(PATH_SEPARATOR); - -if ( child.startsWith(PATH_SEPARATOR) ) -{ -child = child.substring(1); -} - -if ( child.endsWith(PATH_SEPARATOR) ) -{ -child = child.substring(0, child.length() - 1); -} +if ( child.startsWith(PATH_SEPARATOR) ) +{ +child = child.substring(1); +} -// Finally, add the child. -path.append(child); +if ( ch
[2/4] curator git commit: CURATOR-166: Reverted to using two overloads in order to keep binary compatibiity and avoid uneeded array allocation.
CURATOR-166: Reverted to using two overloads in order to keep binary compatibiity and avoid uneeded array allocation. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/b387cf09 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/b387cf09 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/b387cf09 Branch: refs/heads/master Commit: b387cf0963d184c9b2aad88a4947e1bb5ed1275d Parents: 01a23e9 Author: Ricardo Ferreira Authored: Mon Nov 17 23:02:51 2014 + Committer: Ricardo Ferreira Committed: Mon Nov 17 23:02:51 2014 + -- .../java/org/apache/curator/utils/ZKPaths.java | 95 +--- 1 file changed, 61 insertions(+), 34 deletions(-) -- http://git-wip-us.apache.org/repos/asf/curator/blob/b387cf09/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java -- diff --git a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java index 300913b..f485c62 100644 --- a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java +++ b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java @@ -282,18 +282,61 @@ public class ZKPaths Collections.sort(sortedList); return sortedList; } - + /** - * Given a parent path and a list of children nodes, create a combined full path + * Given a parent path and a child node, create a combined full path * * @param parent the parent - * @param children the children + * @param child the child * @return full path */ -public static String makePath(String parent, String... children) +public static String makePath(String parent, String child) { StringBuilder path = new StringBuilder(); +joinPath(path, parent, child); + +return path.toString(); +} + +/** + * Given a parent path and a list of children nodes, create a combined full path + * + * @param parent the parent + * @param firstChild the first children in the path + * @param restChildren the rest of the children in the path + * @return full path + */ +public static String makePath(String parent, String firstChild, String... restChildren) +{ +StringBuilder path = new StringBuilder(); + +joinPath(path, parent, firstChild); + +if ( restChildren == null ) +{ +return path.toString(); +} +else +{ +for ( String child : restChildren ) +{ +joinPath(path, "", child); +} + +return path.toString(); +} +} + +/** + * Given a parent and a child node, join them in the given {@link StringBuilder path} + * + * @param path the {@link StringBuilder} used to make the path + * @param parent the parent + * @param child the child + */ +private static void joinPath(StringBuilder path, String parent, String child) +{ // Add parent piece, with no trailing slash. if ( (parent != null) && (parent.length() > 0) ) { @@ -311,47 +354,31 @@ public class ZKPaths } } -if (children == null || children.length == 0) +if ( (child == null) || (child.length() == 0) || (child.equals(PATH_SEPARATOR)) ) { // Special case, empty parent and child if ( path.length() == 0 ) { -return PATH_SEPARATOR; +path.append(PATH_SEPARATOR); } -return path.toString(); +return; } -for (String child : children) -{ -if ( (child == null) || (child.length() == 0) || (child.equals(PATH_SEPARATOR)) ) -{ -// Special case, empty parent and child -if ( path.length() == 0 ) -{ -path.append(PATH_SEPARATOR); -} +// Now add the separator between parent and child. +path.append(PATH_SEPARATOR); -continue; -} - -// Now add the separator between parent and child. -path.append(PATH_SEPARATOR); - -if ( child.startsWith(PATH_SEPARATOR) ) -{ -child = child.substring(1); -} - -if ( child.endsWith(PATH_SEPARATOR) ) -{ -child = child.substring(0, child.length() - 1); -} +if ( child.startsWith(PATH_SEPARATOR) ) +{ +child = child.substring(1); +} -// Finally, add the child. -path.append(child); +if ( child.e