LUCENE-8927: Set.copyOf and Set.of instead of Collections.unmodifiabl… (#796)

This commit is contained in:
Atri Sharma 2019-07-25 23:45:29 +05:30 committed by Adrien Grand
parent 29f941baa2
commit 3e2ca05b8e
5 changed files with 13 additions and 18 deletions

View File

@ -146,19 +146,15 @@ public class DemoHTMLParser implements HTMLParser {
this.body = body.toString();
}
private static final Set<String> createElementNameSet(String... names) {
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(names)));
}
/** HTML elements that cause a line break (they are block-elements) */
static final Set<String> ENDLINE_ELEMENTS = createElementNameSet(
static final Set<String> ENDLINE_ELEMENTS = Set.of(
"p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "ul", "ol", "dl",
"pre", "hr", "blockquote", "address", "fieldset", "table", "form",
"noscript", "li", "dt", "dd", "noframes", "br", "tr", "select", "option"
);
/** HTML elements with contents that are ignored */
static final Set<String> SUPPRESS_ELEMENTS = createElementNameSet(
static final Set<String> SUPPRESS_ELEMENTS = Set.of(
"style", "script"
);
}

View File

@ -428,7 +428,7 @@ public abstract class FSDirectory extends BaseDirectory {
if (pendingDeletes.isEmpty()) {
return Collections.emptySet();
} else {
return Collections.unmodifiableSet(new HashSet<>(pendingDeletes));
return Set.copyOf(pendingDeletes);
}
}
}

View File

@ -136,7 +136,7 @@ public abstract class PrimaryNode extends Node {
message("top: now flushAndRefresh");
Set<String> completedMergeFiles;
synchronized(finishedMergedFiles) {
completedMergeFiles = Collections.unmodifiableSet(new HashSet<>(finishedMergedFiles));
completedMergeFiles = Set.copyOf(finishedMergedFiles);
}
mgr.maybeRefreshBlocking();
boolean result = setCurrentInfos(completedMergeFiles);

View File

@ -593,14 +593,13 @@ public abstract class LuceneTestCase extends Assert {
private final static long STATIC_LEAK_THRESHOLD = 10 * 1024 * 1024;
/** By-name list of ignored types like loggers etc. */
private final static Set<String> STATIC_LEAK_IGNORED_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
private final static Set<String> STATIC_LEAK_IGNORED_TYPES = Set.of(
"org.slf4j.Logger",
"org.apache.solr.SolrLogFormatter",
"java.io.File", // Solr sometimes refers to this in a static way, but it has a "java.nio.fs.Path" inside
Path.class.getName(), // causes problems because interface is implemented by hidden classes
Class.class.getName(),
EnumSet.class.getName()
)));
EnumSet.class.getName());
/**
* This controls how suite-level rules are nested. It is important that _all_ rules declared