From 00d39ce7a58d1488d1fbb4d6bfcdec3bd8920e71 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 19 Sep 2017 09:15:16 -0700 Subject: [PATCH] Move checks for bitmap size == 0 to isEmpty (#4820) --- .../io/druid/query/search/UseIndexesStrategy.java | 2 +- .../segment/data/BitmapCompressedIndexedInts.java | 6 +++--- .../segment/data/ConciseBitmapSerdeFactory.java | 12 ++++++------ .../segment/data/RoaringBitmapSerdeFactory.java | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/processing/src/main/java/io/druid/query/search/UseIndexesStrategy.java b/processing/src/main/java/io/druid/query/search/UseIndexesStrategy.java index 2597747e8ec..ec4ce207854 100644 --- a/processing/src/main/java/io/druid/query/search/UseIndexesStrategy.java +++ b/processing/src/main/java/io/druid/query/search/UseIndexesStrategy.java @@ -269,7 +269,7 @@ public class UseIndexesStrategy extends SearchStrategy if (timeFilteredBitmap != null) { bitmap = bitmapFactory.intersection(Arrays.asList(timeFilteredBitmap, bitmap)); } - if (bitmap.size() > 0) { + if (!bitmap.isEmpty()) { retVal.addTo(new SearchHit(dimension.getOutputName(), dimVal), bitmap.size()); if (retVal.size() >= limit) { return retVal; diff --git a/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java b/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java index fabbbfcd82c..0dbbc9e0dbd 100644 --- a/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java +++ b/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java @@ -39,13 +39,13 @@ public class BitmapCompressedIndexedInts implements IndexedInts, Comparable conciseComparator = new Ordering() + private static final Ordering CONCISE_COMPARATOR = new Ordering() { @Override public int compare( WrappedImmutableConciseBitmap conciseSet, WrappedImmutableConciseBitmap conciseSet1 ) { - if (conciseSet.size() == 0 && conciseSet1.size() == 0) { + if (conciseSet.isEmpty() && conciseSet1.isEmpty()) { return 0; } - if (conciseSet.size() == 0) { + if (conciseSet.isEmpty()) { return -1; } - if (conciseSet1.size() == 0) { + if (conciseSet1.isEmpty()) { return 1; } return conciseSet.compareTo(conciseSet1); @@ -87,7 +87,7 @@ public class ConciseBitmapSerdeFactory implements BitmapSerdeFactory @Override public byte[] toBytes(ImmutableBitmap val) { - if (val == null || val.size() == 0) { + if (val == null || val.isEmpty()) { return new byte[]{}; } return val.toBytes(); @@ -96,7 +96,7 @@ public class ConciseBitmapSerdeFactory implements BitmapSerdeFactory @Override public int compare(ImmutableBitmap o1, ImmutableBitmap o2) { - return conciseComparator.compare((WrappedImmutableConciseBitmap) o1, (WrappedImmutableConciseBitmap) o2); + return CONCISE_COMPARATOR.compare((WrappedImmutableConciseBitmap) o1, (WrappedImmutableConciseBitmap) o2); } } diff --git a/processing/src/main/java/io/druid/segment/data/RoaringBitmapSerdeFactory.java b/processing/src/main/java/io/druid/segment/data/RoaringBitmapSerdeFactory.java index dc7c45ad70a..74bdb714327 100644 --- a/processing/src/main/java/io/druid/segment/data/RoaringBitmapSerdeFactory.java +++ b/processing/src/main/java/io/druid/segment/data/RoaringBitmapSerdeFactory.java @@ -69,20 +69,20 @@ public class RoaringBitmapSerdeFactory implements BitmapSerdeFactory return bitmapFactory; } - private static Ordering roaringComparator = new Ordering() + private static final Ordering RORING_COMPARATOR = new Ordering() { @Override public int compare( WrappedImmutableRoaringBitmap set1, WrappedImmutableRoaringBitmap set2 ) { - if (set1.size() == 0 && set2.size() == 0) { + if (set1.isEmpty() && set2.isEmpty()) { return 0; } - if (set1.size() == 0) { + if (set1.isEmpty()) { return -1; } - if (set2.size() == 0) { + if (set2.isEmpty()) { return 1; } @@ -118,7 +118,7 @@ public class RoaringBitmapSerdeFactory implements BitmapSerdeFactory @Override public int compare(ImmutableBitmap o1, ImmutableBitmap o2) { - return roaringComparator.compare((WrappedImmutableRoaringBitmap) o1, (WrappedImmutableRoaringBitmap) o2); + return RORING_COMPARATOR.compare((WrappedImmutableRoaringBitmap) o1, (WrappedImmutableRoaringBitmap) o2); } }