mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-02-18 00:20:10 +00:00
added code to prevent adding duplicate children to a gtree node
This commit is contained in:
parent
42b8eb3096
commit
cc65ab7e4a
@ -183,9 +183,7 @@ abstract class CoreGTreeNode implements Cloneable {
|
||||
* @param node the node to add as a child to this node
|
||||
*/
|
||||
protected synchronized void doAddNode(GTreeNode node) {
|
||||
children().add(node);
|
||||
node.setParent((GTreeNode) this);
|
||||
doFireNodeAdded(node);
|
||||
doAddNode(children().size(), node);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,6 +194,9 @@ abstract class CoreGTreeNode implements Cloneable {
|
||||
*/
|
||||
protected synchronized void doAddNode(int index, GTreeNode node) {
|
||||
List<GTreeNode> kids = children();
|
||||
if (kids.contains(node)) {
|
||||
return;
|
||||
}
|
||||
int insertIndex = Math.min(kids.size(), index);
|
||||
kids.add(insertIndex, node);
|
||||
node.setParent((GTreeNode) this);
|
||||
|
@ -456,6 +456,24 @@ public class GTreeNodeTest {
|
||||
assertNotEquals(nodeA.hashCode(), nodeB.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCantAddNodeTwice() {
|
||||
node0 = new TestNode("No Dups");
|
||||
|
||||
int childCount = root.getChildCount();
|
||||
root.addNode(node0);
|
||||
assertEquals(childCount + 1, root.getChildCount());
|
||||
|
||||
// now make sure the count doesn't grow again
|
||||
root.addNode(node0);
|
||||
assertEquals(childCount + 1, root.getChildCount());
|
||||
|
||||
// try adding it with an index, still shouldn't get added
|
||||
root.addNode(0, node0);
|
||||
assertEquals(childCount + 1, root.getChildCount());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneEquals() throws CloneNotSupportedException {
|
||||
GTreeNode nodeA = new TestNode("AAA");
|
||||
|
Loading…
Reference in New Issue
Block a user