The following issues were found
guava/src/com/google/common/hash/AbstractCompositeHashFunction.java
10 issues
Line: 34
*/
@Immutable
@ElementTypesAreNonnullByDefault
abstract class AbstractCompositeHashFunction extends AbstractHashFunction {
@SuppressWarnings("Immutable") // array not modified after creation
final HashFunction[] functions;
AbstractCompositeHashFunction(HashFunction... functions) {
Reported by PMD.
Line: 34
*/
@Immutable
@ElementTypesAreNonnullByDefault
abstract class AbstractCompositeHashFunction extends AbstractHashFunction {
@SuppressWarnings("Immutable") // array not modified after creation
final HashFunction[] functions;
AbstractCompositeHashFunction(HashFunction... functions) {
Reported by PMD.
Line: 37
abstract class AbstractCompositeHashFunction extends AbstractHashFunction {
@SuppressWarnings("Immutable") // array not modified after creation
final HashFunction[] functions;
AbstractCompositeHashFunction(HashFunction... functions) {
for (HashFunction function : functions) {
checkNotNull(function);
}
Reported by PMD.
Line: 39
@SuppressWarnings("Immutable") // array not modified after creation
final HashFunction[] functions;
AbstractCompositeHashFunction(HashFunction... functions) {
for (HashFunction function : functions) {
checkNotNull(function);
}
this.functions = functions;
}
Reported by PMD.
Line: 73
return fromHashers(hashers);
}
private Hasher fromHashers(final Hasher[] hashers) {
return new Hasher() {
@Override
public Hasher putByte(byte b) {
for (Hasher hasher : hashers) {
hasher.putByte(b);
Reported by PMD.
Line: 73
return fromHashers(hashers);
}
private Hasher fromHashers(final Hasher[] hashers) {
return new Hasher() {
@Override
public Hasher putByte(byte b) {
for (Hasher hasher : hashers) {
hasher.putByte(b);
Reported by PMD.
Line: 73
return fromHashers(hashers);
}
private Hasher fromHashers(final Hasher[] hashers) {
return new Hasher() {
@Override
public Hasher putByte(byte b) {
for (Hasher hasher : hashers) {
hasher.putByte(b);
Reported by PMD.
Line: 73
return fromHashers(hashers);
}
private Hasher fromHashers(final Hasher[] hashers) {
return new Hasher() {
@Override
public Hasher putByte(byte b) {
for (Hasher hasher : hashers) {
hasher.putByte(b);
Reported by PMD.
Line: 52
* hashers are the same order as the functions given to the constructor.
*/
// this could be cleaner if it passed HashCode[], but that would create yet another array...
/* protected */ abstract HashCode makeHash(Hasher[] hashers);
@Override
public Hasher newHasher() {
Hasher[] hashers = new Hasher[functions.length];
for (int i = 0; i < hashers.length; i++) {
Reported by PMD.
Line: 73
return fromHashers(hashers);
}
private Hasher fromHashers(final Hasher[] hashers) {
return new Hasher() {
@Override
public Hasher putByte(byte b) {
for (Hasher hasher : hashers) {
hasher.putByte(b);
Reported by PMD.
guava/src/com/google/common/collect/ImmutableMapValues.java
10 issues
Line: 37
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
private final ImmutableMap<K, V> map;
ImmutableMapValues(ImmutableMap<K, V> map) {
this.map = map;
}
Reported by PMD.
Line: 38
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
private final ImmutableMap<K, V> map;
ImmutableMapValues(ImmutableMap<K, V> map) {
this.map = map;
}
Reported by PMD.
Line: 61
@Override
public V next() {
return entryItr.next().getValue();
}
};
}
@Override
Reported by PMD.
Line: 68
@Override
public Spliterator<V> spliterator() {
return CollectSpliterators.map(map.entrySet().spliterator(), Entry::getValue);
}
@Override
public boolean contains(@CheckForNull Object object) {
return object != null && Iterators.contains(iterator(), object);
Reported by PMD.
Line: 83
@Override
public ImmutableList<V> asList() {
final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
return new ImmutableAsList<V>() {
@Override
public V get(int index) {
return entryList.get(index).getValue();
}
Reported by PMD.
Line: 87
return new ImmutableAsList<V>() {
@Override
public V get(int index) {
return entryList.get(index).getValue();
}
@Override
ImmutableCollection<V> delegateCollection() {
return ImmutableMapValues.this;
Reported by PMD.
Line: 108
@GwtIncompatible // serialization
@SuppressWarnings("unused")
private static class SerializedForm<V> implements Serializable {
final ImmutableMap<?, V> map;
SerializedForm(ImmutableMap<?, V> map) {
this.map = map;
}
Reported by PMD.
Line: 83
@Override
public ImmutableList<V> asList() {
final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
return new ImmutableAsList<V>() {
@Override
public V get(int index) {
return entryList.get(index).getValue();
}
Reported by PMD.
Line: 83
@Override
public ImmutableList<V> asList() {
final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
return new ImmutableAsList<V>() {
@Override
public V get(int index) {
return entryList.get(index).getValue();
}
Reported by PMD.
Line: 83
@Override
public ImmutableList<V> asList() {
final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
return new ImmutableAsList<V>() {
@Override
public V get(int index) {
return entryList.get(index).getValue();
}
Reported by PMD.
guava/src/com/google/common/escape/ArrayBasedUnicodeEscaper.java
10 issues
Line: 99
*/
protected ArrayBasedUnicodeEscaper(
ArrayBasedEscaperMap escaperMap,
int safeMin,
int safeMax,
@Nullable String unsafeReplacement) {
checkNotNull(escaperMap); // GWT specific check (do not optimize)
this.replacements = escaperMap.getReplacementArray();
this.replacementsLength = replacements.length;
Reported by PMD.
Line: 100
protected ArrayBasedUnicodeEscaper(
ArrayBasedEscaperMap escaperMap,
int safeMin,
int safeMax,
@Nullable String unsafeReplacement) {
checkNotNull(escaperMap); // GWT specific check (do not optimize)
this.replacements = escaperMap.getReplacementArray();
this.replacementsLength = replacements.length;
if (safeMax < safeMin) {
Reported by PMD.
Line: 182
/* Overridden for performance. */
@Override
protected final int nextEscapeIndex(CharSequence csq, int index, int end) {
while (index < end) {
char c = csq.charAt(index);
if ((c < replacementsLength && replacements[c] != null)
|| c > safeMaxChar
|| c < safeMinChar) {
Reported by PMD.
Line: 49
@ElementTypesAreNonnullByDefault
public abstract class ArrayBasedUnicodeEscaper extends UnicodeEscaper {
// The replacement array (see ArrayBasedEscaperMap).
private final char[][] replacements;
// The number of elements in the replacement array.
private final int replacementsLength;
// The first code point in the safe range.
private final int safeMin;
// The last code point in the safe range.
Reported by PMD.
Line: 51
// The replacement array (see ArrayBasedEscaperMap).
private final char[][] replacements;
// The number of elements in the replacement array.
private final int replacementsLength;
// The first code point in the safe range.
private final int safeMin;
// The last code point in the safe range.
private final int safeMax;
Reported by PMD.
Line: 53
// The number of elements in the replacement array.
private final int replacementsLength;
// The first code point in the safe range.
private final int safeMin;
// The last code point in the safe range.
private final int safeMax;
// Cropped values used in the fast path range checks.
private final char safeMinChar;
Reported by PMD.
Line: 55
// The first code point in the safe range.
private final int safeMin;
// The last code point in the safe range.
private final int safeMax;
// Cropped values used in the fast path range checks.
private final char safeMinChar;
private final char safeMaxChar;
Reported by PMD.
Line: 58
private final int safeMax;
// Cropped values used in the fast path range checks.
private final char safeMinChar;
private final char safeMaxChar;
/**
* Creates a new ArrayBasedUnicodeEscaper instance with the given replacement map and specified
* safe range. If {@code safeMax < safeMin} then no code points are considered safe.
Reported by PMD.
Line: 59
// Cropped values used in the fast path range checks.
private final char safeMinChar;
private final char safeMaxChar;
/**
* Creates a new ArrayBasedUnicodeEscaper instance with the given replacement map and specified
* safe range. If {@code safeMax < safeMin} then no code points are considered safe.
*
Reported by PMD.
Line: 101
ArrayBasedEscaperMap escaperMap,
int safeMin,
int safeMax,
@Nullable String unsafeReplacement) {
checkNotNull(escaperMap); // GWT specific check (do not optimize)
this.replacements = escaperMap.getReplacementArray();
this.replacementsLength = replacements.length;
if (safeMax < safeMin) {
// If the safe range is empty, set the range limits to opposite extremes
Reported by PMD.
guava/src/com/google/common/collect/UnmodifiableSortedMultiset.java
10 issues
Line: 36
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class UnmodifiableSortedMultiset<E extends @Nullable Object> extends UnmodifiableMultiset<E>
implements SortedMultiset<E> {
UnmodifiableSortedMultiset(SortedMultiset<E> delegate) {
super(delegate);
}
@Override
Reported by PMD.
Line: 48
@Override
public Comparator<? super E> comparator() {
return delegate().comparator();
}
@Override
NavigableSet<E> createElementSet() {
return Sets.unmodifiableNavigableSet(delegate().elementSet());
Reported by PMD.
Line: 53
@Override
NavigableSet<E> createElementSet() {
return Sets.unmodifiableNavigableSet(delegate().elementSet());
}
@Override
public NavigableSet<E> elementSet() {
return (NavigableSet<E>) super.elementSet();
Reported by PMD.
Line: 61
return (NavigableSet<E>) super.elementSet();
}
@CheckForNull private transient UnmodifiableSortedMultiset<E> descendingMultiset;
@Override
public SortedMultiset<E> descendingMultiset() {
UnmodifiableSortedMultiset<E> result = descendingMultiset;
if (result == null) {
Reported by PMD.
Line: 67
public SortedMultiset<E> descendingMultiset() {
UnmodifiableSortedMultiset<E> result = descendingMultiset;
if (result == null) {
result = new UnmodifiableSortedMultiset<E>(delegate().descendingMultiset());
result.descendingMultiset = this;
return descendingMultiset = result;
}
return result;
}
Reported by PMD.
Line: 77
@Override
@CheckForNull
public Entry<E> firstEntry() {
return delegate().firstEntry();
}
@Override
@CheckForNull
public Entry<E> lastEntry() {
Reported by PMD.
Line: 83
@Override
@CheckForNull
public Entry<E> lastEntry() {
return delegate().lastEntry();
}
@Override
@CheckForNull
public Entry<E> pollFirstEntry() {
Reported by PMD.
Line: 100
@Override
public SortedMultiset<E> headMultiset(@ParametricNullness E upperBound, BoundType boundType) {
return Multisets.unmodifiableSortedMultiset(delegate().headMultiset(upperBound, boundType));
}
@Override
public SortedMultiset<E> subMultiset(
@ParametricNullness E lowerBound,
Reported by PMD.
Line: 110
@ParametricNullness E upperBound,
BoundType upperBoundType) {
return Multisets.unmodifiableSortedMultiset(
delegate().subMultiset(lowerBound, lowerBoundType, upperBound, upperBoundType));
}
@Override
public SortedMultiset<E> tailMultiset(@ParametricNullness E lowerBound, BoundType boundType) {
return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType));
Reported by PMD.
Line: 115
@Override
public SortedMultiset<E> tailMultiset(@ParametricNullness E lowerBound, BoundType boundType) {
return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType));
}
private static final long serialVersionUID = 0;
}
Reported by PMD.
guava/src/com/google/common/base/CaseFormat.java
10 issues
Line: 137
StringBuilder out = null;
int i = 0;
int j = -1;
while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
if (i == 0) {
// include some extra space for separators
out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
out.append(format.normalizeFirstWord(s.substring(i, j)));
} else {
Reported by PMD.
Line: 140
while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
if (i == 0) {
// include some extra space for separators
out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
out.append(format.normalizeFirstWord(s.substring(i, j)));
} else {
requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
}
out.append(format.wordSeparator);
Reported by PMD.
Line: 140
while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
if (i == 0) {
// include some extra space for separators
out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
out.append(format.normalizeFirstWord(s.substring(i, j)));
} else {
requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
}
out.append(format.wordSeparator);
Reported by PMD.
Line: 143
out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
out.append(format.normalizeFirstWord(s.substring(i, j)));
} else {
requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
}
out.append(format.wordSeparator);
i = j + wordSeparator.length();
}
return (i == 0)
Reported by PMD.
Line: 150
}
return (i == 0)
? format.normalizeFirstWord(s)
: requireNonNull(out).append(format.normalizeWord(s.substring(i))).toString();
}
/**
* Returns a {@code Converter} that converts strings from this format to {@code targetFormat}.
*
Reported by PMD.
Line: 150
}
return (i == 0)
? format.normalizeFirstWord(s)
: requireNonNull(out).append(format.normalizeWord(s.substring(i))).toString();
}
/**
* Returns a {@code Converter} that converts strings from this format to {@code targetFormat}.
*
Reported by PMD.
Line: 165
private static final class StringConverter extends Converter<String, String>
implements Serializable {
private final CaseFormat sourceFormat;
private final CaseFormat targetFormat;
StringConverter(CaseFormat sourceFormat, CaseFormat targetFormat) {
this.sourceFormat = checkNotNull(sourceFormat);
this.targetFormat = checkNotNull(targetFormat);
Reported by PMD.
Line: 166
implements Serializable {
private final CaseFormat sourceFormat;
private final CaseFormat targetFormat;
StringConverter(CaseFormat sourceFormat, CaseFormat targetFormat) {
this.sourceFormat = checkNotNull(sourceFormat);
this.targetFormat = checkNotNull(targetFormat);
}
Reported by PMD.
Line: 134
/** Enum values can override for performance reasons. */
String convert(CaseFormat format, String s) {
// deal with camel conversion
StringBuilder out = null;
int i = 0;
int j = -1;
while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
if (i == 0) {
// include some extra space for separators
Reported by PMD.
Line: 137
StringBuilder out = null;
int i = 0;
int j = -1;
while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
if (i == 0) {
// include some extra space for separators
out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
out.append(format.normalizeFirstWord(s.substring(i, j)));
} else {
Reported by PMD.
guava/src/com/google/common/base/Converter.java
10 issues
Line: 142
*
* [*] In annotating this class, we're ignoring LegacyConverter.
*/
public abstract class Converter<A, B> implements Function<A, B> {
private final boolean handleNullAutomatically;
// We lazily cache the reverse view to avoid allocating on every call to reverse().
@LazyInit @RetainedWith @CheckForNull private transient Converter<B, A> reverse;
Reported by PMD.
Line: 143
* [*] In annotating this class, we're ignoring LegacyConverter.
*/
public abstract class Converter<A, B> implements Function<A, B> {
private final boolean handleNullAutomatically;
// We lazily cache the reverse view to avoid allocating on every call to reverse().
@LazyInit @RetainedWith @CheckForNull private transient Converter<B, A> reverse;
/** Constructor for use by subclasses. */
Reported by PMD.
Line: 146
private final boolean handleNullAutomatically;
// We lazily cache the reverse view to avoid allocating on every call to reverse().
@LazyInit @RetainedWith @CheckForNull private transient Converter<B, A> reverse;
/** Constructor for use by subclasses. */
protected Converter() {
this(true);
}
Reported by PMD.
Line: 318
private static final class ReverseConverter<A, B> extends Converter<B, A>
implements Serializable {
final Converter<A, B> original;
ReverseConverter(Converter<A, B> original) {
this.original = original;
}
Reported by PMD.
Line: 398
private static final class ConverterComposition<A, B, C> extends Converter<A, C>
implements Serializable {
final Converter<A, B> first;
final Converter<B, C> second;
ConverterComposition(Converter<A, B> first, Converter<B, C> second) {
this.first = first;
this.second = second;
Reported by PMD.
Line: 399
private static final class ConverterComposition<A, B, C> extends Converter<A, C>
implements Serializable {
final Converter<A, B> first;
final Converter<B, C> second;
ConverterComposition(Converter<A, B> first, Converter<B, C> second) {
this.first = first;
this.second = second;
}
Reported by PMD.
Line: 511
* interchangeable.
*/
@Override
public boolean equals(@CheckForNull Object object) {
return super.equals(object);
}
// Static converters
Reported by PMD.
Line: 537
return new FunctionBasedConverter<>(forwardFunction, backwardFunction);
}
private static final class FunctionBasedConverter<A, B> extends Converter<A, B>
implements Serializable {
private final Function<? super A, ? extends B> forwardFunction;
private final Function<? super B, ? extends A> backwardFunction;
private FunctionBasedConverter(
Reported by PMD.
Line: 539
private static final class FunctionBasedConverter<A, B> extends Converter<A, B>
implements Serializable {
private final Function<? super A, ? extends B> forwardFunction;
private final Function<? super B, ? extends A> backwardFunction;
private FunctionBasedConverter(
Function<? super A, ? extends B> forwardFunction,
Function<? super B, ? extends A> backwardFunction) {
Reported by PMD.
Line: 540
private static final class FunctionBasedConverter<A, B> extends Converter<A, B>
implements Serializable {
private final Function<? super A, ? extends B> forwardFunction;
private final Function<? super B, ? extends A> backwardFunction;
private FunctionBasedConverter(
Function<? super A, ? extends B> forwardFunction,
Function<? super B, ? extends A> backwardFunction) {
this.forwardFunction = checkNotNull(forwardFunction);
Reported by PMD.
guava/src/com/google/common/base/Strings.java
10 issues
Line: 263
*/
// TODO(diamondm) consider using Arrays.toString() for array parameters
public static String lenientFormat(
@CheckForNull String template, @CheckForNull @Nullable Object... args) {
template = String.valueOf(template); // null -> "null"
if (args == null) {
args = new Object[] {"(Object[])null"};
} else {
Reported by PMD.
Line: 149
public static String repeat(String string, int count) {
checkNotNull(string); // eager for GWT.
if (count <= 1) {
checkArgument(count >= 0, "invalid count: %s", count);
return (count == 0) ? "" : string;
}
// IF YOU MODIFY THE CODE HERE, you must update StringsRepeatBenchmark
Reported by PMD.
Line: 191
if (validSurrogatePairAt(a, p - 1) || validSurrogatePairAt(b, p - 1)) {
p--;
}
return a.subSequence(0, p).toString();
}
/**
* Returns the longest string {@code suffix} such that {@code a.toString().endsWith(suffix) &&
* b.toString().endsWith(suffix)}, taking care not to split surrogate pairs. If {@code a} and
Reported by PMD.
Line: 214
|| validSurrogatePairAt(b, b.length() - s - 1)) {
s--;
}
return a.subSequence(a.length() - s, a.length()).toString();
}
/**
* True when a valid surrogate pair starts at the given {@code index} in the given {@code string}.
* Out-of-range indexes return false.
Reported by PMD.
Line: 275
}
// start substituting the arguments into the '%s' placeholders
StringBuilder builder = new StringBuilder(template.length() + 16 * args.length);
int templateStart = 0;
int i = 0;
while (i < args.length) {
int placeholderStart = template.indexOf("%s", templateStart);
if (placeholderStart == -1) {
Reported by PMD.
Line: 287
builder.append(args[i++]);
templateStart = placeholderStart + 2;
}
builder.append(template, templateStart, template.length());
// if we run out of placeholders, append the extra args in square braces
if (i < args.length) {
builder.append(" [");
builder.append(args[i++]);
Reported by PMD.
Line: 309
}
try {
return o.toString();
} catch (Exception e) {
// Default toString() behavior - see Object.toString()
String objectToString =
o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
// Logger is created inline with fixed name to avoid forcing Proguard to create another class.
Logger.getLogger("com.google.common.base.Strings")
Reported by PMD.
Line: 312
} catch (Exception e) {
// Default toString() behavior - see Object.toString()
String objectToString =
o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
// Logger is created inline with fixed name to avoid forcing Proguard to create another class.
Logger.getLogger("com.google.common.base.Strings")
.log(WARNING, "Exception during lenientFormat for " + objectToString, e);
return "<" + objectToString + " threw " + e.getClass().getName() + ">";
}
Reported by PMD.
Line: 314
String objectToString =
o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
// Logger is created inline with fixed name to avoid forcing Proguard to create another class.
Logger.getLogger("com.google.common.base.Strings")
.log(WARNING, "Exception during lenientFormat for " + objectToString, e);
return "<" + objectToString + " threw " + e.getClass().getName() + ">";
}
}
}
Reported by PMD.
Line: 316
// Logger is created inline with fixed name to avoid forcing Proguard to create another class.
Logger.getLogger("com.google.common.base.Strings")
.log(WARNING, "Exception during lenientFormat for " + objectToString, e);
return "<" + objectToString + " threw " + e.getClass().getName() + ">";
}
}
}
Reported by PMD.
guava-tests/benchmark/com/google/common/io/CharStreamsCopyBenchmark.java
10 issues
Line: 78
abstract Appendable get(int sz);
}
@Param CopyStrategy strategy;
@Param TargetSupplier target;
@Param({"10", "1024", "1048576"})
int size;
Reported by PMD.
Line: 79
}
@Param CopyStrategy strategy;
@Param TargetSupplier target;
@Param({"10", "1024", "1048576"})
int size;
String data;
Reported by PMD.
Line: 82
@Param TargetSupplier target;
@Param({"10", "1024", "1048576"})
int size;
String data;
@BeforeExperiment
public void setUp() {
Reported by PMD.
Line: 84
@Param({"10", "1024", "1048576"})
int size;
String data;
@BeforeExperiment
public void setUp() {
// precalculate some random strings of ascii characters.
StringBuilder sb = new StringBuilder();
Reported by PMD.
Line: 86
String data;
@BeforeExperiment
public void setUp() {
// precalculate some random strings of ascii characters.
StringBuilder sb = new StringBuilder();
Random random = new Random(0xdeadbeef); // for unpredictable but reproducible behavior
sb.ensureCapacity(size);
Reported by PMD.
Line: 107
final CopyStrategy localStrategy = strategy;
for (int i = 0; i < reps; i++) {
Appendable appendable = localTarget.get(localData.length());
r += localStrategy.copy(new StringReader(localData), appendable);
}
return r;
}
}
Reported by PMD.
Line: 90
public void setUp() {
// precalculate some random strings of ascii characters.
StringBuilder sb = new StringBuilder();
Random random = new Random(0xdeadbeef); // for unpredictable but reproducible behavior
sb.ensureCapacity(size);
for (int k = 0; k < size; k++) {
// [9-127) includes all ascii non-control characters
sb.append((char) (random.nextInt(127 - 9) + 9));
}
Reported by PMD.
Line: 102
@Benchmark
public long timeCopy(int reps) throws IOException {
long r = 0;
final String localData = data;
final TargetSupplier localTarget = target;
final CopyStrategy localStrategy = strategy;
for (int i = 0; i < reps; i++) {
Appendable appendable = localTarget.get(localData.length());
r += localStrategy.copy(new StringReader(localData), appendable);
Reported by PMD.
Line: 103
public long timeCopy(int reps) throws IOException {
long r = 0;
final String localData = data;
final TargetSupplier localTarget = target;
final CopyStrategy localStrategy = strategy;
for (int i = 0; i < reps; i++) {
Appendable appendable = localTarget.get(localData.length());
r += localStrategy.copy(new StringReader(localData), appendable);
}
Reported by PMD.
Line: 104
long r = 0;
final String localData = data;
final TargetSupplier localTarget = target;
final CopyStrategy localStrategy = strategy;
for (int i = 0; i < reps; i++) {
Appendable appendable = localTarget.get(localData.length());
r += localStrategy.copy(new StringReader(localData), appendable);
}
return r;
Reported by PMD.
guava-tests/benchmark/com/google/common/base/EnumsBenchmark.java
10 issues
Line: 27
import java.util.List;
@SuppressWarnings("unused") // Nested enums used reflectively in setUp.
public class EnumsBenchmark {
@Param({"Small", "Medium", "Large"})
String enumSize;
@Param({"0.2", "0.8"})
Reported by PMD.
Line: 30
public class EnumsBenchmark {
@Param({"Small", "Medium", "Large"})
String enumSize;
@Param({"0.2", "0.8"})
float hitRate;
private Class<? extends Enum> enumType;
Reported by PMD.
Line: 33
String enumSize;
@Param({"0.2", "0.8"})
float hitRate;
private Class<? extends Enum> enumType;
private String[] sampleData;
@BeforeExperiment
Reported by PMD.
Line: 35
@Param({"0.2", "0.8"})
float hitRate;
private Class<? extends Enum> enumType;
private String[] sampleData;
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws ClassNotFoundException {
Reported by PMD.
Line: 36
float hitRate;
private Class<? extends Enum> enumType;
private String[] sampleData;
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws ClassNotFoundException {
Preconditions.checkArgument(hitRate >= 0 && hitRate <= 1, "hitRate must be in the range [0,1]");
Reported by PMD.
Line: 38
private Class<? extends Enum> enumType;
private String[] sampleData;
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws ClassNotFoundException {
Preconditions.checkArgument(hitRate >= 0 && hitRate <= 1, "hitRate must be in the range [0,1]");
enumType =
Reported by PMD.
Line: 64
sampleDataList.addAll(hits);
sampleDataList.addAll(misses);
Collections.shuffle(sampleDataList);
sampleData = sampleDataList.toArray(new String[sampleDataList.size()]);
}
@Benchmark
boolean getIfPresent(int repetitions) {
boolean retVal = false;
Reported by PMD.
Line: 71
boolean getIfPresent(int repetitions) {
boolean retVal = false;
for (int i = 0; i < repetitions; ++i) {
retVal &= Enums.getIfPresent(enumType, sampleData[i & 255]).isPresent();
}
return retVal;
}
private enum SmallEnum {
Reported by PMD.
Line: 185
X99
}
private enum LargeEnum {
X0,
X1,
X2,
X3,
X4,
Reported by PMD.
Line: 47
(Class<? extends Enum>)
Class.forName(EnumsBenchmark.class.getCanonicalName() + "$" + enumSize + "Enum");
Enum<?>[] allConstants = enumType.getEnumConstants();
List<String> hits = new ArrayList<>();
for (int i = 0; i < hitRate * 256 / 3; ++i) {
hits.add(allConstants[0].name());
hits.add(allConstants[allConstants.length / 2].name());
hits.add(allConstants[allConstants.length - 1].name());
Reported by PMD.
guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java
10 issues
Line: 32
* @author Nicholaus Shupe
*/
class CollectionBenchmarkSampleData {
private final boolean isUserTypeFast;
private final SpecialRandom random;
private final double hitRate;
private final int size;
private final Set<Element> valuesInSet;
Reported by PMD.
Line: 33
*/
class CollectionBenchmarkSampleData {
private final boolean isUserTypeFast;
private final SpecialRandom random;
private final double hitRate;
private final int size;
private final Set<Element> valuesInSet;
private final Element[] queries;
Reported by PMD.
Line: 34
class CollectionBenchmarkSampleData {
private final boolean isUserTypeFast;
private final SpecialRandom random;
private final double hitRate;
private final int size;
private final Set<Element> valuesInSet;
private final Element[] queries;
Reported by PMD.
Line: 35
private final boolean isUserTypeFast;
private final SpecialRandom random;
private final double hitRate;
private final int size;
private final Set<Element> valuesInSet;
private final Element[] queries;
CollectionBenchmarkSampleData(int size) {
Reported by PMD.
Line: 60
}
Element[] getQueries() {
return queries;
}
private Element[] createQueries(Set<Element> elementsInSet, int numQueries) {
List<Element> queryList = Lists.newArrayListWithCapacity(numQueries);
Reported by PMD.
Line: 79
}
List<Element> tmp = Lists.newArrayList(elementsInSet);
Collections.shuffle(tmp, random);
queryList.addAll(tmp.subList(0, extras));
}
// now add bad queries
while (queryList.size() < numQueries) {
Element candidate = newElement();
Reported by PMD.
Line: 83
}
// now add bad queries
while (queryList.size() < numQueries) {
Element candidate = newElement();
if (!elementsInSet.contains(candidate)) {
queryList.add(candidate);
}
}
Reported by PMD.
Line: 95
private Set<Element> createData() {
Set<Element> set = Sets.newHashSetWithExpectedSize(size);
while (set.size() < size) {
set.add(newElement());
}
return set;
}
Reported by PMD.
Line: 107
}
static class Element implements Comparable<Element> {
final int hash;
Element(int hash) {
this.hash = hash;
}
Reported by PMD.
Line: 66
private Element[] createQueries(Set<Element> elementsInSet, int numQueries) {
List<Element> queryList = Lists.newArrayListWithCapacity(numQueries);
int numGoodQueries = (int) (numQueries * hitRate + 0.5);
// add good queries
int size = elementsInSet.size();
if (size > 0) {
int minCopiesOfEachGoodQuery = numGoodQueries / size;
Reported by PMD.