mirror of https://github.com/apache/druid.git
Faster interval comparator (#3605)
This commit is contained in:
parent
98465f47b5
commit
0799640299
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package io.druid.java.util.common.guava;
|
package io.druid.java.util.common.guava;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
import org.joda.time.DateTimeComparator;
|
import org.joda.time.DateTimeComparator;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
|
|
||||||
|
@ -74,6 +75,13 @@ public class Comparators
|
||||||
@Override
|
@Override
|
||||||
public int compare(Interval lhs, Interval rhs)
|
public int compare(Interval lhs, Interval rhs)
|
||||||
{
|
{
|
||||||
|
if (lhs.getChronology().equals(rhs.getChronology())) {
|
||||||
|
int compare = Longs.compare(lhs.getStartMillis(), rhs.getStartMillis());
|
||||||
|
if (compare == 0) {
|
||||||
|
return Longs.compare(lhs.getEndMillis(), rhs.getEndMillis());
|
||||||
|
}
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
int retVal = dateTimeComp.compare(lhs.getStart(), rhs.getStart());
|
int retVal = dateTimeComp.compare(lhs.getStart(), rhs.getStart());
|
||||||
if (retVal == 0) {
|
if (retVal == 0) {
|
||||||
retVal = dateTimeComp.compare(lhs.getEnd(), rhs.getEnd());
|
retVal = dateTimeComp.compare(lhs.getEnd(), rhs.getEnd());
|
||||||
|
@ -89,6 +97,13 @@ public class Comparators
|
||||||
@Override
|
@Override
|
||||||
public int compare(Interval lhs, Interval rhs)
|
public int compare(Interval lhs, Interval rhs)
|
||||||
{
|
{
|
||||||
|
if (lhs.getChronology().equals(rhs.getChronology())) {
|
||||||
|
int compare = Longs.compare(lhs.getEndMillis(), rhs.getEndMillis());
|
||||||
|
if (compare == 0) {
|
||||||
|
return Longs.compare(lhs.getStartMillis(), rhs.getStartMillis());
|
||||||
|
}
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
int retVal = dateTimeComp.compare(lhs.getEnd(), rhs.getEnd());
|
int retVal = dateTimeComp.compare(lhs.getEnd(), rhs.getEnd());
|
||||||
if (retVal == 0) {
|
if (retVal == 0) {
|
||||||
retVal = dateTimeComp.compare(lhs.getStart(), rhs.getStart());
|
retVal = dateTimeComp.compare(lhs.getStart(), rhs.getStart());
|
||||||
|
|
Loading…
Reference in New Issue