[New] added Locator.isEqualOrChildOf() including tests
This commit is contained in:
parent
1b9e687d42
commit
74366ea8a5
|
@ -226,7 +226,23 @@ public class Locator {
|
||||||
* Returns true if the given locator's path elements is the beginning of this locator's path elements
|
* Returns true if the given locator's path elements is the beginning of this locator's path elements
|
||||||
*
|
*
|
||||||
* @param locator
|
* @param locator
|
||||||
* @return
|
*
|
||||||
|
* @return true if the given locator's path elements is the beginning of this locator's path elements
|
||||||
|
*/
|
||||||
|
public boolean isEqualOrChildOf(Locator locator) {
|
||||||
|
if (locator.pathElements.size() > this.pathElements.size())
|
||||||
|
return false;
|
||||||
|
return this.pathElements.subList(0, locator.pathElements.size()).equals(locator.pathElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given locator's path elements is the beginning of this locator's path elements, but not if
|
||||||
|
* they are the same, i.e. must be an actual child
|
||||||
|
*
|
||||||
|
* @param locator
|
||||||
|
*
|
||||||
|
* @return true if the given locator's path elements is the beginning of this locator's path elements, but not if
|
||||||
|
* they are the same, i.e. must be an actual child
|
||||||
*/
|
*/
|
||||||
public boolean isChildOf(Locator locator) {
|
public boolean isChildOf(Locator locator) {
|
||||||
if (locator.pathElements.size() >= this.pathElements.size())
|
if (locator.pathElements.size() >= this.pathElements.size())
|
||||||
|
|
|
@ -94,4 +94,39 @@ public class LocatorTest {
|
||||||
Locator child = Locator.valueOf("Resource/MyType/@myObj");
|
Locator child = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
assertFalse(child.isChildOf(parent));
|
assertFalse(child.isChildOf(parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldBeEqualOrChild1() {
|
||||||
|
Locator parent = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
|
Locator child = Locator.valueOf("Resource/MyType/@myObj/Bags/@bag1/Parameters/@param1");
|
||||||
|
assertTrue(child.isEqualOrChildOf(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldBeEqualOrChild2() {
|
||||||
|
Locator parent = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
|
Locator child = Locator.valueOf("Resource/MyType/@myObj/Bags/");
|
||||||
|
assertTrue(child.isEqualOrChildOf(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldBeEqualOrChild3() {
|
||||||
|
Locator parent = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
|
Locator child = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
|
assertTrue(child.isEqualOrChildOf(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotBeEqualOrChild1() {
|
||||||
|
Locator parent = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
|
Locator child = Locator.valueOf("Resource/OtherType/@myObj/Bags/");
|
||||||
|
assertFalse(child.isEqualOrChildOf(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotBeEqualOrChild2() {
|
||||||
|
Locator parent = Locator.valueOf("Resource/MyType/@myObj");
|
||||||
|
Locator child = Locator.valueOf("Resource/MyType/@myObj1");
|
||||||
|
assertFalse(child.isEqualOrChildOf(parent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue