Skip to content

Commit a9799b6

Browse files
committed
improved id generation. fix bmelnychuk#20
1 parent 1d90738 commit a9799b6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/src/main/java/com/unnamed/b/atv/model/TreeNode.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TreeNode {
2020
public static final String NODES_ID_SEPARATOR = ":";
2121

2222
private int mId;
23+
private int mLastId;
2324
private TreeNode mParent;
2425
private boolean mSelected;
2526
private boolean mSelectable = true;
@@ -36,15 +37,18 @@ public static TreeNode root() {
3637
return root;
3738
}
3839

40+
private int generateId() {
41+
return ++mLastId;
42+
}
43+
3944
public TreeNode(Object value) {
4045
children = new ArrayList<>();
4146
mValue = value;
4247
}
4348

4449
public TreeNode addChild(TreeNode childNode) {
4550
childNode.mParent = this;
46-
//TODO think about id generation
47-
childNode.mId = size();
51+
childNode.mId = generateId();
4852
children.add(childNode);
4953
return this;
5054
}

0 commit comments

Comments
 (0)