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:
Charles Allen 2017-09-20 20:09:29 -07:00 committed by Roman Leventov
parent a36adc63e4
commit 47ebc48059
3 changed files with 3 additions and 33 deletions

View File

@ -22,7 +22,6 @@ package io.druid.client.selector;
import com.fasterxml.jackson.annotation.JacksonInject; import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.primitives.Ints;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
@ -48,16 +47,7 @@ public class CustomTierSelectorStrategy extends AbstractTierSelectorStrategy
pos++; pos++;
} }
this.comparator = new Comparator<Integer>() this.comparator = Comparator.comparingInt(lookup::get);
{
@Override
public int compare(Integer o1, Integer o2)
{
int pos1 = lookup.get(o1);
int pos2 = lookup.get(o2);
return Ints.compare(pos1, pos2);
}
};
} }
@Override @Override

View File

@ -21,7 +21,6 @@ package io.druid.client.selector;
import com.fasterxml.jackson.annotation.JacksonInject; import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.google.common.primitives.Ints;
import java.util.Comparator; import java.util.Comparator;
@ -29,15 +28,6 @@ import java.util.Comparator;
*/ */
public class HighestPriorityTierSelectorStrategy extends AbstractTierSelectorStrategy 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 @JsonCreator
public HighestPriorityTierSelectorStrategy(@JacksonInject ServerSelectorStrategy serverSelectorStrategy) public HighestPriorityTierSelectorStrategy(@JacksonInject ServerSelectorStrategy serverSelectorStrategy)
{ {
@ -47,6 +37,6 @@ public class HighestPriorityTierSelectorStrategy extends AbstractTierSelectorStr
@Override @Override
public Comparator<Integer> getComparator() public Comparator<Integer> getComparator()
{ {
return comparator; return Comparator.reverseOrder();
} }
} }

View File

@ -21,7 +21,6 @@ package io.druid.client.selector;
import com.fasterxml.jackson.annotation.JacksonInject; import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.google.common.primitives.Ints;
import java.util.Comparator; import java.util.Comparator;
@ -29,15 +28,6 @@ import java.util.Comparator;
*/ */
public class LowestPriorityTierSelectorStrategy extends AbstractTierSelectorStrategy 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 @JsonCreator
public LowestPriorityTierSelectorStrategy(@JacksonInject ServerSelectorStrategy serverSelectorStrategy) public LowestPriorityTierSelectorStrategy(@JacksonInject ServerSelectorStrategy serverSelectorStrategy)
{ {
@ -47,6 +37,6 @@ public class LowestPriorityTierSelectorStrategy extends AbstractTierSelectorStra
@Override @Override
public Comparator<Integer> getComparator() public Comparator<Integer> getComparator()
{ {
return comparator; return Comparator.naturalOrder();
} }
} }