Skip to content

Commit

Permalink
Issue checkstyle#3433: Get rid of com.google.common.collect.Sets
Browse files Browse the repository at this point in the history
  • Loading branch information
MEZk committed Sep 19, 2016
1 parent 73ef2ec commit de1e8f9
Show file tree
Hide file tree
Showing 38 changed files with 140 additions and 130 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
Expand Up @@ -23,16 +23,17 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
Expand Down Expand Up @@ -214,7 +215,7 @@ public int process(List<File> files) throws CheckstyleException {
* checks and filters.
*/
private Set<String> getExternalResourceLocations() {
final Set<String> externalResources = Sets.newHashSet();
final Set<String> externalResources = new HashSet<>();
fileSetChecks.stream().filter(check -> check instanceof ExternalResourceHolder)
.forEach(check -> {
final Set<String> locations =
Expand Down Expand Up @@ -290,7 +291,7 @@ private void processFiles(List<File> files) throws CheckstyleException {
* @throws CheckstyleException if error condition within Checkstyle occurs.
*/
private SortedSet<LocalizedMessage> processFile(File file) throws CheckstyleException {
final SortedSet<LocalizedMessage> fileMessages = Sets.newTreeSet();
final SortedSet<LocalizedMessage> fileMessages = new TreeSet<>();
try {
final FileText theText = new FileText(file.getAbsoluteFile(), charset);
for (final FileSetCheck fsc : fileSetChecks) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.Deque;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -35,7 +36,6 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
import com.puppycrawl.tools.checkstyle.api.AbstractLoader;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
Expand Down Expand Up @@ -68,7 +68,7 @@ public final class PackageNamesLoader
private final Deque<String> packageStack = new ArrayDeque<>();

/** The fully qualified package names. */
private final Set<String> packageNames = Sets.newLinkedHashSet();
private final Set<String> packageNames = new LinkedHashSet<>();

/**
* Creates a new {@code PackageNamesLoader} instance.
Expand Down
Expand Up @@ -20,14 +20,15 @@
package com.puppycrawl.tools.checkstyle;

import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;

Expand Down Expand Up @@ -68,7 +69,7 @@ public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoa
}

//create a copy of the given set, but retain ordering
packages = Sets.newLinkedHashSet(packageNames);
packages = new LinkedHashSet<>(packageNames);
this.moduleClassLoader = moduleClassLoader;
}

Expand Down Expand Up @@ -127,7 +128,7 @@ private Object createObjectWithIgnoringProblems(String className,
* @return all possible name for a class.
*/
private Set<String> getAllPossibleNames(String name) {
final Set<String> names = Sets.newHashSet();
final Set<String> names = new HashSet<>();
names.addAll(packages.stream().map(packageName -> packageName + name)
.collect(Collectors.toList()));
return names;
Expand Down
Expand Up @@ -35,12 +35,12 @@
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import javax.xml.bind.DatatypeConverter;

import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
import com.google.common.io.Flushables;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
Expand Down Expand Up @@ -241,7 +241,7 @@ public void putExternalResources(Set<String> locations) {
* @return a set of {@link ExternalResource}.
*/
private static Set<ExternalResource> loadExternalResources(Set<String> resourceLocations) {
final Set<ExternalResource> resources = Sets.newHashSet();
final Set<ExternalResource> resources = new HashSet<>();
for (String location : resourceLocations) {
String contentHashSum = null;
try {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/puppycrawl/tools/checkstyle/TreeWalker.java
Expand Up @@ -39,7 +39,6 @@
import antlr.TokenStreamRecognitionException;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
Expand Down Expand Up @@ -75,10 +74,10 @@ public final class TreeWalker extends AbstractFileSetCheck implements ExternalRe
HashMultimap.create();

/** Registered ordinary checks, that don't use comment nodes. */
private final Set<AbstractCheck> ordinaryChecks = Sets.newHashSet();
private final Set<AbstractCheck> ordinaryChecks = new HashSet<>();

/** Registered comment checks. */
private final Set<AbstractCheck> commentChecks = Sets.newHashSet();
private final Set<AbstractCheck> commentChecks = new HashSet<>();

/** The distance between tab stops. */
private int tabWidth = DEFAULT_TAB_WIDTH;
Expand Down Expand Up @@ -478,7 +477,7 @@ public Set<String> getExternalResourceLocations() {
* @return a set of external configuration resource locations which are used by the checks set.
*/
private static Set<String> getExternalResourceLocations(Set<AbstractCheck> checks) {
final Set<String> externalConfigurationResources = Sets.newHashSet();
final Set<String> externalConfigurationResources = new HashSet<>();
checks.stream().filter(check -> check instanceof ExternalResourceHolder).forEach(check -> {
final Set<String> checkExternalResources =
((ExternalResourceHolder) check).getExternalResourceLocations();
Expand Down
Expand Up @@ -20,10 +20,9 @@
package com.puppycrawl.tools.checkstyle.api;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import com.google.common.collect.Sets;

import com.puppycrawl.tools.checkstyle.utils.CommonUtils;

/**
Expand All @@ -38,7 +37,7 @@ public abstract class AbstractCheck extends AbstractViolationReporter {
private static final int DEFAULT_TAB_WIDTH = 8;

/** The tokens the check is interested in. */
private final Set<String> tokens = Sets.newHashSet();
private final Set<String> tokens = new HashSet<>();

/** The current file contents. */
private FileContents fileContents;
Expand Down
Expand Up @@ -20,11 +20,10 @@
package com.puppycrawl.tools.checkstyle.api;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import com.google.common.collect.Sets;

/**
* A filter set applies filters to AuditEvents.
* If a filter in the set rejects an AuditEvent, then the
Expand All @@ -34,7 +33,7 @@
public class FilterSet
implements Filter {
/** Filter set. */
private final Set<Filter> filters = Sets.newHashSet();
private final Set<Filter> filters = new HashSet<>();

/**
* Adds a Filter to the set.
Expand Down
Expand Up @@ -21,23 +21,22 @@

import java.util.Set;
import java.util.SortedSet;

import com.google.common.collect.Sets;
import java.util.TreeSet;

/**
* Collection of messages.
* @author Oliver Burn
*/
public final class LocalizedMessages {
/** Contains the messages logged. **/
private final Set<LocalizedMessage> messages = Sets.newTreeSet();
private final Set<LocalizedMessage> messages = new TreeSet<>();

/**
* Gets the logged messages.
* @return the logged messages
*/
public SortedSet<LocalizedMessage> getMessages() {
return Sets.newTreeSet(messages);
return new TreeSet<>(messages);
}

/** Reset the object. **/
Expand Down
Expand Up @@ -20,13 +20,13 @@
package com.puppycrawl.tools.checkstyle.checks;

import java.util.Deque;
import java.util.HashSet;
import java.util.Map;
import java.util.Queue;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
Expand Down Expand Up @@ -243,7 +243,7 @@ private static class LexicalFrame {
*/
protected LexicalFrame(LexicalFrame parent) {
this.parent = parent;
varNames = Sets.newHashSet();
varNames = new HashSet<>();
}

/** Add a name to the frame.
Expand Down Expand Up @@ -328,10 +328,10 @@ private static class ClassFrame extends LexicalFrame {
*/
ClassFrame(LexicalFrame parent) {
super(parent);
instanceMembers = Sets.newHashSet();
instanceMethods = Sets.newHashSet();
staticMembers = Sets.newHashSet();
staticMethods = Sets.newHashSet();
instanceMembers = new HashSet<>();
instanceMethods = new HashSet<>();
staticMembers = new HashSet<>();
staticMethods = new HashSet<>();
}

/**
Expand Down
Expand Up @@ -21,12 +21,12 @@

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
Expand All @@ -48,7 +48,7 @@ public abstract class AbstractTypeAwareCheck extends AbstractCheck {
private final Deque<Map<String, AbstractClassInfo>> typeParams = new ArrayDeque<>();

/** Imports details. **/
private final Set<String> imports = Sets.newHashSet();
private final Set<String> imports = new HashSet<>();

/** Full identifier for package of the method. **/
private FullIdent packageFullIdent;
Expand Down
Expand Up @@ -19,12 +19,12 @@

package com.puppycrawl.tools.checkstyle.checks;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TextBlock;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void beginTree(DetailAST rootAST) {
.getCppComments();
final Map<Integer, List<TextBlock>> cComments = getFileContents()
.getCComments();
final Set<Integer> lines = Sets.newHashSet();
final Set<Integer> lines = new HashSet<>();
lines.addAll(cppComments.keySet());
lines.addAll(cComments.keySet());

Expand Down

0 comments on commit de1e8f9

Please sign in to comment.