Skip to content

Commit

Permalink
SOLR-16318: Use up to JDK 11 features (avoid type declaration when <>…
Browse files Browse the repository at this point in the history
… can be used) (apache#916)

Co-authored-by: Kevin Risden <[email protected]>
  • Loading branch information
cpoerschke and risdenk authored Sep 15, 2022
1 parent 992b375 commit f1f32d3
Show file tree
Hide file tree
Showing 217 changed files with 357 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static void printReport(List<String> files, String mode, int stacksize, i
stack.append(frameToString(trace.getFrames().get(i), lineNumbers));
}
String line = stack.toString();
SimpleEntry<String,Long> entry = histogram.computeIfAbsent(line, u -> new SimpleEntry<String, Long>(line, 0L));
SimpleEntry<String,Long> entry = histogram.computeIfAbsent(line, u -> new SimpleEntry<>(line, 0L));
long value = getValue(event);
entry.setValue(entry.getValue() + value);
totalEvents++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static Map<String, Object> getNewProperties(ZkNodeProps message) {
for (Map.Entry<String, Object> entry : message.getProperties().entrySet()) {
if (entry.getKey().startsWith(CONFIG_SET_PROPERTY_PREFIX)) {
if (properties == null) {
properties = new HashMap<String, Object>();
properties = new HashMap<>();
}
properties.put(
entry.getKey().substring((CONFIG_SET_PROPERTY_PREFIX).length()), entry.getValue());
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cloud/Overseer.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public synchronized void start(String id) {
ccThread.start();

systemCollectionCompatCheck(
new BiConsumer<String, Object>() {
new BiConsumer<>() {
boolean firstPair = true;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void shrinkIfNeeded() throws KeeperException, InterruptedException {
int cleanupSize = maxSize / 10;

final PriorityQueue<Long> priorityQueue =
new PriorityQueue<Long>(cleanupSize) {
new PriorityQueue<>(cleanupSize) {
@Override
protected boolean lessThan(Long a, Long b) {
return (a > b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList<Objec
// Let's cleanup as we hit an exception
// We shouldn't be passing 'results' here for the cleanup as the response would then contain
// 'success' element, which may be interpreted by the user as a positive ack
CollectionHandlingUtils.cleanupCollection(collectionName, new NamedList<Object>(), ccc);
CollectionHandlingUtils.cleanupCollection(collectionName, new NamedList<>(), ccc);
log.info("Cleaned up artifacts for failed create collection for [{}]", collectionName);
throw new SolrException(
ErrorCode.BAD_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public List<CoreDescriptor> discover(final CoreContainer cc) {
this.rootDirectory,
options,
maxDepth,
new SimpleFileVisitor<Path>() {
new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/core/NodeRoles.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class NodeRoles {
private Map<Role, String> nodeRoles;

public NodeRoles(String rolesString) {
Map<Role, String> roles = new EnumMap<Role, String>(Role.class);
Map<Role, String> roles = new EnumMap<>(Role.class);
if (StringUtils.isEmpty(rolesString)) {
rolesString = DEFAULT_ROLES_STRING;
}
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/core/PluginBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public PluginHolder<T> createPlugin(PluginInfo info) {
if (log.isDebugEnabled()) {
log.debug("{} : '{}' created with startup=lazy ", meta.getCleanTag(), info.name);
}
return new LazyPluginHolder<T>(meta, info, core, core.getResourceLoader());
return new LazyPluginHolder<>(meta, info, core, core.getResourceLoader());
} else {
if (info.pkgName != null) {
PackagePluginHolder<T> holder = new PackagePluginHolder<>(info, core, meta);
Expand Down Expand Up @@ -329,7 +329,7 @@ void init(Map<String, T> defaults, SolrCore solrCore, List<PluginInfo> infos) {
}
for (Map.Entry<String, T> e : defaults.entrySet()) {
if (!contains(e.getKey())) {
put(e.getKey(), new PluginHolder<T>(null, e.getValue()));
put(e.getKey(), new PluginHolder<>(null, e.getValue()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public boolean isLeader() {

@Override
public void write(JSONWriter arg0) {
LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>();
LinkedHashMap<String, Object> info = new LinkedHashMap<>();
info.put(CoreAdminParams.CORE, getCoreName());
info.put(SolrSnapshotManager.INDEX_DIR_PATH, getIndexDirPath());
info.put(SolrSnapshotManager.GENERATION_NUM, getGenerationNumber());
Expand Down Expand Up @@ -244,7 +244,7 @@ public NamedList<Object> toNamedList() {
result.add(SolrSnapshotManager.SNAPSHOT_STATUS, this.status.toString());
result.add(SolrSnapshotManager.CREATION_DATE, this.getCreationDate().getTime());

NamedList<NamedList<Object>> replicas = new NamedList<NamedList<Object>>();
NamedList<NamedList<Object>> replicas = new NamedList<>();
for (CoreSnapshotMetaData x : replicaSnapshots) {
replicas.add(x.getCoreName(), x.toNamedList());
}
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void nodesWithRole(SolrQueryRequest req, SolrQueryResponse rsp) throws Ex
@SuppressWarnings("unchecked")
public void rolesForNode(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
String node = req.getPathTemplateValues().get("node");
Map<String, String> ret = new HashMap<String, String>();
Map<String, String> ret = new HashMap<>();
Map<String, Map<String, Set<String>>> roles =
(Map<String, Map<String, Set<String>>>)
readRecursive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static boolean handleCommit(
SolrQueryRequest req, UpdateRequestProcessor processor, SolrParams params, boolean force)
throws IOException {
if (params == null) {
params = new MapSolrParams(new HashMap<String, String>());
params = new MapSolrParams(new HashMap<>());
}

boolean optimize = params.getBool(UpdateParams.OPTIMIZE, false);
Expand Down Expand Up @@ -115,7 +115,7 @@ public static boolean handleRollback(
SolrQueryRequest req, UpdateRequestProcessor processor, SolrParams params, boolean force)
throws IOException {
if (params == null) {
params = new MapSolrParams(new HashMap<String, String>());
params = new MapSolrParams(new HashMap<>());
}

boolean rollback = params.getBool(UpdateParams.ROLLBACK, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public CoreAdminHandler() {
// should happen in the constructor...
this.coreContainer = null;
HashMap<String, Map<String, TaskObject>> map = new HashMap<>(3, 1.0f);
map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<>()));
map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<>()));
map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<>()));
requestStatusMap = Collections.unmodifiableMap(map);
}

Expand All @@ -124,9 +124,9 @@ public CoreAdminHandler() {
public CoreAdminHandler(final CoreContainer coreContainer) {
this.coreContainer = coreContainer;
HashMap<String, Map<String, TaskObject>> map = new HashMap<>(3, 1.0f);
map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<>()));
map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<>()));
map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<>()));
requestStatusMap = Collections.unmodifiableMap(map);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public PivotFacet(ResponseBuilder rb, String facetStr) {
public void addRefinement(int shardNumber, PivotFacetValue value) {

if (!queuedRefinements.containsKey(shardNumber)) {
queuedRefinements.put(shardNumber, new ArrayList<PivotFacetValue>());
queuedRefinements.put(shardNumber, new ArrayList<>());
}

queuedRefinements.get(shardNumber).add(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
if (!rb.isDistrib
&& req.getParams().getBool(ShardParams.SHARDS_INFO, false)
&& rb.shortCircuitedURL != null) {
NamedList<Object> shardInfo = new SimpleOrderedMap<Object>();
SimpleOrderedMap<Object> nl = new SimpleOrderedMap<Object>();
NamedList<Object> shardInfo = new SimpleOrderedMap<>();
SimpleOrderedMap<Object> nl = new SimpleOrderedMap<>();
if (rsp.getException() != null) {
Throwable cause = rsp.getException();
if (cause instanceof SolrServerException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static enum Stat {
boolean parseParams(StatsField sf) {
String percentileParas = sf.localParams.get(this.name());
if (percentileParas != null) {
List<Double> percentiles = new ArrayList<Double>();
List<Double> percentiles = new ArrayList<>();
try {
for (String percentile : StrUtils.splitSmart(percentileParas, ',')) {
percentiles.add(Double.parseDouble(percentile));
Expand Down Expand Up @@ -149,7 +149,7 @@ boolean parseParams(StatsField sf) {
* @see #getDistribDeps
*/
Stat(boolean selfDep, Stat... deps) {
distribDeps = new ArrayList<Stat>(deps.length + 1);
distribDeps = new ArrayList<>(deps.length + 1);
distribDeps.addAll(Arrays.asList(deps));
if (selfDep) {
distribDeps.add(this);
Expand Down Expand Up @@ -220,7 +220,7 @@ boolean parseParams(StatsField sf) {
private final List<String> excludeTagList;
private final EnumSet<Stat> statsToCalculate = EnumSet.noneOf(Stat.class);
private final EnumSet<Stat> statsInResponse = EnumSet.noneOf(Stat.class);
private final List<Double> percentilesList = new ArrayList<Double>();
private final List<Double> percentilesList = new ArrayList<>();
private final boolean isShard;

private double tdigestCompression = 100.0D;
Expand Down Expand Up @@ -397,7 +397,7 @@ public DocSet computeBaseDocSet() throws IOException {
return docs;
}

IdentityHashMap<Query, Boolean> excludeSet = new IdentityHashMap<Query, Boolean>();
IdentityHashMap<Query, Boolean> excludeSet = new IdentityHashMap<>();
for (String excludeTag : excludeTagList) {
Object olst = tagMap.get(excludeTag);
// tagMap has entries of List<String,List<QParser>>, but subject to change in the future
Expand All @@ -419,7 +419,7 @@ public DocSet computeBaseDocSet() throws IOException {
}
if (excludeSet.size() == 0) return docs;

List<Query> qlist = new ArrayList<Query>();
List<Query> qlist = new ArrayList<>();

// add the base query
if (!excludeSet.containsKey(rb.getQuery())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private Bits computeDocCorpus(SolrQueryRequest req) throws SyntaxError, IOExcept
final SolrIndexSearcher searcher = req.getSearcher();
final Bits docBits;
if (corpusFilterQueries != null && corpusFilterQueries.length > 0) {
List<Query> filterQueries = new ArrayList<Query>(corpusFilterQueries.length);
List<Query> filterQueries = new ArrayList<>(corpusFilterQueries.length);
for (String corpusFilterQuery : corpusFilterQueries) {
QParser qParser = QParser.getParser(corpusFilterQuery, null, req);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected boolean emptyArray(String[] arr) {

protected static String[] expandWildcardsInFields(
Supplier<Collection<String>> availableFieldNamesSupplier, String... inFields) {
Set<String> expandedFields = new LinkedHashSet<String>();
Set<String> expandedFields = new LinkedHashSet<>();
Collection<String> availableFieldNames = null;
for (String inField : inFields) {
for (String field : SolrPluginUtils.split(inField)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String toString() {

@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
return new Iterator<>() {
int idx = 0;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private List<Path> downloadPackageArtifacts(String packageName, String version)
throws SolrException {
try {
SolrPackageRelease release = getPackageRelease(packageName, version);
List<Path> downloadedPaths = new ArrayList<Path>(release.artifacts.size());
List<Path> downloadedPaths = new ArrayList<>(release.artifacts.size());

for (PackageRepository repo : getRepositories()) {
if (repo.hasPackage(packageName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ protected Query newGraphSynonymQuery(Iterator<Query> sidePathQueriesIterator) {
protected Query newSynonymQuery(TermAndBoost[] terms) {
switch (synonymQueryStyle) {
case PICK_BEST:
List<Query> currPosnClauses = new ArrayList<Query>(terms.length);
List<Query> currPosnClauses = new ArrayList<>(terms.length);
for (TermAndBoost term : terms) {
currPosnClauses.add(newTermQuery(term.term, term.boost));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public static <T> PluginBag.PluginHolder<T> createHolder(T inst, Class<T> type)
SolrConfig.SolrPluginInfo plugin = SolrConfig.classVsSolrPluginInfo.get(type.getName());
PluginInfo info =
new PluginInfo(plugin.tag, Collections.singletonMap("class", inst.getClass().getName()));
return new PluginBag.PluginHolder<T>(info, inst);
return new PluginBag.PluginHolder<>(info, inst);
}

public static <T> PluginBag.PluginHolder<T> createHolder(
PluginInfo info, SolrCore core, Class<T> type, String msg) {
if (info.cName.pkg == null) {
return new PluginBag.PluginHolder<T>(info, core.createInitInstance(info, type, msg, null));
return new PluginBag.PluginHolder<>(info, core.createInitInstance(info, type, msg, null));
} else {
return new PackagePluginHolder<T>(
return new PackagePluginHolder<>(
info, core, SolrConfig.classVsSolrPluginInfo.get(type.getName()));
}
}
Expand Down
8 changes: 4 additions & 4 deletions solr/core/src/java/org/apache/solr/request/NumericFacets.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public long longValue() throws IOException {
if (FacetParams.FACET_SORT_COUNT.equals(sort)
|| FacetParams.FACET_SORT_COUNT_LEGACY.equals(sort)) {
pq =
new PriorityQueue<Entry>(pqSize) {
new PriorityQueue<>(pqSize) {
@Override
protected boolean lessThan(Entry a, Entry b) {
if (a.count < b.count || (a.count == b.count && a.bits > b.bits)) {
Expand All @@ -284,7 +284,7 @@ protected boolean lessThan(Entry a, Entry b) {
};
} else {
pq =
new PriorityQueue<Entry>(pqSize) {
new PriorityQueue<>(pqSize) {
@Override
protected boolean lessThan(Entry a, Entry b) {
return a.bits > b.bits;
Expand Down Expand Up @@ -518,7 +518,7 @@ private static NamedList<Integer> getCountsMultiValued(
if (FacetParams.FACET_SORT_COUNT.equals(sort)
|| FacetParams.FACET_SORT_COUNT_LEGACY.equals(sort)) {
pq =
new PriorityQueue<Entry>(pqSize) {
new PriorityQueue<>(pqSize) {
@Override
protected boolean lessThan(Entry a, Entry b) {
if (a.count < b.count || (a.count == b.count && a.bits > b.bits)) {
Expand All @@ -531,7 +531,7 @@ protected boolean lessThan(Entry a, Entry b) {
} else {
// sort=index
pq =
new PriorityQueue<Entry>(pqSize) {
new PriorityQueue<>(pqSize) {
@Override
protected boolean lessThan(Entry a, Entry b) {
return a.bits > b.bits;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ NamedList<Integer> getFacetCounts(Executor executor) throws IOException {

// now merge the per-segment results
PriorityQueue<SegFacet> queue =
new PriorityQueue<SegFacet>(leaves.size()) {
new PriorityQueue<>(leaves.size()) {
@Override
protected boolean lessThan(SegFacet a, SegFacet b) {
return a.tempBR.compareTo(b.tempBR) < 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void mergeObjects(
@SuppressWarnings({"unchecked"})
Map<String, Object> sub = (Map<String, Object>) outer.get(path.get(i));
if (sub == null) {
sub = new LinkedHashMap<String, Object>();
sub = new LinkedHashMap<>();
outer.put(path.get(i), sub);
}
outer = sub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public Collection<Object> getRawFieldValues(String name) {
@Override
public Iterator<Entry<String, Object>> iterator() {
Iterator<Entry<String, Object>> it = _fields.entrySet().iterator();
return new Iterator<Entry<String, Object>>() {
return new Iterator<>() {
@Override
public boolean hasNext() {
return it.hasNext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected String convertFieldValue(Object val) {
@Override
public Iterator<String> getParameterNamesIterator() {
final Iterator<String> fieldNames = doc.getFieldNames().iterator();
return new Iterator<String>() {
return new Iterator<>() {

@Override
public boolean hasNext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private Analyzer readAnalyzer(ConfigNode node) {

final ArrayList<CharFilterFactory> charFilters = new ArrayList<>();
AbstractPluginLoader<CharFilterFactory> charFilterLoader =
new AbstractPluginLoader<CharFilterFactory>(
new AbstractPluginLoader<>(
"[schema.xml] analyzer/charFilter", CharFilterFactory.class, false, false) {

@Override
Expand Down Expand Up @@ -303,7 +303,7 @@ protected CharFilterFactory register(String name, CharFilterFactory plugin) {

final ArrayList<TokenizerFactory> tokenizers = new ArrayList<>(1);
AbstractPluginLoader<TokenizerFactory> tokenizerLoader =
new AbstractPluginLoader<TokenizerFactory>(
new AbstractPluginLoader<>(
"[schema.xml] analyzer/tokenizer", TokenizerFactory.class, false, false) {

@Override
Expand Down Expand Up @@ -375,7 +375,7 @@ protected TokenizerFactory register(String name, TokenizerFactory plugin) {
final ArrayList<TokenFilterFactory> filters = new ArrayList<>();

AbstractPluginLoader<TokenFilterFactory> filterLoader =
new AbstractPluginLoader<TokenFilterFactory>(
new AbstractPluginLoader<>(
"[schema.xml] analyzer/filter", TokenFilterFactory.class, false, false) {
@Override
protected TokenFilterFactory create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Object put(Object key, Object val) {

public void addCloseHook(Closeable closeable) {
if (closeHooks == null) {
closeHooks = new IdentityHashMap<Closeable, String>();
closeHooks = new IdentityHashMap<>();
// for now, defer closing until the end of the request
SolrRequestInfo.getRequestInfo().addCloseHook(this);
}
Expand Down
Loading

0 comments on commit f1f32d3

Please sign in to comment.