From 2483a37db5400e5d6ede8084a52d670cbb54b4f8 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 16 Nov 2010 15:30:27 +0200 Subject: [PATCH] fix comparator implementation in histogram facet --- .../facet/histogram/HistogramFacet.java | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacet.java index 9f749be50c3..8c0f1034db3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/HistogramFacet.java @@ -66,38 +66,19 @@ public interface HistogramFacet extends Facet, Iterable { KEY((byte) 0, "key", new Comparator() { @Override public int compare(Entry o1, Entry o2) { - // really, there should not be two entries with the same value - int i = (int) (o1.key() - o2.key()); - if (i == 0) { - i = System.identityHashCode(o1) - System.identityHashCode(o2); - } - return i; + return (o1.key() < o2.key() ? -1 : (o1.key() == o2.key() ? 0 : 1)); } }), COUNT((byte) 1, "count", new Comparator() { @Override public int compare(Entry o1, Entry o2) { - int i = (int) (o2.count() - o1.count()); - if (i == 0) { - i = (int) (o2.total() - o1.total()); - if (i == 0) { - i = System.identityHashCode(o2) - System.identityHashCode(o1); - } - } - return i; + return (o1.count() < o2.count() ? -1 : (o1.count() == o2.count() ? 0 : 1)); } }), TOTAL((byte) 2, "total", new Comparator() { @Override public int compare(Entry o1, Entry o2) { - int i = (int) (o2.total() - o1.total()); - if (i == 0) { - i = (int) (o2.count() - o1.count()); - if (i == 0) { - i = System.identityHashCode(o2) - System.identityHashCode(o1); - } - } - return i; + return (o1.total() < o2.total() ? -1 : (o1.total() == o2.total() ? 0 : 1)); } });