From 08f3a64dee8737020d0e65fea6f09799a018f92a Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 3 Nov 2017 10:59:04 +0000 Subject: [PATCH] LUCENE-8017: Use List rather than array --- .../java/org/apache/lucene/search/BooleanWeight.java | 2 +- .../org/apache/lucene/search/DisjunctionMaxQuery.java | 2 +- .../src/java/org/apache/lucene/search/Weight.java | 11 ++++++----- .../lucene/search/spans/SpanContainingQuery.java | 3 ++- .../org/apache/lucene/search/spans/SpanNearQuery.java | 3 +-- .../org/apache/lucene/search/spans/SpanNotQuery.java | 3 ++- .../org/apache/lucene/search/spans/SpanOrQuery.java | 3 +-- .../apache/lucene/search/spans/SpanWithinQuery.java | 3 ++- .../org/apache/lucene/facet/DrillSidewaysQuery.java | 8 +++++--- .../java/org/apache/lucene/queries/BoostingQuery.java | 3 ++- .../org/apache/lucene/queries/CustomScoreQuery.java | 8 +++++--- 11 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java index 047a1b1eed4..cb1c1947b2a 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java @@ -302,7 +302,7 @@ final class BooleanWeight extends Weight { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, weights.toArray(new Weight[0])); + return getCacheHelper(context, weights); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java index c40c25d7a49..38f74ad5615 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java @@ -139,7 +139,7 @@ public final class DisjunctionMaxQuery extends Query implements Iterable @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, weights.toArray(new Weight[0])); + return getCacheHelper(context, weights); } /** Explain the score we computed for doc */ diff --git a/lucene/core/src/java/org/apache/lucene/search/Weight.java b/lucene/core/src/java/org/apache/lucene/search/Weight.java index 0d3ce03d4ff..e87dd3f2ecd 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Weight.java +++ b/lucene/core/src/java/org/apache/lucene/search/Weight.java @@ -18,6 +18,7 @@ package org.apache.lucene.search; import java.io.IOException; +import java.util.List; import java.util.Set; import org.apache.lucene.index.FieldInfo; @@ -123,14 +124,14 @@ public abstract class Weight { * @param weights an array of {@link Weight} to be cached * @return an {@link org.apache.lucene.index.IndexReader.CacheHelper} indicating the cache level */ - protected static IndexReader.CacheHelper getCacheHelper(LeafReaderContext context, Weight... weights) { - if (weights.length == 0) + protected static IndexReader.CacheHelper getCacheHelper(LeafReaderContext context, List weights) { + if (weights.size() == 0) return null; - IndexReader.CacheHelper helper = weights[0].getCacheHelper(context); + IndexReader.CacheHelper helper = weights.get(0).getCacheHelper(context); if (helper == null) return null; - for (int i = 1; i < weights.length; i++) { - IndexReader.CacheHelper nextHelper = weights[i].getCacheHelper(context); + for (int i = 1; i < weights.size(); i++) { + IndexReader.CacheHelper nextHelper = weights.get(i).getCacheHelper(context); if (nextHelper == null || nextHelper != helper) return null; } diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java index 736d3321958..0af481f1cdf 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java @@ -19,6 +19,7 @@ package org.apache.lucene.search.spans; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Map; import org.apache.lucene.index.IndexReader; @@ -119,7 +120,7 @@ public final class SpanContainingQuery extends SpanContainQuery { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, bigWeight, littleWeight); + return getCacheHelper(context, Arrays.asList(bigWeight, littleWeight)); } } } \ No newline at end of file diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java index cb3207d9ae1..a7c42d681c8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java @@ -33,7 +33,6 @@ import org.apache.lucene.index.TermContext; import org.apache.lucene.index.Terms; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; -import org.apache.lucene.search.Weight; /** Matches spans which are near one another. One can specify slop, the * maximum number of intervening unmatched positions, as well as whether @@ -233,7 +232,7 @@ public class SpanNearQuery extends SpanQuery implements Cloneable { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, subWeights.toArray(new Weight[0])); + return getCacheHelper(context, subWeights); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java index a87baf51514..154ddfe2582 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java @@ -18,6 +18,7 @@ package org.apache.lucene.search.spans; import java.io.IOException; +import java.util.Arrays; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -194,7 +195,7 @@ public final class SpanNotQuery extends SpanQuery { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, includeWeight, excludeWeight); + return getCacheHelper(context, Arrays.asList(includeWeight, excludeWeight)); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java index fdde9d19aff..653fc70f5fa 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java @@ -34,7 +34,6 @@ import org.apache.lucene.search.DisjunctionDISIApproximation; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; /** Matches the union of its clauses. @@ -141,7 +140,7 @@ public final class SpanOrQuery extends SpanQuery { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, subWeights.toArray(new Weight[0])); + return getCacheHelper(context, subWeights); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java index 23a04994aec..d29b4dd2c6f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java @@ -19,6 +19,7 @@ package org.apache.lucene.search.spans; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Map; import org.apache.lucene.index.IndexReader; @@ -120,7 +121,7 @@ public final class SpanWithinQuery extends SpanContainQuery { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, littleWeight, bigWeight); + return getCacheHelper(context, Arrays.asList(littleWeight, bigWeight)); } } diff --git a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java index ef733162ced..822eeb4210e 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java @@ -17,8 +17,10 @@ package org.apache.lucene.facet; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.List; import java.util.Objects; import java.util.Set; @@ -103,9 +105,9 @@ class DrillSidewaysQuery extends Query { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - Weight[] weights = new Weight[drillDowns.length + 1]; - weights[0] = baseWeight; - System.arraycopy(drillDowns, 0, weights, 1, drillDowns.length); + List weights = new ArrayList<>(); + weights.add(baseWeight); + weights.addAll(Arrays.asList(drillDowns)); return getCacheHelper(context, weights); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java index 17f84070d64..1864882f26a 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java @@ -17,6 +17,7 @@ package org.apache.lucene.queries; import java.io.IOException; +import java.util.Arrays; import java.util.Objects; import java.util.Set; @@ -124,7 +125,7 @@ public class BoostingQuery extends Query { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - return getCacheHelper(context, matchWeight, contextWeight); + return getCacheHelper(context, Arrays.asList(matchWeight, contextWeight)); } }; } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java index da707252350..1fb0d97fac0 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java @@ -17,9 +17,11 @@ package org.apache.lucene.queries; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Set; import org.apache.lucene.index.IndexReader; @@ -209,9 +211,9 @@ public class CustomScoreQuery extends Query implements Cloneable { @Override public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { - Weight[] weights = new Weight[valSrcWeights.length + 1]; - weights[0] = subQueryWeight; - System.arraycopy(valSrcWeights, 0, weights, 1, valSrcWeights.length); + List weights = new ArrayList<>(); + weights.add(subQueryWeight); + weights.addAll(Arrays.asList(valSrcWeights)); return getCacheHelper(context, weights); }