Apache Lucene open-source search software
LUCENE-3764: Remove MapBackedSet, it's already available in Java 6 through Collections.newSetFromMap(Map). BTW: Funny: http://blog.grovehillsoftware.com/2009/12/handy-but-hidden-collectionsnewsetfromm.html
Uwe Schindler70a7d4975f2c
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsProducer.javaindex 1583c7f4df9..8d0ec06125f 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsProducer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsProducer.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.lucene3x;*/import java.io.IOException;+import java.util.Collections;import java.util.HashMap;import java.util.IdentityHashMap;import java.util.Map;@@ -37,7 +38,6 @@ import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.MapBackedSet;import org.apache.lucene.util.StringHelper;/**@@ -60,7 +60,7 @@ class Lucene3xNormsProducer extends PerDocProducer {final Map<String,NormsDocValues> norms = new HashMap<String,NormsDocValues>();// any .nrm or .sNN files we have open at any time.// TODO: just a list, and double-close() separate norms files?- final Set<IndexInput> openFiles = new MapBackedSet<IndexInput>(new IdentityHashMap<IndexInput,Boolean>());+ final Set<IndexInput> openFiles = Collections.newSetFromMap(new IdentityHashMap<IndexInput,Boolean>());// points to a singleNormFileIndexInput singleNormStream;final int maxdoc;diff --git a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.javaindex c30a76b28e4..e5ff1e0c231 100644--- a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java@@ -27,6 +27,7 @@ import java.nio.channels.ClosedChannelException; // javadoc @linkimport java.nio.channels.FileChannel;import java.nio.channels.FileChannel.MapMode;+import java.util.Collections;import java.util.Set;import java.util.WeakHashMap;@@ -35,7 +36,6 @@ import java.security.PrivilegedExceptionAction;import java.security.PrivilegedActionException;import java.lang.reflect.Method;-import org.apache.lucene.util.MapBackedSet;import org.apache.lucene.util.Constants;/** File-based {@link Directory} implementation that uses@@ -261,7 +261,7 @@ public class MMapDirectory extends FSDirectory {private ByteBuffer curBuf; // redundant for speed: buffers[curBufIndex]private boolean isClone = false;- private final Set<MMapIndexInput> clones = new MapBackedSet<MMapIndexInput>(new WeakHashMap<MMapIndexInput,Boolean>());+ private final Set<MMapIndexInput> clones = Collections.newSetFromMap(new WeakHashMap<MMapIndexInput,Boolean>());MMapIndexInput(String resourceDescription, RandomAccessFile raf, long offset, long length, int chunkSizePower) throws IOException {super(resourceDescription);diff --git a/lucene/core/src/java/org/apache/lucene/util/MapBackedSet.java b/lucene/core/src/java/org/apache/lucene/util/MapBackedSet.javadeleted file mode 100644index d6c6567b778..00000000000--- a/lucene/core/src/java/org/apache/lucene/util/MapBackedSet.java+++ /dev/null@@ -1,69 +0,0 @@-package org.apache.lucene.util;--/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import java.util.AbstractSet;-import java.util.Iterator;-import java.util.Map;--/**- * A Set implementation that wraps an actual Map based- * implementation.- *- * @lucene.internal- */-public final class MapBackedSet<E> extends AbstractSet<E> {- private final Map<E, Boolean> map;-- /**- * Creates a new instance which wraps the specified {@code map}.- */- public MapBackedSet(Map<E, Boolean> map) {- this.map = map;- }-- @Override- public int size() {- return map.size();- }-- @Override- public boolean contains(Object o) {- return map.containsKey(o);- }-- @Override- public boolean add(E o) {- return map.put(o, Boolean.TRUE) == null;- }-- @Override- public boolean remove(Object o) {- return map.remove(o) != null;- }-- @Override- public void clear() {- map.clear();- }-- @Override- public Iterator<E> iterator() {- return map.keySet().iterator();- }-}diff --git a/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestIndexClose.java b/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestIndexClose.javaindex 1c5b2f574ad..6af3a781871 100644--- a/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestIndexClose.java+++ b/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestIndexClose.java@@ -1,6 +1,7 @@package org.apache.lucene.facet.taxonomy.directory;import java.io.IOException;+import java.util.Collections;import java.util.HashSet;import java.util.IdentityHashMap;import java.util.Set;@@ -10,13 +11,11 @@ import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.IndexWriterConfig.OpenMode;-import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.LockObtainFailedException;import org.junit.Test;import org.apache.lucene.util.LuceneTestCase;-import org.apache.lucene.util.MapBackedSet;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;import org.apache.lucene.facet.taxonomy.CategoryPath;@@ -95,7 +94,7 @@ public class TestIndexClose extends LuceneTestCase {}private static class LeakChecker {- Set<DirectoryReader> readers = new MapBackedSet<DirectoryReader>(new IdentityHashMap<DirectoryReader,Boolean>());+ Set<DirectoryReader> readers = Collections.newSetFromMap(new IdentityHashMap<DirectoryReader,Boolean>());int iwriter=0;Set<Integer> openWriters = new HashSet<Integer>();