Skip to content

Commit 012b7b7

Browse files
committed
use builderWithExpectedSize when possible
1 parent 81601a1 commit 012b7b7

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/IssueCodeToLabelMapGenerationTest.xtend

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class IssueCodeToLabelMapGenerationTest extends AbstractCheckGenerationTestCase
4646
''';
4747

4848
// check for the construction of an empty map
49-
val expectedCatalog = #['ImmutableMap.<String,String>builder().build()']
49+
val expectedCatalog = #['ImmutableMap.<String,String>builderWithExpectedSize(0).build()']
5050

5151
// ACT AND ASSERT
5252
testMapGeneration(source, expectedCatalog)
@@ -121,7 +121,7 @@ class IssueCodeToLabelMapGenerationTest extends AbstractCheckGenerationTestCase
121121
val catalogClass = compiledClassesList.findFirst[s | s.fileName.equals(catalogClassName)].code;
122122

123123
for (code: expectedCatalog) {
124-
assertTrue('''«catalogClassName» was generated correctly''', catalogClass.replaceAll("\\s+","").contains(code))
124+
assertTrue('''«catalogClassName» was generated correctly''', catalogClass.replaceAll("\\s+","").contains(code))
125125
}
126126
}
127127

com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/jvmmodel/CheckJvmModelInferrer.xtend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class CheckJvmModelInferrer extends AbstractModelInferrer {
121121
}
122122
}
123123
initializer = [append('''
124-
«ImmutableMap.simpleName».<«String.simpleName», «String.simpleName»>builder()
124+
«ImmutableMap.simpleName».<«String.simpleName», «String.simpleName»>builderWithExpectedSize(«sortedUniqueQualifiedIssueCodeNamesAndLabels.entrySet.size»)
125125
«FOR qualifiedIssueCodeNameAndLabel : sortedUniqueQualifiedIssueCodeNamesAndLabels.entrySet»
126126
.put(«qualifiedIssueCodeNameAndLabel.key», "«qualifiedIssueCodeNameAndLabel.value»")
127127
«ENDFOR»

com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProviderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
/**
4040
* Unit test for {@link DefaultCheckRuleLabelProvider}.
4141
*/
42+
@SuppressWarnings("nls")
4243
public class CheckRuleLabelProviderTest {
4344

4445
// Test data
@@ -114,7 +115,7 @@ private void mockValidatorsWithChecks() {
114115
when(mockCheckValidatorRegistry.getValidators()).thenReturn(mockValidators);
115116

116117
for (int validator = 0; NUM_VALIDATORS > validator; ++validator) {
117-
final Builder<String, String> builder = ImmutableMap.<String, String> builder();
118+
final Builder<String, String> builder = ImmutableMap.builder();
118119
for (int check = 0; NUM_CHECKS_PER_VALIDATOR > check; ++check) {
119120
builder.put(ISSUE_CODES[validator][check], LABELS[validator][check]);
120121
}

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ private void pollForCancellation(final IProgressMonitor monitor) {
12811281
* @return the map of URIs indexed by their managers
12821282
*/
12831283
private ImmutableListMultimap<Manager, URI> getUrisByManager(final Set<URI> uRIs) {
1284-
ImmutableListMultimap.Builder<Manager, URI> builder = ImmutableListMultimap.builder();
1284+
ImmutableListMultimap.Builder<Manager, URI> builder = ImmutableListMultimap.builderWithExpectedKeys(uRIs.size());
12851285
for (URI uri : uRIs) {
12861286
Manager mgr = getResourceDescriptionManager(uri);
12871287
if (mgr != null) {

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/DetachableEObjectDescription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static IEObjectDescription create(final QualifiedName qualifiedName, fina
133133
* @return object description
134134
*/
135135
public static IEObjectDescription create(final QualifiedName qualifiedName, final EObject element) {
136-
return new DetachableEObjectDescription(qualifiedName, element, ImmutableMap.<String, String> of());
136+
return new DetachableEObjectDescription(qualifiedName, element, Map.of());
137137
}
138138

139139
@Override

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/FixedCopiedResourceDescription.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public FixedCopiedResourceDescription(final IResourceDescription original) {
6464
}
6565
InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
6666
result.eSetProxyURI(from.getEObjectURI());
67-
ImmutableMap.Builder<String, String> userData = ImmutableMap.builder();
68-
for (final String key : from.getUserDataKeys()) {
67+
String[] userDataKeys = from.getUserDataKeys();
68+
ImmutableMap.Builder<String, String> userData = ImmutableMap.builderWithExpectedSize(userDataKeys.length);
69+
for (final String key : userDataKeys) {
6970
userData.put(key, from.getUserData(key));
7071
}
7172
return EObjectDescription.create(from.getName(), result, userData.build());

0 commit comments

Comments
 (0)