Merge pull request #2482 from navis/lazy-init-boundfilter

Lazily initialize predicate for bound filter
This commit is contained in:
Slim 2016-02-29 07:18:35 -06:00
commit 5aa1164b1a
1 changed files with 40 additions and 24 deletions

View File

@ -33,6 +33,25 @@ public class BoundFilter extends DimensionPredicateFilter
{
super(
boundDimFilter.getDimension(), new Predicate<String>()
{
private volatile Predicate<String> predicate;
@Override
public boolean apply(String input)
{
return function().apply(input);
}
private Predicate<String> function()
{
if (predicate == null) {
final Comparator<String> comparator;
if (boundDimFilter.isAlphaNumeric()) {
comparator = new AlphaNumericTopNMetricSpec(null).getComparator(null, null);
} else {
comparator = new LexicographicTopNMetricSpec(null).getComparator(null, null);
}
predicate = new Predicate<String>()
{
@Override
public boolean apply(String input)
@ -40,13 +59,6 @@ public class BoundFilter extends DimensionPredicateFilter
if (input == null) {
return false;
}
Comparator<String> comparator;
if (boundDimFilter.isAlphaNumeric()) {
comparator = new AlphaNumericTopNMetricSpec(null).getComparator(null, null);
} else {
comparator = new LexicographicTopNMetricSpec(null).getComparator(null, null);
}
int lowerComparing = 1;
int upperComparing = 1;
if (boundDimFilter.getLower() != null) {
@ -64,6 +76,10 @@ public class BoundFilter extends DimensionPredicateFilter
}
return (lowerComparing >= 0) && (upperComparing >= 0);
}
};
}
return predicate;
}
}
);
}