mirror of https://github.com/apache/druid.git
Use java 8 features in TierSelectorStrategy implementations (#4827)
* Use java 8 features in TierSelectorStrategy implementations * Minor code cleanup * More java8 coolness * Code comments
This commit is contained in:
parent
a36adc63e4
commit
47ebc48059
|
@ -22,7 +22,6 @@ package io.druid.client.selector;
|
|||
import com.fasterxml.jackson.annotation.JacksonInject;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
@ -48,16 +47,7 @@ public class CustomTierSelectorStrategy extends AbstractTierSelectorStrategy
|
|||
pos++;
|
||||
}
|
||||
|
||||
this.comparator = new Comparator<Integer>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2)
|
||||
{
|
||||
int pos1 = lookup.get(o1);
|
||||
int pos2 = lookup.get(o2);
|
||||
return Ints.compare(pos1, pos2);
|
||||
}
|
||||
};
|
||||
this.comparator = Comparator.comparingInt(lookup::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ package io.druid.client.selector;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JacksonInject;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
|
@ -29,15 +28,6 @@ import java.util.Comparator;
|
|||
*/
|
||||
public class HighestPriorityTierSelectorStrategy extends AbstractTierSelectorStrategy
|
||||
{
|
||||
private static final Comparator<Integer> comparator = new Comparator<Integer>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2)
|
||||
{
|
||||
return Ints.compare(o2, o1);
|
||||
}
|
||||
};
|
||||
|
||||
@JsonCreator
|
||||
public HighestPriorityTierSelectorStrategy(@JacksonInject ServerSelectorStrategy serverSelectorStrategy)
|
||||
{
|
||||
|
@ -47,6 +37,6 @@ public class HighestPriorityTierSelectorStrategy extends AbstractTierSelectorStr
|
|||
@Override
|
||||
public Comparator<Integer> getComparator()
|
||||
{
|
||||
return comparator;
|
||||
return Comparator.reverseOrder();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package io.druid.client.selector;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JacksonInject;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
|
@ -29,15 +28,6 @@ import java.util.Comparator;
|
|||
*/
|
||||
public class LowestPriorityTierSelectorStrategy extends AbstractTierSelectorStrategy
|
||||
{
|
||||
private static final Comparator<Integer> comparator = new Comparator<Integer>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2)
|
||||
{
|
||||
return Ints.compare(o1, o2);
|
||||
}
|
||||
};
|
||||
|
||||
@JsonCreator
|
||||
public LowestPriorityTierSelectorStrategy(@JacksonInject ServerSelectorStrategy serverSelectorStrategy)
|
||||
{
|
||||
|
@ -47,6 +37,6 @@ public class LowestPriorityTierSelectorStrategy extends AbstractTierSelectorStra
|
|||
@Override
|
||||
public Comparator<Integer> getComparator()
|
||||
{
|
||||
return comparator;
|
||||
return Comparator.naturalOrder();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue