use immutablemap where possible
This commit is contained in:
parent
e195128381
commit
a15b62b572
|
|
@ -18,10 +18,10 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.api;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaTokenTypes;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
|
|
@ -3337,13 +3337,14 @@ public final class TokenTypes
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** maps from a token name to value */
|
||||
private static final Map<String, Integer> TOKEN_NAME_TO_VALUE =
|
||||
Maps.newHashMap();
|
||||
private static final ImmutableMap<String, Integer> TOKEN_NAME_TO_VALUE;
|
||||
/** maps from a token value to name */
|
||||
private static final String[] TOKEN_VALUE_TO_NAME;
|
||||
|
||||
// initialise the constants
|
||||
static {
|
||||
final ImmutableMap.Builder<String, Integer> builder =
|
||||
ImmutableMap.builder();
|
||||
final Field[] fields = TokenTypes.class.getDeclaredFields();
|
||||
String[] tempTokenValueToName = new String[0];
|
||||
for (final Field f : fields) {
|
||||
|
|
@ -3355,7 +3356,7 @@ public final class TokenTypes
|
|||
final String name = f.getName();
|
||||
try {
|
||||
final int tokenValue = f.getInt(name);
|
||||
TOKEN_NAME_TO_VALUE.put(name, tokenValue);
|
||||
builder.put(name, tokenValue);
|
||||
if (tokenValue > tempTokenValueToName.length - 1) {
|
||||
final String[] temp = new String[tokenValue + 1];
|
||||
System.arraycopy(tempTokenValueToName, 0,
|
||||
|
|
@ -3373,6 +3374,8 @@ public final class TokenTypes
|
|||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
TOKEN_NAME_TO_VALUE = builder.build();
|
||||
TOKEN_VALUE_TO_NAME = tempTokenValueToName;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks.imports;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents the result of an access check.
|
||||
|
|
@ -54,13 +54,15 @@ final class AccessResult
|
|||
LABEL_UNKNOWN);
|
||||
|
||||
/** map from results names to the respective result */
|
||||
private static final Map<String, AccessResult> NAME_TO_LEVEL =
|
||||
Maps.newHashMap();
|
||||
private static final ImmutableMap<String, AccessResult> NAME_TO_LEVEL;
|
||||
|
||||
static {
|
||||
NAME_TO_LEVEL.put(LABEL_ALLOWED, ALLOWED);
|
||||
NAME_TO_LEVEL.put(LABEL_DISALLOWED, DISALLOWED);
|
||||
NAME_TO_LEVEL.put(LABEL_UNKNOWN, UNKNOWN);
|
||||
final ImmutableMap.Builder<String, AccessResult> builder =
|
||||
ImmutableMap.builder();
|
||||
builder.put(LABEL_ALLOWED, ALLOWED);
|
||||
builder.put(LABEL_DISALLOWED, DISALLOWED);
|
||||
builder.put(LABEL_UNKNOWN, UNKNOWN);
|
||||
NAME_TO_LEVEL = builder.build();
|
||||
}
|
||||
|
||||
/** Code for the access result. */
|
||||
|
|
|
|||
|
|
@ -18,19 +18,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.filters;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
|
||||
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
|
||||
import com.puppycrawl.tools.checkstyle.api.FileContents;
|
||||
|
|
@ -38,6 +26,15 @@ import com.puppycrawl.tools.checkstyle.api.Filter;
|
|||
import com.puppycrawl.tools.checkstyle.api.TextBlock;
|
||||
import com.puppycrawl.tools.checkstyle.api.Utils;
|
||||
import com.puppycrawl.tools.checkstyle.checks.FileContentsHolder;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -292,7 +289,7 @@ public class SuppressWithNearbyCommentFilter
|
|||
|
||||
//TODO: Investigate performance improvement with array
|
||||
/** Tagged comments */
|
||||
private final List<Tag> mTags = new ArrayList<Tag>();
|
||||
private final List<Tag> mTags = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* References the current FileContents for this filter.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
lines="28"/>
|
||||
<suppress checks="ImportControl"
|
||||
files="SuppressWithNearbyCommentFilter.java"
|
||||
lines="40"/>
|
||||
lines="28"/>
|
||||
<suppress id="paramNum"
|
||||
files="LocalizedMessage.java"
|
||||
lines="141,145,178,210"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue