Skip to content

Commit

Permalink
SortedTreeNode - specify Comparable<T>, remove unused functions, add …
Browse files Browse the repository at this point in the history
…"lo" device, copyright (#250)
  • Loading branch information
Pitterling committed Jan 5, 2022
1 parent 54687ce commit 301410a
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions src/main/java/net/atomique/ksar/ui/SortedTreeNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 The kSAR Project. All rights reserved.
* Copyright 2022 The kSAR Project. All rights reserved.
* See the LICENSE file in the project root for more information.
*/

Expand All @@ -9,13 +9,15 @@
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;

public class SortedTreeNode extends DefaultMutableTreeNode implements Comparable {
public class SortedTreeNode extends DefaultMutableTreeNode implements Comparable<SortedTreeNode> {

public static final long serialVersionUID = 15071L;

private static final Comparator<String> comparator =
Comparator.nullsFirst(
Comparator.<String, Boolean>comparing("all"::equals).thenComparing("sum"::equals)
Comparator.<String, Boolean>comparing("all"::equals)
.thenComparing("sum"::equals)
.thenComparing("lo"::equals)
.reversed()
.thenComparing(NaturalComparator.INSTANCE));

Expand All @@ -31,44 +33,14 @@ public SortedTreeNode(ParentNodeInfo tmp) {
super(tmp);
}

/*
public SortedTreeNode (GraphDescription graphdesc) {
super(graphdesc);
}
*/

public void count_graph(SortedTreeNode node) {
int num = node.getChildCount();

if (num > 0) {
for (int i = 0; i < num; i++) {
SortedTreeNode l = (SortedTreeNode) node.getChildAt(i);
count_graph(l);
}
} else {
Object obj1 = node.getUserObject();
if (obj1 instanceof TreeNodeInfo) {
leaf_num++;
}
}

}

public int LeafCount() {
leaf_num = 0;
count_graph(this);
return leaf_num;
}

@Override
public void insert(final MutableTreeNode newChild, final int childIndex) {
super.insert(newChild, childIndex);
this.children.sort(null);
}

public int compareTo(final Object o) {
public int compareTo(final SortedTreeNode o) {
return comparator.compare(this.toString(), o.toString());
}

private int leaf_num = 0;
}

0 comments on commit 301410a

Please sign in to comment.