Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortedTreeNode - specify Comparable<T>, remove unused functions, add "lo" device, copyright #250

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}