Add more utility methods to DocumentPath
Change-Id: I993006c45187be1cb7d4b627a5c9d7c5ee5edec9
diff --git a/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java b/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
index 8c969aa..25caabe 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
@@ -125,9 +125,38 @@
* @return {@code DocumentPath} instance
*/
public static DocumentPath from(List<String> elements, String child) {
- elements = new ArrayList<>(elements);
- elements.add(child);
- return from(elements);
+ List<String> concat = new ArrayList<>(elements.size() + 1);
+ concat.addAll(elements);
+ concat.add(child);
+ return from(concat);
+ }
+
+ /**
+ * Creates a new {@code DocumentPath} from a list of path elements.
+ *
+ * @param elements path elements
+ * @param childElms child element
+ * @return {@code DocumentPath} instance
+ */
+ public static DocumentPath from(List<String> elements, String... childElms) {
+ List<String> concat = new ArrayList<>(elements.size() + childElms.length);
+ concat.addAll(elements);
+ concat.addAll(Arrays.asList(childElms));
+ return from(concat);
+ }
+
+ /**
+ * Creates a new DocumentPath element appending {@code childElm} to
+ * this path.
+ *
+ * @param childElms to append
+ * @return this + childElm
+ */
+ public DocumentPath append(List<String> childElms) {
+ List<String> concat = new ArrayList<>(pathElements.size() + childElms.size());
+ concat.addAll(pathElements);
+ concat.addAll(childElms);
+ return from(concat);
}
/**