Skip to content

Commit 2483a37

Browse files
committed
fix comparator implementation in histogram facet
1 parent e7fdea8 commit 2483a37

File tree

1 file changed

+3
-22
lines changed
  • modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram

1 file changed

+3
-22
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacet.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,38 +66,19 @@ public static enum ComparatorType {
6666
KEY((byte) 0, "key", new Comparator<Entry>() {
6767

6868
@Override public int compare(Entry o1, Entry o2) {
69-
// really, there should not be two entries with the same value
70-
int i = (int) (o1.key() - o2.key());
71-
if (i == 0) {
72-
i = System.identityHashCode(o1) - System.identityHashCode(o2);
73-
}
74-
return i;
69+
return (o1.key() < o2.key() ? -1 : (o1.key() == o2.key() ? 0 : 1));
7570
}
7671
}),
7772
COUNT((byte) 1, "count", new Comparator<Entry>() {
7873

7974
@Override public int compare(Entry o1, Entry o2) {
80-
int i = (int) (o2.count() - o1.count());
81-
if (i == 0) {
82-
i = (int) (o2.total() - o1.total());
83-
if (i == 0) {
84-
i = System.identityHashCode(o2) - System.identityHashCode(o1);
85-
}
86-
}
87-
return i;
75+
return (o1.count() < o2.count() ? -1 : (o1.count() == o2.count() ? 0 : 1));
8876
}
8977
}),
9078
TOTAL((byte) 2, "total", new Comparator<Entry>() {
9179

9280
@Override public int compare(Entry o1, Entry o2) {
93-
int i = (int) (o2.total() - o1.total());
94-
if (i == 0) {
95-
i = (int) (o2.count() - o1.count());
96-
if (i == 0) {
97-
i = System.identityHashCode(o2) - System.identityHashCode(o1);
98-
}
99-
}
100-
return i;
81+
return (o1.total() < o2.total() ? -1 : (o1.total() == o2.total() ? 0 : 1));
10182
}
10283
});
10384

0 commit comments

Comments
 (0)