diff --git a/api/src/main/java/org/apache/druid/guice/LifecycleScope.java b/api/src/main/java/org/apache/druid/guice/LifecycleScope.java index 5c3bedf74d3..e8496c1e3ec 100644 --- a/api/src/main/java/org/apache/druid/guice/LifecycleScope.java +++ b/api/src/main/java/org/apache/druid/guice/LifecycleScope.java @@ -19,13 +19,13 @@ package org.apache.druid.guice; -import com.google.common.collect.Lists; import com.google.inject.Key; import com.google.inject.Provider; import com.google.inject.Scope; import org.apache.druid.java.util.common.lifecycle.Lifecycle; import org.apache.druid.java.util.common.logger.Logger; +import java.util.ArrayList; import java.util.List; /** @@ -37,7 +37,7 @@ public class LifecycleScope implements Scope private final Lifecycle.Stage stage; private Lifecycle lifecycle; - private final List instances = Lists.newLinkedList(); + private final List instances = new ArrayList<>(); public LifecycleScope(Lifecycle.Stage stage) { diff --git a/codestyle/druid-forbidden-apis.txt b/codestyle/druid-forbidden-apis.txt index 8959c18dee3..aaeac46fafb 100644 --- a/codestyle/druid-forbidden-apis.txt +++ b/codestyle/druid-forbidden-apis.txt @@ -4,4 +4,8 @@ com.google.common.util.concurrent.Futures#transform(com.google.common.util.concu com.google.common.collect.Iterators#emptyIterator() @ Use java.util.Collections#emptyIterator() com.google.common.base.Charsets @ Use java.nio.charset.StandardCharsets instead java.io.File#toURL() @ Use java.io.File#toURI() and java.net.URI#toURL() instead -org.apache.commons.io.FileUtils#getTempDirectory() @ Use org.junit.rules.TemporaryFolder for tests instead \ No newline at end of file +org.apache.commons.io.FileUtils#getTempDirectory() @ Use org.junit.rules.TemporaryFolder for tests instead + +java.util.LinkedList @ Use ArrayList or ArrayDeque instead +com.google.common.collect.Lists#newLinkedList() @ Use ArrayList or ArrayDeque instead +com.google.common.collect.Lists#newLinkedList(java.lang.Iterable) @ Use ArrayList or ArrayDeque instead diff --git a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramTest.java b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramTest.java index 411466c1a6f..ddb71ed8327 100644 --- a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramTest.java +++ b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramTest.java @@ -20,12 +20,12 @@ package org.apache.druid.query.aggregation.histogram; import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; import org.apache.druid.java.util.common.StringUtils; import org.junit.Assert; import org.junit.Test; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -239,7 +239,7 @@ public class ApproximateHistogramTest randNums[i] = (float) rand.nextGaussian(); } - List randHist = Lists.newLinkedList(); + List randHist = new ArrayList<>(); Iterator it = Iterators.cycle(randHist); for (int k = 0; k < numRand; ++k) { diff --git a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/IncrementalPublishingKafkaIndexTaskRunner.java b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/IncrementalPublishingKafkaIndexTaskRunner.java index 96167571f72..e815cfa3016 100644 --- a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/IncrementalPublishingKafkaIndexTaskRunner.java +++ b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/IncrementalPublishingKafkaIndexTaskRunner.java @@ -99,11 +99,11 @@ import javax.ws.rs.core.Response; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -181,8 +181,8 @@ public class IncrementalPublishingKafkaIndexTaskRunner implements KafkaIndexTask private final RowIngestionMeters rowIngestionMeters; private final Set publishingSequences = Sets.newConcurrentHashSet(); - private final List> publishWaitList = new LinkedList<>(); - private final List> handOffWaitList = new LinkedList<>(); + private final List> publishWaitList = new ArrayList<>(); + private final List> handOffWaitList = new ArrayList<>(); private volatile DateTime startTime; private volatile Status status = Status.NOT_STARTED; // this is only ever set by the task runner thread (runThread) diff --git a/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java b/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java index 2b18e881031..aea0e4265e3 100644 --- a/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java +++ b/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java @@ -23,7 +23,6 @@ import com.google.caliper.Param; import com.google.caliper.Runner; import com.google.caliper.SimpleBenchmark; import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; import sun.misc.Unsafe; @@ -31,6 +30,7 @@ import sun.misc.Unsafe; import java.lang.reflect.Field; import java.nio.Buffer; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -41,7 +41,7 @@ public class HyperLogLogCollectorBenchmark extends SimpleBenchmark { private final HashFunction fn = Hashing.murmur3_128(); - private final List collectors = Lists.newLinkedList(); + private final List collectors = new ArrayList<>(); @Param({"true"}) boolean targetIsDirect; @Param({"default", "random", "0"}) String alignment; diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/AppenderatorDriverRealtimeIndexTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/AppenderatorDriverRealtimeIndexTaskTest.java index da6cd0b4293..9e45b81e899 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/AppenderatorDriverRealtimeIndexTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/AppenderatorDriverRealtimeIndexTaskTest.java @@ -29,6 +29,7 @@ import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import org.apache.commons.io.FileUtils; import org.apache.druid.client.cache.CacheConfig; import org.apache.druid.client.cache.CachePopulatorStats; import org.apache.druid.client.cache.MapCache; @@ -49,12 +50,12 @@ import org.apache.druid.discovery.DruidNodeAnnouncer; import org.apache.druid.discovery.LookupNodeService; import org.apache.druid.indexer.IngestionState; import org.apache.druid.indexer.TaskState; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.Counters; import org.apache.druid.indexing.common.IngestionStatsAndErrorsTaskReportData; import org.apache.druid.indexing.common.SegmentLoaderFactory; import org.apache.druid.indexing.common.TaskReport; import org.apache.druid.indexing.common.TaskReportFileWriter; -import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.TaskToolbox; import org.apache.druid.indexing.common.TaskToolboxFactory; import org.apache.druid.indexing.common.TestUtils; @@ -133,7 +134,6 @@ import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; import org.apache.druid.timeline.partition.NumberedShardSpec; import org.apache.druid.utils.Runnables; -import org.apache.commons.io.FileUtils; import org.easymock.EasyMock; import org.joda.time.DateTime; import org.joda.time.Period; @@ -149,10 +149,11 @@ import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.ArrayDeque; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; +import java.util.Deque; import java.util.List; import java.util.Map; import java.util.Optional; @@ -178,7 +179,7 @@ public class AppenderatorDriverRealtimeIndexTaskTest private static class TestFirehose implements Firehose { private final InputRowParser> parser; - private final List> queue = new LinkedList<>(); + private final Deque>> queue = new ArrayDeque<>(); private boolean closed = false; public TestFirehose(final InputRowParser> parser) @@ -189,7 +190,7 @@ public class AppenderatorDriverRealtimeIndexTaskTest public void addRows(List> rows) { synchronized (this) { - queue.addAll(rows); + rows.stream().map(Optional::ofNullable).forEach(queue::add); notifyAll(); } } @@ -215,7 +216,7 @@ public class AppenderatorDriverRealtimeIndexTaskTest public InputRow nextRow() { synchronized (this) { - final InputRow row = parser.parseBatch(queue.remove(0)).get(0); + final InputRow row = parser.parseBatch(queue.removeFirst().orElse(null)).get(0); if (row != null && row.getRaw(FAIL_DIM) != null) { throw new ParseException(FAIL_DIM); } diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RealtimeIndexTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RealtimeIndexTaskTest.java index 88a5a43ac63..a4283e12ab1 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RealtimeIndexTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RealtimeIndexTaskTest.java @@ -46,9 +46,9 @@ import org.apache.druid.discovery.DataNodeService; import org.apache.druid.discovery.DruidNodeAnnouncer; import org.apache.druid.discovery.LookupNodeService; import org.apache.druid.indexer.TaskState; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.Counters; import org.apache.druid.indexing.common.SegmentLoaderFactory; -import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.TaskToolbox; import org.apache.druid.indexing.common.TaskToolboxFactory; import org.apache.druid.indexing.common.TestUtils; @@ -138,10 +138,12 @@ import org.junit.rules.TemporaryFolder; import javax.annotation.Nullable; import java.io.File; import java.nio.file.Files; +import java.util.ArrayDeque; import java.util.Arrays; -import java.util.LinkedList; +import java.util.Deque; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; @@ -161,7 +163,7 @@ public class RealtimeIndexTaskTest private static class TestFirehose implements Firehose { private final InputRowParser> parser; - private final List> queue = new LinkedList<>(); + private final Deque>> queue = new ArrayDeque<>(); private boolean closed = false; public TestFirehose(final InputRowParser> parser) @@ -172,7 +174,7 @@ public class RealtimeIndexTaskTest public void addRows(List> rows) { synchronized (this) { - queue.addAll(rows); + rows.stream().map(Optional::ofNullable).forEach(queue::add); notifyAll(); } } @@ -198,7 +200,7 @@ public class RealtimeIndexTaskTest public InputRow nextRow() { synchronized (this) { - final InputRow row = parser.parseBatch(queue.remove(0)).get(0); + final InputRow row = parser.parseBatch(queue.removeFirst().orElse(null)).get(0); if (row != null && row.getRaw(FAIL_DIM) != null) { throw new ParseException(FAIL_DIM); } diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/firehose/IngestSegmentFirehoseFactoryTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/firehose/IngestSegmentFirehoseFactoryTest.java index bbfb25ffb51..a0b8c7e04be 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/firehose/IngestSegmentFirehoseFactoryTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/firehose/IngestSegmentFirehoseFactoryTest.java @@ -110,7 +110,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -324,7 +323,7 @@ public class IngestSegmentFirehoseFactoryTest null, new NoopTestTaskFileWriter() ); - Collection values = new LinkedList<>(); + Collection values = new ArrayList<>(); for (InputRowParser parser : Arrays.asList( ROW_PARSER, new MapInputRowParser( diff --git a/java-util/src/main/java/org/apache/druid/java/util/http/client/io/AppendableByteArrayInputStream.java b/java-util/src/main/java/org/apache/druid/java/util/http/client/io/AppendableByteArrayInputStream.java index 10fb06b97ff..6789faf56a7 100644 --- a/java-util/src/main/java/org/apache/druid/java/util/http/client/io/AppendableByteArrayInputStream.java +++ b/java-util/src/main/java/org/apache/druid/java/util/http/client/io/AppendableByteArrayInputStream.java @@ -23,7 +23,8 @@ import org.apache.druid.java.util.common.logger.Logger; import java.io.IOException; import java.io.InputStream; -import java.util.LinkedList; +import java.util.ArrayDeque; +import java.util.Deque; /** */ @@ -31,7 +32,7 @@ public class AppendableByteArrayInputStream extends InputStream { private static final Logger log = new Logger(AppendableByteArrayInputStream.class); - private final LinkedList bytes = new LinkedList(); + private final Deque bytes = new ArrayDeque<>(); private final SingleByteReaderDoer singleByteReaderDoer = new SingleByteReaderDoer(); private volatile boolean done = false; diff --git a/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorUtil.java b/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorUtil.java index 6265407a3d1..53a1b448f28 100644 --- a/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorUtil.java +++ b/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorUtil.java @@ -37,8 +37,9 @@ import org.apache.druid.segment.FloatColumnSelector; import org.apache.druid.segment.LongColumnSelector; import org.apache.druid.segment.virtual.ExpressionSelectors; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -113,18 +114,20 @@ public class AggregatorUtil */ public static List pruneDependentPostAgg(List postAggregatorList, String postAggName) { - LinkedList rv = Lists.newLinkedList(); + ArrayList rv = new ArrayList<>(); Set deps = new HashSet<>(); deps.add(postAggName); - // Iterate backwards to find the last calculated aggregate and add dependent aggregator as we find dependencies in reverse order + // Iterate backwards to find the last calculated aggregate and add dependent aggregator as we find dependencies + // in reverse order for (PostAggregator agg : Lists.reverse(postAggregatorList)) { if (deps.contains(agg.getName())) { - rv.addFirst(agg); // add to the beginning of List + rv.add(agg); // add to the beginning of List deps.remove(agg.getName()); deps.addAll(agg.getDependentFields()); } } + Collections.reverse(rv); return rv; } @@ -135,10 +138,7 @@ public class AggregatorUtil ) { - List condensedPostAggs = AggregatorUtil.pruneDependentPostAgg( - postAggList, - metric - ); + List condensedPostAggs = AggregatorUtil.pruneDependentPostAgg(postAggList, metric); // calculate dependent aggregators for these postAgg Set dependencySet = new HashSet<>(); dependencySet.add(metric); @@ -152,7 +152,7 @@ public class AggregatorUtil condensedAggs.add(aggregatorSpec); } } - return new Pair(condensedAggs, condensedPostAggs); + return new Pair<>(condensedAggs, condensedPostAggs); } public static BaseFloatColumnValueSelector makeColumnValueSelectorWithFloatDefault( diff --git a/processing/src/main/java/org/apache/druid/query/topn/AggregateTopNMetricFirstAlgorithm.java b/processing/src/main/java/org/apache/druid/query/topn/AggregateTopNMetricFirstAlgorithm.java index 5541678927b..a8b4d2039a9 100644 --- a/processing/src/main/java/org/apache/druid/query/topn/AggregateTopNMetricFirstAlgorithm.java +++ b/processing/src/main/java/org/apache/druid/query/topn/AggregateTopNMetricFirstAlgorithm.java @@ -75,11 +75,8 @@ public class AggregateTopNMetricFirstAlgorithm implements TopNAlgorithm, List> condensedAggPostAggPair = AggregatorUtil.condensedAggregators( - query.getAggregatorSpecs(), - query.getPostAggregatorSpecs(), - metric - ); + Pair, List> condensedAggPostAggPair = + AggregatorUtil.condensedAggregators(query.getAggregatorSpecs(), query.getPostAggregatorSpecs(), metric); if (condensedAggPostAggPair.lhs.isEmpty() && condensedAggPostAggPair.rhs.isEmpty()) { throw new ISE("WTF! Can't find the metric to do topN over?"); diff --git a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryBuilder.java b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryBuilder.java index f1d187e1197..5fd3b00ab0a 100644 --- a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryBuilder.java +++ b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryBuilder.java @@ -37,7 +37,9 @@ import org.apache.druid.segment.VirtualColumn; import org.apache.druid.segment.VirtualColumns; import org.joda.time.Interval; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -247,13 +249,13 @@ public class TopNQueryBuilder @SuppressWarnings("unchecked") public TopNQueryBuilder aggregators(List a) { - aggregatorSpecs = (List) a; + aggregatorSpecs = new ArrayList<>(a); // defensive copy return this; } - public TopNQueryBuilder postAggregators(List p) + public TopNQueryBuilder postAggregators(Collection p) { - postAggregatorSpecs = p; + postAggregatorSpecs = new ArrayList<>(p); // defensive copy return this; } diff --git a/processing/src/test/java/org/apache/druid/query/aggregation/AggregatorUtilTest.java b/processing/src/test/java/org/apache/druid/query/aggregation/AggregatorUtilTest.java index 83f81d35702..92dc8f74e0b 100644 --- a/processing/src/test/java/org/apache/druid/query/aggregation/AggregatorUtilTest.java +++ b/processing/src/test/java/org/apache/druid/query/aggregation/AggregatorUtilTest.java @@ -172,11 +172,12 @@ public class AggregatorUtilTest ); Assert.assertEquals( - new Pair(Lists.newArrayList(agg1, agg2), Collections.singletonList(postAgg2)), AggregatorUtil.condensedAggregators( - Lists.newArrayList(agg1, agg2), - Lists.newArrayList(postAgg1, postAgg2), - "postAgg" - ) + new Pair<>(Lists.newArrayList(agg1, agg2), Collections.singletonList(postAgg2)), + AggregatorUtil.condensedAggregators( + Lists.newArrayList(agg1, agg2), + Lists.newArrayList(postAgg1, postAgg2), + "postAgg" + ) ); } diff --git a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerTest.java b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerTest.java index cc532982b65..5fb8457780f 100644 --- a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerTest.java +++ b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerTest.java @@ -54,6 +54,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -754,11 +755,11 @@ public class ScanQueryRunnerTest @Override public ScanResultValue apply(ScanResultValue input) { - List mapEvents = Lists.newLinkedList(); - List events = ((List) input.getEvents()); + List> mapEvents = new ArrayList<>(); + List events = ((List) input.getEvents()); for (Object event : events) { - Iterator compactedEventIter = ((List) event).iterator(); - Map mapEvent = new LinkedHashMap(); + Iterator compactedEventIter = ((List) event).iterator(); + Map mapEvent = new LinkedHashMap<>(); for (String column : input.getColumns()) { mapEvent.put(column, compactedEventIter.next()); } diff --git a/processing/src/test/java/org/apache/druid/query/search/SearchQueryRunnerTest.java b/processing/src/test/java/org/apache/druid/query/search/SearchQueryRunnerTest.java index 1631307af9f..dfc2e8a8525 100644 --- a/processing/src/test/java/org/apache/druid/query/search/SearchQueryRunnerTest.java +++ b/processing/src/test/java/org/apache/druid/query/search/SearchQueryRunnerTest.java @@ -21,7 +21,6 @@ package org.apache.druid.query.search; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; import org.apache.druid.common.config.NullHandling; import org.apache.druid.data.input.MapBasedInputRow; import org.apache.druid.java.util.common.DateTimes; @@ -64,6 +63,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -135,7 +135,7 @@ public class SearchQueryRunnerTest .query("a") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 279)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "travel", 93)); @@ -178,7 +178,7 @@ public class SearchQueryRunnerTest } ); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 91)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 273)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "travel", 91)); @@ -207,7 +207,7 @@ public class SearchQueryRunnerTest .query("e") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementDimension, "preferred", 1209)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "e", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "preferred", 1209)); @@ -232,7 +232,7 @@ public class SearchQueryRunnerTest .query("e") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "e", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementDimension, "preferred", 1209)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "preferred", 1209)); @@ -250,7 +250,7 @@ public class SearchQueryRunnerTest .query(new FragmentSearchQuerySpec(Arrays.asList("auto", "ve"))) .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); checkSearchQuery(searchQuery, expectedHits); @@ -259,7 +259,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithDimensionQuality() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 279)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "travel", 93)); @@ -281,7 +281,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithDimensionProvider() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186)); checkSearchQuery( @@ -299,7 +299,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithDimensionsQualityAndProvider() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 279)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "travel", 93)); @@ -327,7 +327,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithDimensionsPlacementAndProvider() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186)); checkSearchQuery( @@ -352,7 +352,7 @@ public class SearchQueryRunnerTest public void testSearchWithExtractionFilter1() { final String automotiveSnowman = "automotiveā˜ƒ"; - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, automotiveSnowman, 93)); final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn( @@ -391,7 +391,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithSingleFilter1() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 93)); checkSearchQuery( @@ -415,7 +415,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithSingleFilter2() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186)); checkSearchQuery( @@ -434,7 +434,7 @@ public class SearchQueryRunnerTest @Test public void testSearchMultiAndFilter() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); DimFilter filter = new AndDimFilter( @@ -458,7 +458,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithMultiOrFilter() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); DimFilter filter = new OrDimFilter( @@ -482,7 +482,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithEmptyResults() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); checkSearchQuery( Druids.newSearchQueryBuilder() @@ -498,7 +498,7 @@ public class SearchQueryRunnerTest @Test public void testSearchWithFilterEmptyResults() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); DimFilter filter = new AndDimFilter( new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "total_market", null), @@ -521,7 +521,7 @@ public class SearchQueryRunnerTest @Test public void testSearchNonExistingDimension() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); checkSearchQuery( Druids.newSearchQueryBuilder() @@ -538,7 +538,7 @@ public class SearchQueryRunnerTest @Test public void testSearchAll() { - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "spot", 837)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "upfront", 186)); @@ -575,7 +575,7 @@ public class SearchQueryRunnerTest .sortSpec(new SearchSortSpec(StringComparators.NUMERIC)) .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "a", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "entertainment", 93)); @@ -609,7 +609,7 @@ public class SearchQueryRunnerTest )) .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit("__time2", "Friday", 169)); checkSearchQuery(searchQuery, expectedHits); @@ -631,7 +631,7 @@ public class SearchQueryRunnerTest .query("1297123200000") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(Column.TIME_COLUMN_NAME, "1297123200000", 13)); checkSearchQuery(searchQuery, expectedHits); } @@ -655,7 +655,7 @@ public class SearchQueryRunnerTest .query("1297123200000") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(Column.TIME_COLUMN_NAME, "super-1297123200000", 13)); checkSearchQuery(searchQuery, expectedHits); } @@ -676,7 +676,7 @@ public class SearchQueryRunnerTest .query("100.7") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "100.706057", 1)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "100.775597", 1)); checkSearchQuery(searchQuery, expectedHits); @@ -701,7 +701,7 @@ public class SearchQueryRunnerTest .query("100.7") .build(); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "super-100.706057", 1)); expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "super-100.775597", 1)); checkSearchQuery(searchQuery, expectedHits); @@ -751,7 +751,7 @@ public class SearchQueryRunnerTest QueryRunnerTestHelper.NOOP_QUERYWATCHER ); QueryRunner runner = factory.createRunner(new QueryableIndexSegment("asdf", TestIndex.persistRealtimeAndLoadMMapped(index))); - List expectedHits = Lists.newLinkedList(); + List expectedHits = new ArrayList<>(); expectedHits.add(new SearchHit("table", "table", 1)); expectedHits.add(new SearchHit("table", NullHandling.defaultStringValue(), 1)); checkSearchQuery(searchQuery, runner, expectedHits); @@ -769,7 +769,7 @@ public class SearchQueryRunnerTest .intervals(QueryRunnerTestHelper.fullOnInterval) .build(); - List noHit = Lists.newLinkedList(); + List noHit = new ArrayList<>(); checkSearchQuery(searchQuery, noHit); } @@ -782,7 +782,7 @@ public class SearchQueryRunnerTest private void checkSearchQuery(Query searchQuery, QueryRunner runner, List expectedResults) { Iterable> results = runner.run(QueryPlus.wrap(searchQuery), ImmutableMap.of()).toList(); - List copy = Lists.newLinkedList(expectedResults); + List copy = new ArrayList<>(expectedResults); for (Result result : results) { Assert.assertEquals(DateTimes.of("2011-01-12T00:00:00.000Z"), result.getTimestamp()); Assert.assertTrue(result.getValue() instanceof Iterable); diff --git a/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java b/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java index 50c0c108932..1c5d866a2ad 100644 --- a/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java +++ b/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java @@ -36,9 +36,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; @@ -196,7 +196,7 @@ public class BenchmarkIndexibleWrites extends AbstractBenchmark ) ); final AtomicInteger index = new AtomicInteger(0); - List> futures = new LinkedList<>(); + List> futures = new ArrayList<>(); final Integer loops = totalIndexSize / concurrentThreads; @@ -249,7 +249,7 @@ public class BenchmarkIndexibleWrites extends AbstractBenchmark ); final AtomicInteger index = new AtomicInteger(0); final AtomicInteger queryableIndex = new AtomicInteger(0); - List> futures = new LinkedList<>(); + List> futures = new ArrayList<>(); final Integer loops = totalIndexSize / concurrentThreads; diff --git a/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexBenchmark.java b/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexBenchmark.java index fcc2fc06b3c..eb4609cb688 100644 --- a/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexBenchmark.java +++ b/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexBenchmark.java @@ -68,7 +68,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -347,8 +346,8 @@ public class OnheapIncrementalIndexBenchmark extends AbstractBenchmark ); final long timestamp = System.currentTimeMillis(); final Interval queryInterval = Intervals.of("1900-01-01T00:00:00Z/2900-01-01T00:00:00Z"); - final List> indexFutures = new LinkedList<>(); - final List> queryFutures = new LinkedList<>(); + final List> indexFutures = new ArrayList<>(); + final List> queryFutures = new ArrayList<>(); final Segment incrementalIndexSegment = new IncrementalIndexSegment(incrementalIndex, null); final QueryRunnerFactory factory = new TimeseriesQueryRunnerFactory( new TimeseriesQueryQueryToolChest(QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator()), diff --git a/server/src/main/java/org/apache/druid/client/CachingQueryRunner.java b/server/src/main/java/org/apache/druid/client/CachingQueryRunner.java index 8f9a88a9502..3a09c5c36e4 100644 --- a/server/src/main/java/org/apache/druid/client/CachingQueryRunner.java +++ b/server/src/main/java/org/apache/druid/client/CachingQueryRunner.java @@ -38,10 +38,10 @@ import org.apache.druid.query.QueryToolChest; import org.apache.druid.query.SegmentDescriptor; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import java.util.LinkedList; import java.util.Map; public class CachingQueryRunner implements QueryRunner @@ -134,7 +134,7 @@ public class CachingQueryRunner implements QueryRunner } } - final Collection> cacheFutures = Collections.synchronizedList(new LinkedList<>()); + final Collection> cacheFutures = Collections.synchronizedList(new ArrayList<>()); if (populateCache) { final Function cacheFn = strategy.prepareForSegmentLevelCache(); return cachePopulator.wrap(base.run(queryPlus, responseContext), value -> cacheFn.apply(value), cache, key); diff --git a/server/src/main/java/org/apache/druid/client/cache/BackgroundCachePopulator.java b/server/src/main/java/org/apache/druid/client/cache/BackgroundCachePopulator.java index 9d61469e1a7..fa1a9ea5a0a 100644 --- a/server/src/main/java/org/apache/druid/client/cache/BackgroundCachePopulator.java +++ b/server/src/main/java/org/apache/druid/client/cache/BackgroundCachePopulator.java @@ -32,7 +32,7 @@ import org.apache.druid.java.util.common.guava.Sequences; import org.apache.druid.java.util.common.logger.Logger; import java.io.ByteArrayOutputStream; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.function.Function; @@ -67,7 +67,7 @@ public class BackgroundCachePopulator implements CachePopulator final Cache.NamedKey cacheKey ) { - final List> cacheFutures = new LinkedList<>(); + final List> cacheFutures = new ArrayList<>(); final Sequence wrappedSequence = Sequences.map( sequence, diff --git a/server/src/main/java/org/apache/druid/client/cache/MapCache.java b/server/src/main/java/org/apache/druid/client/cache/MapCache.java index 13a1e87356b..e05c35a515c 100644 --- a/server/src/main/java/org/apache/druid/client/cache/MapCache.java +++ b/server/src/main/java/org/apache/druid/client/cache/MapCache.java @@ -19,12 +19,12 @@ package org.apache.druid.client.cache; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.primitives.Ints; import org.apache.druid.java.util.emitter.service.ServiceEmitter; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -127,7 +127,7 @@ public class MapCache implements Cache } synchronized (clearLock) { Iterator iter = baseMap.keySet().iterator(); - List toRemove = Lists.newLinkedList(); + List toRemove = new ArrayList<>(); while (iter.hasNext()) { ByteBuffer next = iter.next(); diff --git a/server/src/main/java/org/apache/druid/metadata/SQLMetadataStorageActionHandler.java b/server/src/main/java/org/apache/druid/metadata/SQLMetadataStorageActionHandler.java index 8fad097ab60..ebee2c192ff 100644 --- a/server/src/main/java/org/apache/druid/metadata/SQLMetadataStorageActionHandler.java +++ b/server/src/main/java/org/apache/druid/metadata/SQLMetadataStorageActionHandler.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.druid.indexer.TaskInfo; import org.apache.druid.java.util.common.DateTimes; @@ -47,6 +46,7 @@ import javax.annotation.Nullable; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -488,29 +488,18 @@ public abstract class SQLMetadataStorageActionHandler, byte[]>() - { - @Override - public List fold( - List list, byte[] bytes, FoldController control, StatementContext ctx - ) throws SQLException - { - try { - list.add( - jsonMapper.readValue( - bytes, logType - ) - ); - return list; - } - catch (IOException e) { - log.makeAlert(e, "Failed to deserialize log") - .addData("entryId", entryId) - .addData("payload", StringUtils.fromUtf8(bytes)) - .emit(); - throw new SQLException(e); - } + new ArrayList<>(), + (List list, byte[] bytes, FoldController control, StatementContext ctx) -> { + try { + list.add(jsonMapper.readValue(bytes, logType)); + return list; + } + catch (IOException e) { + log.makeAlert(e, "Failed to deserialize log") + .addData("entryId", entryId) + .addData("payload", StringUtils.fromUtf8(bytes)) + .emit(); + throw new SQLException(e); } } ); diff --git a/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java b/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java index 010c2d4ce2c..9388bbc24f9 100644 --- a/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java +++ b/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java @@ -624,7 +624,7 @@ public class SegmentLoadDropHandler implements DataSegmentChangeHandler synchronized (lock) { try { if (!(finished && queue.isEmpty())) { - final List segments = Lists.newLinkedList(); + final List segments = new ArrayList<>(); queue.drainTo(segments); try { announcer.announceSegments(segments); @@ -656,7 +656,7 @@ public class SegmentLoadDropHandler implements DataSegmentChangeHandler finished = true; // announce any remaining segments try { - final List segments = Lists.newLinkedList(); + final List segments = new ArrayList<>(); queue.drainTo(segments); announcer.announceSegments(segments); } diff --git a/server/src/test/java/org/apache/druid/client/cache/ByteCountingLRUMapTest.java b/server/src/test/java/org/apache/druid/client/cache/ByteCountingLRUMapTest.java index c15c47885a0..de8285e70b5 100644 --- a/server/src/test/java/org/apache/druid/client/cache/ByteCountingLRUMapTest.java +++ b/server/src/test/java/org/apache/druid/client/cache/ByteCountingLRUMapTest.java @@ -19,12 +19,12 @@ package org.apache.druid.client.cache; -import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -70,7 +70,7 @@ public class ByteCountingLRUMapTest Assert.assertEquals(oneByte, ByteBuffer.wrap(map.get(twoByte))); Iterator it = map.keySet().iterator(); - List toRemove = Lists.newLinkedList(); + List toRemove = new ArrayList<>(); while (it.hasNext()) { ByteBuffer buf = it.next(); if (buf.remaining() == 10) { diff --git a/server/src/test/java/org/apache/druid/metadata/SQLMetadataConnectorTest.java b/server/src/test/java/org/apache/druid/metadata/SQLMetadataConnectorTest.java index 0baaf70d2c7..f5ed368566e 100644 --- a/server/src/test/java/org/apache/druid/metadata/SQLMetadataConnectorTest.java +++ b/server/src/test/java/org/apache/druid/metadata/SQLMetadataConnectorTest.java @@ -26,7 +26,8 @@ import org.junit.Test; import org.skife.jdbi.v2.Handle; import org.skife.jdbi.v2.tweak.HandleCallback; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.List; public class SQLMetadataConnectorTest @@ -47,7 +48,7 @@ public class SQLMetadataConnectorTest @Test public void testCreateTables() { - final LinkedList tables = new LinkedList(); + final List tables = new ArrayList<>(); final String entryType = tablesConfig.getTaskEntryType(); tables.add(tablesConfig.getConfigTable()); tables.add(tablesConfig.getSegmentsTable()); diff --git a/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java b/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java index cc4f4ca69d1..4799f3f2c1a 100644 --- a/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java +++ b/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.druid.java.util.common.Intervals; @@ -274,7 +273,7 @@ public class SegmentLoadDropHandlerTest @Test public void testLoadCache() throws Exception { - List segments = Lists.newLinkedList(); + List segments = new ArrayList<>(); for (int i = 0; i < COUNT; ++i) { segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-01"))); segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-02"))); @@ -406,7 +405,7 @@ public class SegmentLoadDropHandlerTest announcer, EasyMock.createNiceMock(DataSegmentServerAnnouncer.class), segmentManager ); - List segments = Lists.newLinkedList(); + List segments = new ArrayList<>(); for (int i = 0; i < COUNT; ++i) { segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-01"))); segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-02")));