The following issues were found
guava-tests/test/com/google/common/collect/CompactHashMapTest.java
44 issues
Line: 39
* @author Louis Wasserman
*/
public class CompactHashMapTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(
MapTestSuiteBuilder.using(
new TestStringMapGenerator() {
@Override
Reported by PMD.
Line: 68
@Override
protected Map<String, String> create(Entry<String, String>[] entries) {
CompactHashMap<String, String> map = CompactHashMap.create();
map.convertToHashFloodingResistantImplementation();
for (Entry<String, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
Reported by PMD.
Line: 89
return suite;
}
public void testTrimToSize() {
CompactHashMap<Integer, String> map = CompactHashMap.createWithExpectedSize(100);
for (int i = 0; i < 10; i++) {
map.put(i, Integer.toString(i));
}
map.trimToSize();
Reported by PMD.
Line: 89
return suite;
}
public void testTrimToSize() {
CompactHashMap<Integer, String> map = CompactHashMap.createWithExpectedSize(100);
for (int i = 0; i < 10; i++) {
map.put(i, Integer.toString(i));
}
map.trimToSize();
Reported by PMD.
Line: 94
for (int i = 0; i < 10; i++) {
map.put(i, Integer.toString(i));
}
map.trimToSize();
assertThat(map.entries).hasLength(10);
assertThat(map.keys).hasLength(10);
assertThat(map.values).hasLength(10);
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
Reported by PMD.
Line: 95
map.put(i, Integer.toString(i));
}
map.trimToSize();
assertThat(map.entries).hasLength(10);
assertThat(map.keys).hasLength(10);
assertThat(map.values).hasLength(10);
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
assertEquals(Integer.toString(i), map.get(i));
Reported by PMD.
Line: 96
}
map.trimToSize();
assertThat(map.entries).hasLength(10);
assertThat(map.keys).hasLength(10);
assertThat(map.values).hasLength(10);
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
assertEquals(Integer.toString(i), map.get(i));
}
Reported by PMD.
Line: 97
map.trimToSize();
assertThat(map.entries).hasLength(10);
assertThat(map.keys).hasLength(10);
assertThat(map.values).hasLength(10);
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
assertEquals(Integer.toString(i), map.get(i));
}
}
Reported by PMD.
Line: 98
assertThat(map.entries).hasLength(10);
assertThat(map.keys).hasLength(10);
assertThat(map.values).hasLength(10);
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
assertEquals(Integer.toString(i), map.get(i));
}
}
Reported by PMD.
Line: 98
assertThat(map.entries).hasLength(10);
assertThat(map.keys).hasLength(10);
assertThat(map.values).hasLength(10);
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
assertEquals(Integer.toString(i), map.get(i));
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/DerivedCollectionGenerators.java
44 issues
Line: 384
// nulls are usually out of bounds for a subset, so ban them altogether
for (Object o : elements) {
if (o == null) {
throw new NullPointerException();
}
}
// prepare extreme values to be filtered out of view
E firstExclusive = delegate.belowSamplesGreater();
Reported by PMD.
Line: 17
* limitations under the License.
*/
package com.google.common.collect.testing;
import static com.google.common.collect.testing.Helpers.castOrCopyToList;
import static com.google.common.collect.testing.Helpers.equal;
import static com.google.common.collect.testing.Helpers.mapEntry;
import static java.util.Collections.sort;
Reported by PMD.
Line: 46
public final class DerivedCollectionGenerators {
public static class MapEntrySetGenerator<K, V>
implements TestSetGenerator<Entry<K, V>>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
public MapEntrySetGenerator(
OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
}
Reported by PMD.
Line: 60
@Override
public Set<Entry<K, V>> create(Object... elements) {
return mapGenerator.create(elements).entrySet();
}
@Override
public Entry<K, V>[] createArray(int length) {
return mapGenerator.createArray(length);
Reported by PMD.
Line: 94
}
public static class MapKeySetGenerator<K, V> implements TestSetGenerator<K>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
private final SampleElements<K> samples;
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
final SampleElements<Entry<K, V>> mapSamples = this.mapGenerator.samples();
Reported by PMD.
Line: 95
public static class MapKeySetGenerator<K, V> implements TestSetGenerator<K>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
private final SampleElements<K> samples;
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
final SampleElements<Entry<K, V>> mapSamples = this.mapGenerator.samples();
this.samples =
Reported by PMD.
Line: 95
public static class MapKeySetGenerator<K, V> implements TestSetGenerator<K>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
private final SampleElements<K> samples;
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
final SampleElements<Entry<K, V>> mapSamples = this.mapGenerator.samples();
this.samples =
Reported by PMD.
Line: 129
entries.add(Helpers.mapEntry(keysArray[i++], entry.getValue()));
}
return mapGenerator.create(entries.toArray()).keySet();
}
@Override
public K[] createArray(int length) {
// TODO: with appropriate refactoring of OneSizeGenerator, we can perhaps
Reported by PMD.
Line: 164
public static class MapSortedKeySetGenerator<K, V> extends MapKeySetGenerator<K, V>
implements TestSortedSetGenerator<K>, DerivedGenerator {
private final TestSortedMapGenerator<K, V> delegate;
public MapSortedKeySetGenerator(
OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
super(mapGenerator);
this.delegate = (TestSortedMapGenerator<K, V>) mapGenerator.getInnerGenerator();
Reported by PMD.
Line: 179
@Override
public K belowSamplesLesser() {
return delegate.belowSamplesLesser().getKey();
}
@Override
public K belowSamplesGreater() {
return delegate.belowSamplesGreater().getKey();
Reported by PMD.
android/guava-tests/test/com/google/common/util/concurrent/FuturesGetCheckedInputs.java
44 issues
Line: 115
static final class ExceptionWithGoodAndBadConstructor extends Exception {
public ExceptionWithGoodAndBadConstructor(String message, Throwable cause) {
throw new RuntimeException("bad constructor");
}
public ExceptionWithGoodAndBadConstructor(Throwable cause) {
super(cause);
}
Reported by PMD.
Line: 125
static final class ExceptionWithBadConstructor extends Exception {
public ExceptionWithBadConstructor(String message, Throwable cause) {
throw new RuntimeException("bad constructor");
}
}
static final class OtherThrowable extends Throwable {}
Reported by PMD.
Line: 43
UncheckedThrowingFuture.throwingRuntimeException(RUNTIME_EXCEPTION);
static final Future<String> ERROR_FUTURE = UncheckedThrowingFuture.throwingError(ERROR);
public static final class TwoArgConstructorException extends Exception {
public TwoArgConstructorException(String message, Throwable cause) {
super(message, cause);
}
}
Reported by PMD.
Line: 49
}
}
public static final class TwoArgConstructorRuntimeException extends RuntimeException {
public TwoArgConstructorRuntimeException(String message, Throwable cause) {
super(message, cause);
}
}
Reported by PMD.
Line: 55
}
}
public static final class ExceptionWithPrivateConstructor extends Exception {
private ExceptionWithPrivateConstructor(String message, Throwable cause) {
super(message, cause);
}
}
Reported by PMD.
Line: 62
}
@SuppressWarnings("unused") // we're testing that they're not used
public static final class ExceptionWithSomePrivateConstructors extends Exception {
private ExceptionWithSomePrivateConstructors(String a) {}
private ExceptionWithSomePrivateConstructors(String a, String b) {}
public ExceptionWithSomePrivateConstructors(String a, String b, String c) {}
Reported by PMD.
Line: 75
String a, String b, String c, String d, String e) {}
}
public static final class ExceptionWithManyConstructors extends Exception {
boolean usedExpectedConstructor;
public ExceptionWithManyConstructors() {}
public ExceptionWithManyConstructors(Integer i) {}
Reported by PMD.
Line: 76
}
public static final class ExceptionWithManyConstructors extends Exception {
boolean usedExpectedConstructor;
public ExceptionWithManyConstructors() {}
public ExceptionWithManyConstructors(Integer i) {}
Reported by PMD.
Line: 80
public ExceptionWithManyConstructors() {}
public ExceptionWithManyConstructors(Integer i) {}
public ExceptionWithManyConstructors(Throwable a) {}
public ExceptionWithManyConstructors(Throwable a, Throwable b) {}
Reported by PMD.
Line: 82
public ExceptionWithManyConstructors(Integer i) {}
public ExceptionWithManyConstructors(Throwable a) {}
public ExceptionWithManyConstructors(Throwable a, Throwable b) {}
public ExceptionWithManyConstructors(String s, Throwable b) {
usedExpectedConstructor = true;
Reported by PMD.
android/guava/src/com/google/common/reflect/Types.java
44 issues
Line: 614
* Android don't *seem* to mind, but there might be edge cases of which we're unaware.)
*/
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
},
Reported by PMD.
Line: 616
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
},
JAVA9 {
@Override
Reported by PMD.
Line: 15
* the License.
*/
package com.google.common.reflect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static java.util.Objects.requireNonNull;
Reported by PMD.
Line: 57
* @author Ben Yu
*/
@ElementTypesAreNonnullByDefault
final class Types {
/** Class#toString without the "class " and "interface " prefixes */
private static final Function<Type, String> TYPE_NAME =
new Function<Type, String>() {
@Override
Reported by PMD.
Line: 64
new Function<Type, String>() {
@Override
public String apply(Type from) {
return JavaVersion.CURRENT.typeName(from);
}
};
private static final Joiner COMMA_JOINER = Joiner.on(", ").useForNull("null");
Reported by PMD.
Line: 74
static Type newArrayType(Type componentType) {
if (componentType instanceof WildcardType) {
WildcardType wildcard = (WildcardType) componentType;
Type[] lowerBounds = wildcard.getLowerBounds();
checkArgument(lowerBounds.length <= 1, "Wildcard cannot have more than one lower bounds.");
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
Reported by PMD.
Line: 76
WildcardType wildcard = (WildcardType) componentType;
Type[] lowerBounds = wildcard.getLowerBounds();
checkArgument(lowerBounds.length <= 1, "Wildcard cannot have more than one lower bounds.");
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
checkArgument(upperBounds.length == 1, "Wildcard should have only one upper bound.");
return subtypeOf(newArrayType(upperBounds[0]));
Reported by PMD.
Line: 79
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
checkArgument(upperBounds.length == 1, "Wildcard should have only one upper bound.");
return subtypeOf(newArrayType(upperBounds[0]));
}
}
return JavaVersion.CURRENT.newArrayType(componentType);
Reported by PMD.
Line: 84
return subtypeOf(newArrayType(upperBounds[0]));
}
}
return JavaVersion.CURRENT.newArrayType(componentType);
}
/**
* Returns a type where {@code rawType} is parameterized by {@code arguments} and is owned by
* {@code ownerType}.
Reported by PMD.
Line: 105
/** Returns a type where {@code rawType} is parameterized by {@code arguments}. */
static ParameterizedType newParameterizedType(Class<?> rawType, Type... arguments) {
return new ParameterizedTypeImpl(
ClassOwnership.JVM_BEHAVIOR.getOwnerType(rawType), rawType, arguments);
}
/** Decides what owner type to use for constructing {@link ParameterizedType} from a raw class. */
private enum ClassOwnership {
OWNED_BY_ENCLOSING_CLASS {
Reported by PMD.
guava/src/com/google/common/reflect/Types.java
44 issues
Line: 614
* Android don't *seem* to mind, but there might be edge cases of which we're unaware.)
*/
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
},
Reported by PMD.
Line: 616
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
},
JAVA9 {
@Override
Reported by PMD.
Line: 15
* the License.
*/
package com.google.common.reflect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static java.util.Objects.requireNonNull;
Reported by PMD.
Line: 57
* @author Ben Yu
*/
@ElementTypesAreNonnullByDefault
final class Types {
/** Class#toString without the "class " and "interface " prefixes */
private static final Function<Type, String> TYPE_NAME =
new Function<Type, String>() {
@Override
Reported by PMD.
Line: 64
new Function<Type, String>() {
@Override
public String apply(Type from) {
return JavaVersion.CURRENT.typeName(from);
}
};
private static final Joiner COMMA_JOINER = Joiner.on(", ").useForNull("null");
Reported by PMD.
Line: 74
static Type newArrayType(Type componentType) {
if (componentType instanceof WildcardType) {
WildcardType wildcard = (WildcardType) componentType;
Type[] lowerBounds = wildcard.getLowerBounds();
checkArgument(lowerBounds.length <= 1, "Wildcard cannot have more than one lower bounds.");
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
Reported by PMD.
Line: 76
WildcardType wildcard = (WildcardType) componentType;
Type[] lowerBounds = wildcard.getLowerBounds();
checkArgument(lowerBounds.length <= 1, "Wildcard cannot have more than one lower bounds.");
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
checkArgument(upperBounds.length == 1, "Wildcard should have only one upper bound.");
return subtypeOf(newArrayType(upperBounds[0]));
Reported by PMD.
Line: 79
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
checkArgument(upperBounds.length == 1, "Wildcard should have only one upper bound.");
return subtypeOf(newArrayType(upperBounds[0]));
}
}
return JavaVersion.CURRENT.newArrayType(componentType);
Reported by PMD.
Line: 84
return subtypeOf(newArrayType(upperBounds[0]));
}
}
return JavaVersion.CURRENT.newArrayType(componentType);
}
/**
* Returns a type where {@code rawType} is parameterized by {@code arguments} and is owned by
* {@code ownerType}.
Reported by PMD.
Line: 105
/** Returns a type where {@code rawType} is parameterized by {@code arguments}. */
static ParameterizedType newParameterizedType(Class<?> rawType, Type... arguments) {
return new ParameterizedTypeImpl(
ClassOwnership.JVM_BEHAVIOR.getOwnerType(rawType), rawType, arguments);
}
/** Decides what owner type to use for constructing {@link ParameterizedType} from a raw class. */
private enum ClassOwnership {
OWNED_BY_ENCLOSING_CLASS {
Reported by PMD.
guava-tests/test/com/google/common/util/concurrent/FuturesGetCheckedInputs.java
44 issues
Line: 115
static final class ExceptionWithGoodAndBadConstructor extends Exception {
public ExceptionWithGoodAndBadConstructor(String message, Throwable cause) {
throw new RuntimeException("bad constructor");
}
public ExceptionWithGoodAndBadConstructor(Throwable cause) {
super(cause);
}
Reported by PMD.
Line: 125
static final class ExceptionWithBadConstructor extends Exception {
public ExceptionWithBadConstructor(String message, Throwable cause) {
throw new RuntimeException("bad constructor");
}
}
static final class OtherThrowable extends Throwable {}
Reported by PMD.
Line: 43
UncheckedThrowingFuture.throwingRuntimeException(RUNTIME_EXCEPTION);
static final Future<String> ERROR_FUTURE = UncheckedThrowingFuture.throwingError(ERROR);
public static final class TwoArgConstructorException extends Exception {
public TwoArgConstructorException(String message, Throwable cause) {
super(message, cause);
}
}
Reported by PMD.
Line: 49
}
}
public static final class TwoArgConstructorRuntimeException extends RuntimeException {
public TwoArgConstructorRuntimeException(String message, Throwable cause) {
super(message, cause);
}
}
Reported by PMD.
Line: 55
}
}
public static final class ExceptionWithPrivateConstructor extends Exception {
private ExceptionWithPrivateConstructor(String message, Throwable cause) {
super(message, cause);
}
}
Reported by PMD.
Line: 62
}
@SuppressWarnings("unused") // we're testing that they're not used
public static final class ExceptionWithSomePrivateConstructors extends Exception {
private ExceptionWithSomePrivateConstructors(String a) {}
private ExceptionWithSomePrivateConstructors(String a, String b) {}
public ExceptionWithSomePrivateConstructors(String a, String b, String c) {}
Reported by PMD.
Line: 75
String a, String b, String c, String d, String e) {}
}
public static final class ExceptionWithManyConstructors extends Exception {
boolean usedExpectedConstructor;
public ExceptionWithManyConstructors() {}
public ExceptionWithManyConstructors(Integer i) {}
Reported by PMD.
Line: 76
}
public static final class ExceptionWithManyConstructors extends Exception {
boolean usedExpectedConstructor;
public ExceptionWithManyConstructors() {}
public ExceptionWithManyConstructors(Integer i) {}
Reported by PMD.
Line: 80
public ExceptionWithManyConstructors() {}
public ExceptionWithManyConstructors(Integer i) {}
public ExceptionWithManyConstructors(Throwable a) {}
public ExceptionWithManyConstructors(Throwable a, Throwable b) {}
Reported by PMD.
Line: 82
public ExceptionWithManyConstructors(Integer i) {}
public ExceptionWithManyConstructors(Throwable a) {}
public ExceptionWithManyConstructors(Throwable a, Throwable b) {}
public ExceptionWithManyConstructors(String s, Throwable b) {
usedExpectedConstructor = true;
Reported by PMD.
guava/src/com/google/common/util/concurrent/MoreExecutors.java
44 issues
Line: 883
* don't *seem* to mind, but there might be edge cases of which we're unaware.)
*/
} catch (IllegalAccessException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (InvocationTargetException e) {
Reported by PMD.
Line: 885
} catch (IllegalAccessException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (InvocationTargetException e) {
throw Throwables.propagate(e.getCause());
}
Reported by PMD.
Line: 887
} catch (ClassNotFoundException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
} catch (InvocationTargetException e) {
throw Throwables.propagate(e.getCause());
}
}
Reported by PMD.
Line: 15
* the License.
*/
package com.google.common.util.concurrent;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Internal.toNanosSaturated;
Reported by PMD.
Line: 67
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class MoreExecutors {
private MoreExecutors() {}
/**
* Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application
* is complete. It does so by using daemon threads and adding a shutdown hook to wait for their
Reported by PMD.
Line: 67
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class MoreExecutors {
private MoreExecutors() {}
/**
* Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application
* is complete. It does so by using daemon threads and adding a shutdown hook to wait for their
Reported by PMD.
Line: 67
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class MoreExecutors {
private MoreExecutors() {}
/**
* Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application
* is complete. It does so by using daemon threads and adding a shutdown hook to wait for their
Reported by PMD.
Line: 67
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class MoreExecutors {
private MoreExecutors() {}
/**
* Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application
* is complete. It does so by using daemon threads and adding a shutdown hook to wait for their
Reported by PMD.
Line: 67
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class MoreExecutors {
private MoreExecutors() {}
/**
* Converts the given ThreadPoolExecutor into an ExecutorService that exits when the application
* is complete. It does so by using daemon threads and adding a shutdown hook to wait for their
Reported by PMD.
Line: 106
*/
@Beta
@GwtIncompatible // TODO
@SuppressWarnings("GoodTime") // should accept a java.time.Duration
public static ExecutorService getExitingExecutorService(
ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
return new Application().getExitingExecutorService(executor, terminationTimeout, timeUnit);
}
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/DerivedCollectionGenerators.java
44 issues
Line: 384
// nulls are usually out of bounds for a subset, so ban them altogether
for (Object o : elements) {
if (o == null) {
throw new NullPointerException();
}
}
// prepare extreme values to be filtered out of view
E firstExclusive = delegate.belowSamplesGreater();
Reported by PMD.
Line: 17
* limitations under the License.
*/
package com.google.common.collect.testing;
import static com.google.common.collect.testing.Helpers.castOrCopyToList;
import static com.google.common.collect.testing.Helpers.equal;
import static com.google.common.collect.testing.Helpers.mapEntry;
import static java.util.Collections.sort;
Reported by PMD.
Line: 46
public final class DerivedCollectionGenerators {
public static class MapEntrySetGenerator<K, V>
implements TestSetGenerator<Entry<K, V>>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
public MapEntrySetGenerator(
OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
}
Reported by PMD.
Line: 60
@Override
public Set<Entry<K, V>> create(Object... elements) {
return mapGenerator.create(elements).entrySet();
}
@Override
public Entry<K, V>[] createArray(int length) {
return mapGenerator.createArray(length);
Reported by PMD.
Line: 94
}
public static class MapKeySetGenerator<K, V> implements TestSetGenerator<K>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
private final SampleElements<K> samples;
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
final SampleElements<Entry<K, V>> mapSamples = this.mapGenerator.samples();
Reported by PMD.
Line: 95
public static class MapKeySetGenerator<K, V> implements TestSetGenerator<K>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
private final SampleElements<K> samples;
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
final SampleElements<Entry<K, V>> mapSamples = this.mapGenerator.samples();
this.samples =
Reported by PMD.
Line: 95
public static class MapKeySetGenerator<K, V> implements TestSetGenerator<K>, DerivedGenerator {
private final OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator;
private final SampleElements<K> samples;
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
final SampleElements<Entry<K, V>> mapSamples = this.mapGenerator.samples();
this.samples =
Reported by PMD.
Line: 129
entries.add(Helpers.mapEntry(keysArray[i++], entry.getValue()));
}
return mapGenerator.create(entries.toArray()).keySet();
}
@Override
public K[] createArray(int length) {
// TODO: with appropriate refactoring of OneSizeGenerator, we can perhaps
Reported by PMD.
Line: 164
public static class MapSortedKeySetGenerator<K, V> extends MapKeySetGenerator<K, V>
implements TestSortedSetGenerator<K>, DerivedGenerator {
private final TestSortedMapGenerator<K, V> delegate;
public MapSortedKeySetGenerator(
OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>> mapGenerator) {
super(mapGenerator);
this.delegate = (TestSortedMapGenerator<K, V>) mapGenerator.getInnerGenerator();
Reported by PMD.
Line: 179
@Override
public K belowSamplesLesser() {
return delegate.belowSamplesLesser().getKey();
}
@Override
public K belowSamplesGreater() {
return delegate.belowSamplesGreater().getKey();
Reported by PMD.
android/guava-tests/test/com/google/common/collect/SynchronizedQueueTest.java
44 issues
Line: 41
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public final Object mutex = new Integer(1); // something Serializable
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
return delegate.offer(o);
Reported by PMD.
Line: 35
protected Queue<String> create() {
TestQueue<String> inner = new TestQueue<>();
Queue<String> outer = Synchronized.queue(inner, inner.mutex);
outer.add("foo"); // necessary because we try to remove elements later on
return outer;
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
Reported by PMD.
Line: 35
protected Queue<String> create() {
TestQueue<String> inner = new TestQueue<>();
Queue<String> outer = Synchronized.queue(inner, inner.mutex);
outer.add("foo"); // necessary because we try to remove elements later on
return outer;
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
Reported by PMD.
Line: 39
return outer;
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public final Object mutex = new Integer(1); // something Serializable
@Override
public boolean offer(E o) {
Reported by PMD.
Line: 40
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public final Object mutex = new Integer(1); // something Serializable
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
Reported by PMD.
Line: 41
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public final Object mutex = new Integer(1); // something Serializable
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
return delegate.offer(o);
Reported by PMD.
Line: 45
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
return delegate.offer(o);
}
@Override
public E poll() {
Reported by PMD.
Line: 51
@Override
public E poll() {
assertTrue(Thread.holdsLock(mutex));
return delegate.poll();
}
@Override
public E remove() {
Reported by PMD.
Line: 57
@Override
public E remove() {
assertTrue(Thread.holdsLock(mutex));
return delegate.remove();
}
@Override
public boolean remove(Object object) {
Reported by PMD.
Line: 63
@Override
public boolean remove(Object object) {
assertTrue(Thread.holdsLock(mutex));
return delegate.remove(object);
}
@Override
public E peek() {
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRetainAllTester.java
43 issues
Line: 44
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
/** A collection of elements to retain, along with a description for use in failure messages. */
private class Target {
private final Collection<E> toRetain;
private final String description;
Reported by PMD.
Line: 48
/** A collection of elements to retain, along with a description for use in failure messages. */
private class Target {
private final Collection<E> toRetain;
private final String description;
private Target(Collection<E> toRetain, String description) {
this.toRetain = toRetain;
this.description = description;
Reported by PMD.
Line: 49
/** A collection of elements to retain, along with a description for use in failure messages. */
private class Target {
private final Collection<E> toRetain;
private final String description;
private Target(Collection<E> toRetain, String description) {
this.toRetain = toRetain;
this.description = description;
}
Reported by PMD.
Line: 62
}
}
private Target empty;
private Target disjoint;
private Target superset;
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
Reported by PMD.
Line: 63
}
private Target empty;
private Target disjoint;
private Target superset;
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
private Target containsDuplicates;
Reported by PMD.
Line: 64
private Target empty;
private Target disjoint;
private Target superset;
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
private Target containsDuplicates;
private Target nullSingleton;
Reported by PMD.
Line: 65
private Target empty;
private Target disjoint;
private Target superset;
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
private Target containsDuplicates;
private Target nullSingleton;
Reported by PMD.
Line: 66
private Target disjoint;
private Target superset;
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
private Target containsDuplicates;
private Target nullSingleton;
@Override
Reported by PMD.
Line: 67
private Target superset;
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
private Target containsDuplicates;
private Target nullSingleton;
@Override
public void setUp() throws Exception {
Reported by PMD.
Line: 68
private Target nonEmptyProperSubset;
private Target sameElements;
private Target partialOverlap;
private Target containsDuplicates;
private Target nullSingleton;
@Override
public void setUp() throws Exception {
super.setUp();
Reported by PMD.