MCPcopy Create free account
hub / github.com/PCGen/pcgen / TreeTableNodeComparator

Class TreeTableNodeComparator

code/src/java/pcgen/util/Comparators.java:124–166  ·  view source on GitHub ↗

A Comparator to compare tree table nodes. This respects SORTKEY for the contained object.

Source from the content-addressed store, hash-verified

122 * A {@code Comparator} to compare tree table nodes. This respects SORTKEY for the contained object.
123 */
124 private static final class TreeTableNodeComparator implements Comparator<Object>, Serializable
125 {
126
127 @Override
128 public int compare(Object o1, Object o2)
129 {
130 String key1 = getSortKey(o1);
131 String key2 = getSortKey(o2);
132 final Collator collator = Collator.getInstance();
133
134 if (!key1.equals(key2))
135 {
136 return collator.compare(key1, key2);
137 }
138 return collator.compare(String.valueOf(o1), String.valueOf(o2));
139 }
140
141 private static String getSortKey(Object obj1)
142 {
143 String key;
144 if (obj1 == null)
145 {
146 key = "";
147 }
148 else if (obj1 instanceof CDOMObject co)
149 {
150 key = co.get(StringKey.SORT_KEY);
151 if (key == null)
152 {
153 key = co.getDisplayName();
154 }
155 }
156 else if (obj1 instanceof SortKeyAware)
157 {
158 key = ((SortKeyAware) obj1).getSortKey();
159 }
160 else
161 {
162 key = obj1.toString();
163 }
164 return key;
165 }
166 }
167
168 private static final class ToStringIgnoreCaseCollator implements Comparator<Object>, Serializable
169 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected