CloudnamePath { public boolean isSubpathOf(final CloudnamePath other) { if (other == null) { return false; } if (this.pathElements.length > other.pathElements.length) { return false; } if (this.pathElements.length == 0) { return true; } for (int i = 0; i < this.pathElements.length; i++) { if (!other.pathElements[i].equals(this.pathElements[i])) { return false; } } return true; } CloudnamePath(final String[] pathElements);  CloudnamePath(final CloudnamePath path, final String additionalElement); static boolean isValidPathElementName(final String name); int length(); String join(final char separator); String get(final int index); boolean isSubpathOf(final CloudnamePath other); CloudnamePath getParent(); @Override boolean equals(final Object other); @Override int hashCode(); @Override String toString();  }
@Test public void subpaths() { final String[] e1 = new String[] { "1", "2", "3", "4" }; final String[] e2 = new String[] { "1", "2" }; final CloudnamePath first = new CloudnamePath(e1); final CloudnamePath second = new CloudnamePath(e2); final CloudnamePath last = new CloudnamePath(twoElements); assertThat("More specific paths can't be subpaths", first.isSubpathOf(second), is(false)); assertThat("More generic paths are subpaths", second.isSubpathOf(first), is(true)); assertThat("A path can be subpath of itself", first.isSubpathOf(first), is(true)); assertThat("Paths must match at root levels", last.isSubpathOf(second), is(false)); assertThat("Null paths are not subpaths of anything", first.isSubpathOf(null), is(false)); final CloudnamePath empty = new CloudnamePath(emptyElements); assertThat("An empty path is a subpath of everything", empty.isSubpathOf(first), is(true)); assertThat("Empty paths can't have subpaths", first.isSubpathOf(empty), is(false)); }