Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
PMD is an extensible multilanguage static code analyzer. It finds common programming flaws like unused variables,
empty catch blocks, unnecessary object creation, and so forth. It's mainly concerned with Java and
Apex, but supports 16 other languages. It comes with 400+ built-in rules. It can be
extended with custom rules. It uses JavaCC and Antlr to parse source files into abstract syntax trees
(AST) and runs rules against them to find violations. Rules can be written in Java or using a XPath query.
Currently, PMD supports Java, JavaScript, Salesforce.com Apex and Visualforce,
Kotlin, Swift, Modelica, PLSQL, Apache Velocity, JSP, WSDL, Maven POM, HTML, XML and XSL.
Scala is supported, but there are currently no Scala rules available.
Additionally, it includes CPD, the copy-paste-detector. CPD finds duplicated code in
Coco, C/C++, C#, Dart, Fortran, Gherkin, Go, Groovy, HTML, Java, JavaScript, JSP, Julia, Kotlin,
Lua, Matlab, Modelica, Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex and
Visualforce, Scala, Swift, T-SQL, Typescript, Apache Velocity, WSDL, XML and XSL.
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.util;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyIterator;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collector.Characteristics;
import java.util.stream.Collectors;
import org.apache.commons.lang3.Validate;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.pcollections.ConsPStack;
import org.pcollections.HashTreePSet;
import org.pcollections.PMap;
import org.pcollections.PSequence;
import org.pcollections.PSet;
import net.sourceforge.pmd.lang.document.Chars;
/**
* Generic collection-related utility functions for java.util types.
*
* @author Brian Remedios
* @author Clément Fournier
*/
public final class CollectionUtil {
private static final int UNKNOWN_SIZE = -1;
private CollectionUtil() {
}
/**
* Returns a list view that pretends it is the concatenation of
* both lists. The returned view is unmodifiable. The implementation
* is pretty stupid and not optimized for repeated concatenation,
* but should be ok for smallish chains of random-access lists.
*
* @param head Head elements (to the left)
* @param tail Tail elements (to the right)
* @param Type of elements in both lists
*
* @return A concatenated view
*/
public static List concatView(List extends T> head, List extends T> tail) {
if (head.isEmpty()) {
return makeUnmodifiableAndNonNull(tail);
} else if (tail.isEmpty()) {
return makeUnmodifiableAndNonNull(head);
} else {
return new ConsList<>(head, tail);
}
}
/**
* Returns the set union of the given collections.
*
* @param c1 First collection
* @param c2 Second collection
*
* @return Union of both arguments
*/
@SafeVarargs
public static Set union(Collection extends T> c1, Collection extends T> c2, Collection extends T>... rest) {
Set union = new LinkedHashSet<>(c1);
union.addAll(c2);
for (Collection extends T> ts : rest) {
union.addAll(ts);
}
return union;
}
/**
* Returns the set intersection of the given collections.
*
* @param c1 First collection
* @param c2 Second collection
*
* @return Intersection of both arguments
*/
@SafeVarargs
public static Set intersect(Collection extends T> c1, Collection extends T> c2, Collection extends T>... rest) {
Set union = new LinkedHashSet<>(c1);
union.retainAll(c2);
for (Collection extends T> ts : rest) {
union.retainAll(ts);
}
return union;
}
/**
* Returns the set difference of the first collection with the other
* collections.
*
* @param c1 First collection
* @param c2 Second collection
*
* @return Difference of arguments
*/
@SafeVarargs
public static Set diff(Collection extends T> c1, Collection extends T> c2, Collection extends T>... rest) {
Set union = new LinkedHashSet<>(c1);
union.removeAll(c2);
for (Collection extends T> ts : rest) {
union.removeAll(ts);
}
return union;
}
/**
* Returns a set containing the given elements. No guarantee is
* made about mutability.
*
* @param first First element
* @param rest Following elements
*/
@SafeVarargs
public static Set setOf(T first, T... rest) {
return immutableSetOf(first, rest);
}
/**
* Returns an unmodifiable set containing the given elements.
*
* @param first First element
* @param rest Following elements
*/
@SafeVarargs
public static Set immutableSetOf(T first, T... rest) {
if (rest.length == 0) {
return Collections.singleton(first);
}
Set union = new LinkedHashSet<>();
union.add(first);
Collections.addAll(union, rest);
return Collections.unmodifiableSet(union);
}
/**
* Returns an unmodifiable set containing the given elements.
*
* @param first First element
* @param rest Following elements
*/
@SafeVarargs
public static > Set immutableEnumSet(T first, T... rest) {
return Collections.unmodifiableSet(EnumSet.of(first, rest));
}
@SafeVarargs
public static List listOf(T first, T... rest) {
if (rest.length == 0) {
return ConsPStack.singleton(first);
}
List union = new ArrayList<>();
union.add(first);
union.addAll(asList(rest));
return Collections.unmodifiableList(union);
}
public static Map mapOf(K k0, V v0) {
return Collections.singletonMap(k0, v0);
}
public static Map mapOf(K k1, V v1, K k2, V v2) {
Map map = new LinkedHashMap<>();
map.put(k1, v1);
map.put(k2, v2);
return Collections.unmodifiableMap(map);
}
public static Map buildMap(Consumer