ItEr54S04ValidacionEProbasFuncionaisItEr53S04: Add method to check if an object is contained on the tree.
This commit is contained in:
parent
0ed32cedda
commit
bbca20332b
2 changed files with 16 additions and 0 deletions
|
|
@ -386,6 +386,10 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
|
|||
return getChildCount(node) > 0;
|
||||
}
|
||||
|
||||
public boolean contains(T object) {
|
||||
return find(object) != null;
|
||||
}
|
||||
|
||||
public boolean contains(T parent, T child) {
|
||||
Node<T> parentNode = find(parent);
|
||||
Node<T> childNode = find(child);
|
||||
|
|
|
|||
|
|
@ -488,6 +488,18 @@ public class MutableTreeModelTest {
|
|||
assertThat(model.getChild(model.getRoot(), 1), equalTo(prueba2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canBeKnownIfAnEntityIsOnTheTree() {
|
||||
final MutableTreeModel<Prueba> model = MutableTreeModel
|
||||
.create(Prueba.class);
|
||||
Prueba prueba1 = new Prueba();
|
||||
model.addToRoot(prueba1);
|
||||
|
||||
assertTrue(model.contains(prueba1));
|
||||
assertTrue(model.contains(model.getRoot()));
|
||||
assertFalse(model.contains(new Prueba()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void treeParentContainsChild() {
|
||||
final MutableTreeModel<Prueba> model = MutableTreeModel
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue