IdPath { public boolean isChildOrParentOf(IdPath p) { return startsWith(p) || p.startsWith(this); } IdPath(int... parts);  IdPath(Stream s); void write(Stream s); int getId(); IdPath getParent(); IdPath appendedWith(int id); boolean isChildOrParentOf(IdPath p); boolean contains(int id); boolean startsWith(IdPath p); boolean rootEquals(int id); IdPath withoutRoot(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testIsChildOrParent() { IdPath p = new IdPath(1, 2, 3, 4); assertTrue(p.isChildOrParentOf(new IdPath(1))); assertTrue(p.isChildOrParentOf(new IdPath(1, 2, 3))); assertTrue(p.isChildOrParentOf(new IdPath(1, 2, 3, 4))); assertTrue(p.isChildOrParentOf(new IdPath(1, 2, 3, 4, 5, 6))); assertFalse(p.isChildOrParentOf(new IdPath(2))); assertFalse(p.isChildOrParentOf(new IdPath(1, 22))); assertFalse(p.isChildOrParentOf(new IdPath(1, 2, 33, 4))); assertFalse(p.isChildOrParentOf(new IdPath(1, 2, 3, 5))); }