Skip to content

Commit

Permalink
Replace usage of Maps.newHashMapWithExpectedSize() with standard Java
Browse files Browse the repository at this point in the history
Part of #2975
  • Loading branch information
HannesWell committed Aug 14, 2024
1 parent f5f3da6 commit 83ae503
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.eclipse.xtext.builder.clustering;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -26,7 +27,6 @@
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;

/**
* Makes an eager copy of the exported objects of another resource description.
Expand Down Expand Up @@ -56,7 +56,7 @@ public IEObjectDescription apply(IEObjectDescription from) {
Map<String, String> userData = null;
for (final String key : from.getUserDataKeys()) {
if (userData == null) {
userData = Maps.newHashMapWithExpectedSize(2);
userData = new HashMap<>(3);
}
userData.put(key, from.getUserData(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*******************************************************************************/
package org.eclipse.xtext.ecore;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
Expand All @@ -19,7 +20,6 @@
import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy;
import org.eclipse.xtext.util.IAcceptor;

import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Singleton;

Expand Down Expand Up @@ -48,7 +48,7 @@ protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedName
try {
QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject);
if (qualifiedName != null) {
Map<String, String> userData = Maps.newHashMapWithExpectedSize(1);
Map<String, String> userData = new HashMap<>(2);
userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI));
IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData);
acceptor.accept(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.eclipse.xtext.ide.serializer.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -31,7 +32,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.inject.Inject;

Expand Down Expand Up @@ -59,7 +59,7 @@ public SimpleNameDescription(QualifiedName qName, EObject resolvedObject, IEObje
Map<String, String> userData = null;
for (final String key : source.getUserDataKeys()) {
if (userData == null) {
userData = Maps.newHashMapWithExpectedSize(2);
userData = new HashMap<>(3);
}
userData.put(key, source.getUserData(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*******************************************************************************/
package org.eclipse.xtext.testlanguages.ecore;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
Expand All @@ -19,7 +20,6 @@
import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy;
import org.eclipse.xtext.util.IAcceptor;

import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Singleton;

Expand Down Expand Up @@ -48,7 +48,7 @@ protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedName
try {
QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject);
if (qualifiedName != null) {
Map<String, String> userData = Maps.newHashMapWithExpectedSize(1);
Map<String, String> userData = new HashMap<>(1);
userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI));
IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData);
acceptor.accept(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.eclipse.xtext.ui.editor;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -27,7 +28,6 @@
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Provider;

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ public IEObjectDescription apply(IEObjectDescription from) {
Map<String, String> userData = null;
for(String key: from.getUserDataKeys()) {
if (userData == null) {
userData = Maps.newHashMapWithExpectedSize(2);
userData = new HashMap<>(3);
}
userData.put(key, from.getUserData(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*******************************************************************************/
package org.eclipse.xtext.xtext.generator

import com.google.common.collect.Maps
import com.google.inject.Binder
import com.google.inject.Guice
import com.google.inject.Inject
Expand All @@ -18,6 +17,7 @@ import com.google.inject.Provider
import com.google.inject.Singleton
import com.google.inject.name.Names
import java.util.Collections
import java.util.HashMap
import java.util.List
import java.util.Map
import java.util.Properties
Expand All @@ -36,12 +36,12 @@ import org.eclipse.xtext.xtext.generator.model.FileAccessFactory
import org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess
import org.eclipse.xtext.xtext.generator.model.JavaFileAccess
import org.eclipse.xtext.xtext.generator.model.TextFileAccess
import org.eclipse.xtext.xtext.generator.model.TypeReference
import org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation
import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig

import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
import org.eclipse.xtext.xtext.generator.model.TextFileAccess

/**
* Templates for generating the common language infrastructure.
Expand Down Expand Up @@ -505,7 +505,7 @@ class XtextGeneratorTemplates {

private static «activator.simpleName» INSTANCE;

private «Map»<String, «Injector»> injectors = «Collections».synchronizedMap(«Maps».<String, «Injector»> newHashMapWithExpectedSize(1));
private «Map»<String, «Injector»> injectors = «Collections».synchronizedMap(new «HashMap»<>(2));

@Override
public void start(«'org.osgi.framework.BundleContext'.typeRef» context) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
package org.eclipse.xtext.xtext.generator;

import com.google.common.collect.Maps;
import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Inject;
Expand All @@ -17,6 +16,7 @@
import com.google.inject.Singleton;
import com.google.inject.name.Names;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -1526,11 +1526,9 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui
_builder.append(Injector.class, "\t");
_builder.append("> injectors = ");
_builder.append(Collections.class, "\t");
_builder.append(".synchronizedMap(");
_builder.append(Maps.class, "\t");
_builder.append(".<String, ");
_builder.append(Injector.class, "\t");
_builder.append("> newHashMapWithExpectedSize(1));");
_builder.append(".synchronizedMap(new ");
_builder.append(HashMap.class, "\t");
_builder.append("<>(2));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -132,8 +133,7 @@ public Map<SourceRelativeURI, List<AbstractTraceRegion>> invertAll(SourceRelativ

protected Map<SourceRelativeURI, List<Pair<ILocationData, AbstractTraceRegion>>> collectMatchingLocations(
SourceRelativeURI expectedAssociatedPath) {
Map<SourceRelativeURI, List<Pair<ILocationData, AbstractTraceRegion>>> result = Maps
.newHashMapWithExpectedSize(2);
Map<SourceRelativeURI, List<Pair<ILocationData, AbstractTraceRegion>>> result = new HashMap<>(3);
Iterator<AbstractTraceRegion> treeIterator = treeIterator();
while (treeIterator.hasNext()) {
AbstractTraceRegion next = treeIterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
*******************************************************************************/
package org.eclipse.xtext.resource;

import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.Maps;

/**
* Immutable SaveOptions can be used to read and write options into the
* map that is passed into {@link org.eclipse.emf.ecore.resource.Resource#save(Map)}.
Expand Down Expand Up @@ -70,7 +69,7 @@ public void addTo(Map<Object, Object> saveOptions) {
}

public Map<Object, Object> toOptionsMap() {
Map<Object, Object> result = Maps.newHashMapWithExpectedSize(2);
Map<Object, Object> result = new HashMap<>(3);
addTo(result);
return result;
}
Expand Down

0 comments on commit 83ae503

Please sign in to comment.