From 3bd885f1e7bd0460d2537c412f312df08f3a7717 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 15 Apr 2013 12:01:16 +0000 Subject: [PATCH] Make use of diamond operator in join module. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1467952 13f79535-47bb-0310-9956-ffa450edef68 --- .../join/ToParentBlockJoinCollector.java | 12 +++--- .../lucene/search/join/TestBlockJoin.java | 18 ++++---- .../lucene/search/join/TestJoinUtil.java | 43 +++++++++++-------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java index a1b8c008477..a27be0cd9c4 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java @@ -80,7 +80,7 @@ public class ToParentBlockJoinCollector extends Collector { // Maps each BlockJoinQuery instance to its "slot" in // joinScorers and in OneGroup's cached doc/scores/count: - private final Map joinQueryID = new HashMap(); + private final Map joinQueryID = new HashMap<>(); private final int numParentHits; private final FieldValueHitQueue queue; private final FieldComparator[] comparators; @@ -138,7 +138,7 @@ public class ToParentBlockJoinCollector extends Collector { int[][] docs; float[][] scores; int[] counts; - }; + } @Override public void collect(int parentDoc) throws IOException { @@ -470,7 +470,7 @@ public class ToParentBlockJoinCollector extends Collector { final TopDocs topDocs = collector.topDocs(withinGroupOffset, numDocsInGroup); - groups[groupIDX-offset] = new GroupDocs(og.score, + groups[groupIDX-offset] = new GroupDocs<>(og.score, topDocs.getMaxScore(), numChildDocs, topDocs.scoreDocs, @@ -478,9 +478,9 @@ public class ToParentBlockJoinCollector extends Collector { groupSortValues); } - return new TopGroups(new TopGroups(sort.getSort(), - withinGroupSort == null ? null : withinGroupSort.getSort(), - 0, totalGroupedHitCount, groups, maxScore), + return new TopGroups<>(new TopGroups<>(sort.getSort(), + withinGroupSort == null ? null : withinGroupSort.getSort(), + 0, totalGroupedHitCount, groups, maxScore), totalHitCount); } diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java index cd3fe5a2de7..ab9fb420d90 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java @@ -162,13 +162,13 @@ public class TestBlockJoin extends LuceneTestCase { final Directory dir = newDirectory(); final RandomIndexWriter w = new RandomIndexWriter(random(), dir); - final List docs = new ArrayList(); + final List docs = new ArrayList<>(); docs.add(makeJob("java", 2007)); docs.add(makeJob("python", 2010)); Collections.shuffle(docs, random()); docs.add(makeResume("Lisa", "United Kingdom")); - final List docs2 = new ArrayList(); + final List docs2 = new ArrayList<>(); docs2.add(makeJob("ruby", 2005)); docs2.add(makeJob("java", 2006)); Collections.shuffle(docs2, random()); @@ -283,7 +283,7 @@ public class TestBlockJoin extends LuceneTestCase { // Cannot assert this since we use NoMergePolicy: w.setDoRandomForceMergeAssert(false); - List docs = new ArrayList(); + List docs = new ArrayList<>(); docs.add(makeJob("java", 2007)); docs.add(makeJob("python", 2010)); docs.add(makeResume("Lisa", "United Kingdom")); @@ -358,7 +358,7 @@ public class TestBlockJoin extends LuceneTestCase { } private Sort getRandomSort(String prefix, int numFields) { - final List sortFields = new ArrayList(); + final List sortFields = new ArrayList<>(); // TODO: sometimes sort by score; problem is scores are // not comparable across the two indices // sortFields.add(SortField.FIELD_SCORE); @@ -390,7 +390,7 @@ public class TestBlockJoin extends LuceneTestCase { final String[][] childFields = getRandomFields(numParentDocs); final boolean doDeletes = random().nextBoolean(); - final List toDelete = new ArrayList(); + final List toDelete = new ArrayList<>(); // TODO: parallel star join, nested join cases too! final RandomIndexWriter w = new RandomIndexWriter(random(), dir); @@ -415,7 +415,7 @@ public class TestBlockJoin extends LuceneTestCase { parentJoinDoc.add(newStringField("blockID", ""+parentDocID, Field.Store.NO)); } - final List joinDocs = new ArrayList(); + final List joinDocs = new ArrayList<>(); if (VERBOSE) { StringBuilder sb = new StringBuilder(); @@ -608,7 +608,7 @@ public class TestBlockJoin extends LuceneTestCase { } // Merge both sorts: - final List sortFields = new ArrayList(Arrays.asList(parentSort.getSort())); + final List sortFields = new ArrayList<>(Arrays.asList(parentSort.getSort())); sortFields.addAll(Arrays.asList(childSort.getSort())); final Sort parentAndChildSort = new Sort(sortFields.toArray(new SortField[sortFields.size()])); @@ -915,7 +915,7 @@ public class TestBlockJoin extends LuceneTestCase { final Directory dir = newDirectory(); final RandomIndexWriter w = new RandomIndexWriter(random(), dir); - final List docs = new ArrayList(); + final List docs = new ArrayList<>(); docs.add(makeJob("java", 2007)); docs.add(makeJob("python", 2010)); @@ -1060,7 +1060,7 @@ public class TestBlockJoin extends LuceneTestCase { final Directory dir = newDirectory(); final RandomIndexWriter w = new RandomIndexWriter(random(), dir); - final List docs = new ArrayList(); + final List docs = new ArrayList<>(); docs.add(makeJob("ruby", 2005)); docs.add(makeJob("java", 2006)); docs.add(makeJob("java", 2010)); diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java index 8083cdecd42..dbbf7ba2d7f 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java @@ -17,9 +17,6 @@ package org.apache.lucene.search.join; * limitations under the License. */ -import java.io.IOException; -import java.util.*; - import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; @@ -28,12 +25,10 @@ import org.apache.lucene.document.TextField; import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.BinaryDocValues; -import org.apache.lucene.index.DocTermOrds; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.index.SlowCompositeReaderWrapper; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.Term; @@ -54,11 +49,23 @@ import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; -import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; import org.junit.Test; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + public class TestJoinUtil extends LuceneTestCase { public void testSimple() throws Exception { @@ -374,7 +381,7 @@ public class TestJoinUtil extends LuceneTestCase { IndexIterationContext context = new IndexIterationContext(); int numRandomValues = nDocs / 2; context.randomUniqueValues = new String[numRandomValues]; - Set trackSet = new HashSet(); + Set trackSet = new HashSet<>(); context.randomFrom = new boolean[numRandomValues]; for (int i = 0; i < numRandomValues; i++) { String uniqueRandomValue; @@ -462,7 +469,7 @@ public class TestJoinUtil extends LuceneTestCase { toField = "from"; queryVals = context.toHitsToJoinScore; } - final Map joinValueToJoinScores = new HashMap(); + final Map joinValueToJoinScores = new HashMap<>(); if (multipleValuesPerDocument) { fromSearcher.search(new TermQuery(new Term("value", uniqueRandomValue)), new Collector() { @@ -538,7 +545,7 @@ public class TestJoinUtil extends LuceneTestCase { }); } - final Map docToJoinScore = new HashMap(); + final Map docToJoinScore = new HashMap<>(); if (multipleValuesPerDocument) { if (scoreDocsInOrder) { AtomicReader slowCompositeReader = SlowCompositeReaderWrapper.wrap(toSearcher.getIndexReader()); @@ -546,7 +553,7 @@ public class TestJoinUtil extends LuceneTestCase { if (terms != null) { DocsEnum docsEnum = null; TermsEnum termsEnum = null; - SortedSet joinValues = new TreeSet(BytesRef.getUTF8SortedAsUnicodeComparator()); + SortedSet joinValues = new TreeSet<>(BytesRef.getUTF8SortedAsUnicodeComparator()); joinValues.addAll(joinValueToJoinScores.keySet()); for (BytesRef joinValue : joinValues) { termsEnum = terms.iterator(termsEnum); @@ -651,7 +658,7 @@ public class TestJoinUtil extends LuceneTestCase { } else { hitsToJoinScores = context.toHitsToJoinScore.get(queryValue); } - List> hits = new ArrayList>(hitsToJoinScores.entrySet()); + List> hits = new ArrayList<>(hitsToJoinScores.entrySet()); Collections.sort(hits, new Comparator>() { @Override @@ -714,13 +721,13 @@ public class TestJoinUtil extends LuceneTestCase { String[] randomUniqueValues; boolean[] randomFrom; - Map> fromDocuments = new HashMap>(); - Map> toDocuments = new HashMap>(); - Map> randomValueFromDocs = new HashMap>(); - Map> randomValueToDocs = new HashMap>(); + Map> fromDocuments = new HashMap<>(); + Map> toDocuments = new HashMap<>(); + Map> randomValueFromDocs = new HashMap<>(); + Map> randomValueToDocs = new HashMap<>(); - Map> fromHitsToJoinScore = new HashMap>(); - Map> toHitsToJoinScore = new HashMap>(); + Map> fromHitsToJoinScore = new HashMap<>(); + Map> toHitsToJoinScore = new HashMap<>(); } @@ -734,7 +741,7 @@ public class TestJoinUtil extends LuceneTestCase { private RandomDoc(String id, int numberOfLinkValues, String value, boolean from) { this.id = id; this.from = from; - linkValues = new ArrayList(numberOfLinkValues); + linkValues = new ArrayList<>(numberOfLinkValues); this.value = value; } }