From 301410ace25a844a7fa42b6df1b60b513623b417 Mon Sep 17 00:00:00 2001 From: Pitt Date: Wed, 5 Jan 2022 21:56:57 +0100 Subject: [PATCH] SortedTreeNode - specify Comparable, remove unused functions, add "lo" device, copyright (#250) --- .../net/atomique/ksar/ui/SortedTreeNode.java | 40 +++---------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/atomique/ksar/ui/SortedTreeNode.java b/src/main/java/net/atomique/ksar/ui/SortedTreeNode.java index faefd36..59b67a9 100644 --- a/src/main/java/net/atomique/ksar/ui/SortedTreeNode.java +++ b/src/main/java/net/atomique/ksar/ui/SortedTreeNode.java @@ -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. */ @@ -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 { public static final long serialVersionUID = 15071L; private static final Comparator comparator = Comparator.nullsFirst( - Comparator.comparing("all"::equals).thenComparing("sum"::equals) + Comparator.comparing("all"::equals) + .thenComparing("sum"::equals) + .thenComparing("lo"::equals) .reversed() .thenComparing(NaturalComparator.INSTANCE)); @@ -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; }