The following issues were found
guava-tests/test/com/google/common/collect/TablesTransformValuesTest.java
11 issues
Line: 53
}
// Null support depends on the underlying table and function.
@GwtIncompatible // NullPointerTester
@Override
public void testNullPointerInstance() {}
// put() and putAll() aren't supported.
@Override
Reported by PMD.
Line: 58
public void testNullPointerInstance() {}
// put() and putAll() aren't supported.
@Override
public void testPut() {
try {
table.put("foo", 1, 'a');
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
Reported by PMD.
Line: 61
@Override
public void testPut() {
try {
table.put("foo", 1, 'a');
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
assertSize(0);
}
Reported by PMD.
Line: 68
assertSize(0);
}
@Override
public void testPutAllTable() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
Reported by PMD.
Line: 69
}
@Override
public void testPutAllTable() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
other.put("cat", 2, 'f');
Reported by PMD.
Line: 72
public void testPutAllTable() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
other.put("cat", 2, 'f');
try {
table.putAll(other);
fail("Expected UnsupportedOperationException");
Reported by PMD.
Line: 73
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
other.put("cat", 2, 'f');
try {
table.putAll(other);
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
Reported by PMD.
Line: 74
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
other.put("cat", 2, 'f');
try {
table.putAll(other);
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
Reported by PMD.
Line: 86
assertSize(3);
}
@Override
public void testPutNull() {}
@Override
public void testPutNullReplace() {}
Reported by PMD.
Line: 89
@Override
public void testPutNull() {}
@Override
public void testPutNullReplace() {}
@Override
public void testRowClearAndPut() {}
}
Reported by PMD.
guava-tests/test/com/google/common/collect/SortedIterablesTest.java
11 issues
Line: 28
*/
@GwtCompatible
public class SortedIterablesTest extends TestCase {
public void testSameComparator() {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet()));
// Before JDK6 (including under GWT), the TreeMap keySet is a plain Set.
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
Reported by PMD.
Line: 28
*/
@GwtCompatible
public class SortedIterablesTest extends TestCase {
public void testSameComparator() {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet()));
// Before JDK6 (including under GWT), the TreeMap keySet is a plain Set.
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
Reported by PMD.
Line: 29
@GwtCompatible
public class SortedIterablesTest extends TestCase {
public void testSameComparator() {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet()));
// Before JDK6 (including under GWT), the TreeMap keySet is a plain Set.
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
assertTrue(
Reported by PMD.
Line: 31
public void testSameComparator() {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet()));
// Before JDK6 (including under GWT), the TreeMap keySet is a plain Set.
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
assertTrue(
SortedIterables.hasSameComparator(
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
Reported by PMD.
Line: 32
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet()));
// Before JDK6 (including under GWT), the TreeMap keySet is a plain Set.
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
assertTrue(
SortedIterables.hasSameComparator(
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
}
Reported by PMD.
Line: 32
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Sets.newTreeSet()));
// Before JDK6 (including under GWT), the TreeMap keySet is a plain Set.
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
assertTrue(
SortedIterables.hasSameComparator(
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
}
Reported by PMD.
Line: 34
if (Maps.newTreeMap().keySet() instanceof SortedSet) {
assertTrue(SortedIterables.hasSameComparator(Ordering.natural(), Maps.newTreeMap().keySet()));
}
assertTrue(
SortedIterables.hasSameComparator(
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
}
public void testComparator() {
Reported by PMD.
Line: 36
}
assertTrue(
SortedIterables.hasSameComparator(
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
}
public void testComparator() {
assertEquals(Ordering.natural(), SortedIterables.comparator(Sets.newTreeSet()));
}
Reported by PMD.
Line: 36
}
assertTrue(
SortedIterables.hasSameComparator(
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
}
public void testComparator() {
assertEquals(Ordering.natural(), SortedIterables.comparator(Sets.newTreeSet()));
}
Reported by PMD.
Line: 39
Ordering.natural().reverse(), Sets.newTreeSet(Ordering.natural().reverse())));
}
public void testComparator() {
assertEquals(Ordering.natural(), SortedIterables.comparator(Sets.newTreeSet()));
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionSpliteratorTester.java
11 issues
Line: 46
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionSpliteratorTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(absent = KNOWN_ORDER)
public void testSpliteratorUnknownOrder() {
synchronized (collection) {
SpliteratorTester.of(collection::spliterator).expect(getSampleElements());
}
}
Reported by PMD.
Line: 49
@CollectionFeature.Require(absent = KNOWN_ORDER)
public void testSpliteratorUnknownOrder() {
synchronized (collection) {
SpliteratorTester.of(collection::spliterator).expect(getSampleElements());
}
}
@CollectionFeature.Require(KNOWN_ORDER)
public void testSpliteratorKnownOrder() {
Reported by PMD.
Line: 53
}
}
@CollectionFeature.Require(KNOWN_ORDER)
public void testSpliteratorKnownOrder() {
synchronized (collection) {
SpliteratorTester.of(collection::spliterator).expect(getOrderedElements()).inOrder();
}
}
Reported by PMD.
Line: 56
@CollectionFeature.Require(KNOWN_ORDER)
public void testSpliteratorKnownOrder() {
synchronized (collection) {
SpliteratorTester.of(collection::spliterator).expect(getOrderedElements()).inOrder();
}
}
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 56
@CollectionFeature.Require(KNOWN_ORDER)
public void testSpliteratorKnownOrder() {
synchronized (collection) {
SpliteratorTester.of(collection::spliterator).expect(getOrderedElements()).inOrder();
}
}
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 60
}
}
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testSpliteratorNullable() {
initCollectionWithNullElement();
synchronized (collection) { // for Collections.synchronized
assertFalse(collection.spliterator().hasCharacteristics(Spliterator.NONNULL));
Reported by PMD.
Line: 65
public void testSpliteratorNullable() {
initCollectionWithNullElement();
synchronized (collection) { // for Collections.synchronized
assertFalse(collection.spliterator().hasCharacteristics(Spliterator.NONNULL));
}
}
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSpliteratorNotImmutable_CollectionAllowsAdd() {
Reported by PMD.
Line: 69
}
}
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSpliteratorNotImmutable_CollectionAllowsAdd() {
// If add is supported, verify that IMMUTABLE is not reported.
synchronized (collection) { // for Collections.synchronized
assertFalse(collection.spliterator().hasCharacteristics(Spliterator.IMMUTABLE));
}
Reported by PMD.
Line: 73
public void testSpliteratorNotImmutable_CollectionAllowsAdd() {
// If add is supported, verify that IMMUTABLE is not reported.
synchronized (collection) { // for Collections.synchronized
assertFalse(collection.spliterator().hasCharacteristics(Spliterator.IMMUTABLE));
}
}
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testSpliteratorNotImmutable_CollectionAllowsRemove() {
Reported by PMD.
Line: 77
}
}
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testSpliteratorNotImmutable_CollectionAllowsRemove() {
// If remove is supported, verify that IMMUTABLE is not reported.
synchronized (collection) { // for Collections.synchronized
assertFalse(collection.spliterator().hasCharacteristics(Spliterator.IMMUTABLE));
}
Reported by PMD.
guava-tests/test/com/google/common/primitives/ByteArrayAsListTest.java
11 issues
Line: 41
* @author Kevin Bourrillion
*/
@GwtCompatible(emulated = true)
public class ByteArrayAsListTest extends TestCase {
private static List<Byte> asList(Byte[] values) {
byte[] temp = new byte[values.length];
for (int i = 0; i < values.length; i++) {
temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).
Reported by PMD.
Line: 51
return Bytes.asList(temp);
}
@GwtIncompatible // suite
public static Test suite() {
List<ListTestSuiteBuilder<Byte>> builders =
ImmutableList.of(
ListTestSuiteBuilder.using(new BytesAsListGenerator()).named("Bytes.asList"),
ListTestSuiteBuilder.using(new BytesAsListHeadSubListGenerator())
Reported by PMD.
Line: 66
TestSuite suite = new TestSuite();
for (ListTestSuiteBuilder<Byte> builder : builders) {
suite.addTest(
builder
.withFeatures(
CollectionSize.ONE,
CollectionSize.SEVERAL,
CollectionFeature.RESTRICTS_ELEMENTS,
ListFeature.SUPPORTS_SET)
Reported by PMD.
Line: 92
protected List<Byte> create(Byte[] elements) {
Byte[] suffix = {Byte.MIN_VALUE, Byte.MAX_VALUE};
Byte[] all = concat(elements, suffix);
return asList(all).subList(0, elements.length);
}
}
public static final class BytesAsListTailSubListGenerator extends TestByteListGenerator {
@Override
Reported by PMD.
Line: 101
protected List<Byte> create(Byte[] elements) {
Byte[] prefix = {(byte) 86, (byte) 99};
Byte[] all = concat(prefix, elements);
return asList(all).subList(2, elements.length + 2);
}
}
public static final class BytesAsListMiddleSubListGenerator extends TestByteListGenerator {
@Override
Reported by PMD.
Line: 111
Byte[] prefix = {Byte.MIN_VALUE, Byte.MAX_VALUE};
Byte[] suffix = {(byte) 86, (byte) 99};
Byte[] all = concat(concat(prefix, elements), suffix);
return asList(all).subList(2, elements.length + 2);
}
}
private static Byte[] concat(Byte[] left, Byte[] right) {
Byte[] result = new Byte[left.length + right.length];
Reported by PMD.
Line: 44
public class ByteArrayAsListTest extends TestCase {
private static List<Byte> asList(Byte[] values) {
byte[] temp = new byte[values.length];
for (int i = 0; i < values.length; i++) {
temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).
}
return Bytes.asList(temp);
}
Reported by PMD.
Line: 46
private static List<Byte> asList(Byte[] values) {
byte[] temp = new byte[values.length];
for (int i = 0; i < values.length; i++) {
temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).
}
return Bytes.asList(temp);
}
@GwtIncompatible // suite
Reported by PMD.
Line: 130
@Override
public List<Byte> create(Object... elements) {
Byte[] array = new Byte[elements.length];
int i = 0;
for (Object e : elements) {
array[i++] = (Byte) e;
}
return create(array);
Reported by PMD.
Line: 131
@Override
public List<Byte> create(Object... elements) {
Byte[] array = new Byte[elements.length];
int i = 0;
for (Object e : elements) {
array[i++] = (Byte) e;
}
return create(array);
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutTester.java
11 issues
Line: 42
public class SetMultimapPutTester<K, V> extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {
// Tests for non-duplicate values are in MultimapPutTester
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutDuplicateValuePreservesSize() {
assertFalse(multimap().put(k0(), v0()));
assertEquals(getNumElements(), multimap().size());
}
Reported by PMD.
Line: 44
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutDuplicateValuePreservesSize() {
assertFalse(multimap().put(k0(), v0()));
assertEquals(getNumElements(), multimap().size());
}
@MapFeature.Require(SUPPORTS_PUT)
Reported by PMD.
Line: 45
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutDuplicateValuePreservesSize() {
assertFalse(multimap().put(k0(), v0()));
assertEquals(getNumElements(), multimap().size());
}
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
Reported by PMD.
Line: 46
@CollectionSize.Require(absent = ZERO)
public void testPutDuplicateValuePreservesSize() {
assertFalse(multimap().put(k0(), v0()));
assertEquals(getNumElements(), multimap().size());
}
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
List<Entry<K, V>> entries = copyToList(multimap().entries());
Reported by PMD.
Line: 49
assertEquals(getNumElements(), multimap().size());
}
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
List<Entry<K, V>> entries = copyToList(multimap().entries());
for (Entry<K, V> entry : entries) {
resetContainer();
Reported by PMD.
Line: 50
}
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
List<Entry<K, V>> entries = copyToList(multimap().entries());
for (Entry<K, V> entry : entries) {
resetContainer();
K k = entry.getKey();
Reported by PMD.
Line: 51
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
List<Entry<K, V>> entries = copyToList(multimap().entries());
for (Entry<K, V> entry : entries) {
resetContainer();
K k = entry.getKey();
V v = entry.getValue();
Reported by PMD.
Line: 58
K k = entry.getKey();
V v = entry.getValue();
Set<V> values = multimap().get(k);
Set<V> expectedValues = copyToSet(values);
assertFalse(multimap().put(k, v));
assertEquals(expectedValues, values);
assertGet(k, expectedValues);
Reported by PMD.
Line: 61
Set<V> values = multimap().get(k);
Set<V> expectedValues = copyToSet(values);
assertFalse(multimap().put(k, v));
assertEquals(expectedValues, values);
assertGet(k, expectedValues);
}
}
Reported by PMD.
Line: 67
}
}
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testPutDuplicateValue_null() {
initMultimapWithNullValue();
assertFalse(multimap().put(getKeyForNullValue(), null));
expectContents(createArrayWithNullValue());
Reported by PMD.
guava-tests/benchmark/com/google/common/collect/MultipleSetContainsBenchmark.java
11 issues
Line: 29
public class MultipleSetContainsBenchmark {
@Param({"0.0", "0.1", "0.7", "1.0"})
double emptySetProportion;
@Param({"0.0", "0.1", "0.7", "1.0"})
double singletonSetProportion;
@Param({"0.2", "0.8"})
Reported by PMD.
Line: 32
double emptySetProportion;
@Param({"0.0", "0.1", "0.7", "1.0"})
double singletonSetProportion;
@Param({"0.2", "0.8"})
double hitRate;
static final Object PRESENT = new Object();
Reported by PMD.
Line: 35
double singletonSetProportion;
@Param({"0.2", "0.8"})
double hitRate;
static final Object PRESENT = new Object();
static final Object ABSENT = new Object();
@SuppressWarnings("unchecked")
Reported by PMD.
Line: 41
static final Object ABSENT = new Object();
@SuppressWarnings("unchecked")
private final ImmutableSet<Object>[] sets = new ImmutableSet[0x1000];
private final Object[] queries = new Object[0x1000];
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 43
@SuppressWarnings("unchecked")
private final ImmutableSet<Object>[] sets = new ImmutableSet[0x1000];
private final Object[] queries = new Object[0x1000];
@BeforeExperiment
void setUp() {
if (emptySetProportion + singletonSetProportion > 1.01) {
throw new SkipThisScenarioException();
Reported by PMD.
Line: 45
private final Object[] queries = new Object[0x1000];
@BeforeExperiment
void setUp() {
if (emptySetProportion + singletonSetProportion > 1.01) {
throw new SkipThisScenarioException();
}
Reported by PMD.
Line: 47
@BeforeExperiment
void setUp() {
if (emptySetProportion + singletonSetProportion > 1.01) {
throw new SkipThisScenarioException();
}
Random rng = new Random();
for (int i = 0; i < 0x1000; i++) {
Reported by PMD.
Line: 59
} else if (setSize < emptySetProportion + singletonSetProportion) {
sets[i] = ImmutableSet.of(PRESENT);
} else {
sets[i] = ImmutableSet.of(PRESENT, new Object());
}
if (rng.nextDouble() < hitRate) {
queries[i] = PRESENT;
} else {
Reported by PMD.
Line: 51
throw new SkipThisScenarioException();
}
Random rng = new Random();
for (int i = 0; i < 0x1000; i++) {
double setSize = rng.nextDouble();
if (setSize < emptySetProportion) {
sets[i] = ImmutableSet.of();
} else if (setSize < emptySetProportion + singletonSetProportion) {
Reported by PMD.
Line: 72
@Benchmark
public boolean contains(int reps) {
ImmutableSet<Object>[] sets = this.sets;
Object[] queries = this.queries;
boolean result = false;
for (int i = 0; i < reps; i++) {
int j = i & 0xFFF;
result ^= sets[j].contains(queries[j]);
Reported by PMD.
guava-tests/benchmark/com/google/common/cache/LoadingCacheSingleThreadBenchmark.java
11 issues
Line: 112
double hit = req - misses.get();
// Currently, this is going into /dev/null, but I'll fix that
System.out.println("hit rate: " + hit / req);
}
// for proper distributions later:
// import JSci.maths.statistics.ProbabilityDistribution;
// int key = (int) dist.inverse(random.nextDouble());
Reported by PMD.
Line: 34
*/
public class LoadingCacheSingleThreadBenchmark {
@Param({"1000", "2000"})
int maximumSize;
@Param("5000")
int distinctKeys;
@Param("4")
Reported by PMD.
Line: 37
int maximumSize;
@Param("5000")
int distinctKeys;
@Param("4")
int segments;
// 1 means uniform likelihood of keys; higher means some keys are more popular
Reported by PMD.
Line: 40
int distinctKeys;
@Param("4")
int segments;
// 1 means uniform likelihood of keys; higher means some keys are more popular
// tweak this to control hit rate
@Param("2.5")
double concentration;
Reported by PMD.
Line: 45
// 1 means uniform likelihood of keys; higher means some keys are more popular
// tweak this to control hit rate
@Param("2.5")
double concentration;
Random random = new Random();
LoadingCache<Integer, Integer> cache;
Reported by PMD.
Line: 47
@Param("2.5")
double concentration;
Random random = new Random();
LoadingCache<Integer, Integer> cache;
int max;
Reported by PMD.
Line: 49
Random random = new Random();
LoadingCache<Integer, Integer> cache;
int max;
static AtomicLong requests = new AtomicLong(0);
static AtomicLong misses = new AtomicLong(0);
Reported by PMD.
Line: 51
LoadingCache<Integer, Integer> cache;
int max;
static AtomicLong requests = new AtomicLong(0);
static AtomicLong misses = new AtomicLong(0);
@BeforeExperiment
Reported by PMD.
Line: 56
static AtomicLong requests = new AtomicLong(0);
static AtomicLong misses = new AtomicLong(0);
@BeforeExperiment
void setUp() {
// random integers will be generated in this range, then raised to the
// power of (1/concentration) and floor()ed
max = Ints.checkedCast((long) Math.pow(distinctKeys, concentration));
Reported by PMD.
Line: 78
// Each miss both increments the counter and causes the map to grow by one,
// so until evictions begin, the size of the map is the greatest return
// value seen so far
while (cache.getUnchecked(nextRandomKey()) < maximumSize) {}
requests.set(0);
misses.set(0);
}
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/testers/MapToStringTester.java
11 issues
Line: 44
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapToStringTester<K, V> extends AbstractMapTester<K, V> {
public void testToString_minimal() {
assertNotNull("toString() should not return null", getMap().toString());
}
@CollectionSize.Require(ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
Reported by PMD.
Line: 45
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapToStringTester<K, V> extends AbstractMapTester<K, V> {
public void testToString_minimal() {
assertNotNull("toString() should not return null", getMap().toString());
}
@CollectionSize.Require(ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size0() {
Reported by PMD.
Line: 48
assertNotNull("toString() should not return null", getMap().toString());
}
@CollectionSize.Require(ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size0() {
assertEquals("emptyMap.toString should return {}", "{}", getMap().toString());
}
Reported by PMD.
Line: 51
@CollectionSize.Require(ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size0() {
assertEquals("emptyMap.toString should return {}", "{}", getMap().toString());
}
@CollectionSize.Require(ONE)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size1() {
Reported by PMD.
Line: 54
assertEquals("emptyMap.toString should return {}", "{}", getMap().toString());
}
@CollectionSize.Require(ONE)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size1() {
assertEquals("size1Map.toString should return {entry}", "{" + e0() + "}", getMap().toString());
}
Reported by PMD.
Line: 57
@CollectionSize.Require(ONE)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size1() {
assertEquals("size1Map.toString should return {entry}", "{" + e0() + "}", getMap().toString());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
@MapFeature.Require(ALLOWS_NULL_KEYS)
Reported by PMD.
Line: 60
assertEquals("size1Map.toString should return {entry}", "{" + e0() + "}", getMap().toString());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
@MapFeature.Require(ALLOWS_NULL_KEYS)
public void testToStringWithNullKey() {
initMapWithNullKey();
testToString_formatting();
Reported by PMD.
Line: 68
testToString_formatting();
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
@MapFeature.Require(ALLOWS_NULL_VALUES)
public void testToStringWithNullValue() {
initMapWithNullValue();
testToString_formatting();
Reported by PMD.
Line: 76
testToString_formatting();
}
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_formatting() {
assertEquals(
"map.toString() incorrect", expectedToString(getMap().entrySet()), getMap().toString());
}
Reported by PMD.
Line: 79
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_formatting() {
assertEquals(
"map.toString() incorrect", expectedToString(getMap().entrySet()), getMap().toString());
}
private String expectedToString(Set<Entry<K, V>> entries) {
Map<K, V> reference = new LinkedHashMap<>();
for (Entry<K, V> entry : entries) {
Reported by PMD.
android/guava-tests/benchmark/com/google/common/cache/LoadingCacheSingleThreadBenchmark.java
11 issues
Line: 112
double hit = req - misses.get();
// Currently, this is going into /dev/null, but I'll fix that
System.out.println("hit rate: " + hit / req);
}
// for proper distributions later:
// import JSci.maths.statistics.ProbabilityDistribution;
// int key = (int) dist.inverse(random.nextDouble());
Reported by PMD.
Line: 34
*/
public class LoadingCacheSingleThreadBenchmark {
@Param({"1000", "2000"})
int maximumSize;
@Param("5000")
int distinctKeys;
@Param("4")
Reported by PMD.
Line: 37
int maximumSize;
@Param("5000")
int distinctKeys;
@Param("4")
int segments;
// 1 means uniform likelihood of keys; higher means some keys are more popular
Reported by PMD.
Line: 40
int distinctKeys;
@Param("4")
int segments;
// 1 means uniform likelihood of keys; higher means some keys are more popular
// tweak this to control hit rate
@Param("2.5")
double concentration;
Reported by PMD.
Line: 45
// 1 means uniform likelihood of keys; higher means some keys are more popular
// tweak this to control hit rate
@Param("2.5")
double concentration;
Random random = new Random();
LoadingCache<Integer, Integer> cache;
Reported by PMD.
Line: 47
@Param("2.5")
double concentration;
Random random = new Random();
LoadingCache<Integer, Integer> cache;
int max;
Reported by PMD.
Line: 49
Random random = new Random();
LoadingCache<Integer, Integer> cache;
int max;
static AtomicLong requests = new AtomicLong(0);
static AtomicLong misses = new AtomicLong(0);
Reported by PMD.
Line: 51
LoadingCache<Integer, Integer> cache;
int max;
static AtomicLong requests = new AtomicLong(0);
static AtomicLong misses = new AtomicLong(0);
@BeforeExperiment
Reported by PMD.
Line: 56
static AtomicLong requests = new AtomicLong(0);
static AtomicLong misses = new AtomicLong(0);
@BeforeExperiment
void setUp() {
// random integers will be generated in this range, then raised to the
// power of (1/concentration) and floor()ed
max = Ints.checkedCast((long) Math.pow(distinctKeys, concentration));
Reported by PMD.
Line: 78
// Each miss both increments the counter and causes the map to grow by one,
// so until evictions begin, the size of the map is the greatest return
// value seen so far
while (cache.getUnchecked(nextRandomKey()) < maximumSize) {}
requests.set(0);
misses.set(0);
}
Reported by PMD.
android/guava-tests/benchmark/com/google/common/collect/MultipleSetContainsBenchmark.java
11 issues
Line: 29
public class MultipleSetContainsBenchmark {
@Param({"0.0", "0.1", "0.7", "1.0"})
double emptySetProportion;
@Param({"0.0", "0.1", "0.7", "1.0"})
double singletonSetProportion;
@Param({"0.2", "0.8"})
Reported by PMD.
Line: 32
double emptySetProportion;
@Param({"0.0", "0.1", "0.7", "1.0"})
double singletonSetProportion;
@Param({"0.2", "0.8"})
double hitRate;
static final Object PRESENT = new Object();
Reported by PMD.
Line: 35
double singletonSetProportion;
@Param({"0.2", "0.8"})
double hitRate;
static final Object PRESENT = new Object();
static final Object ABSENT = new Object();
@SuppressWarnings("unchecked")
Reported by PMD.
Line: 41
static final Object ABSENT = new Object();
@SuppressWarnings("unchecked")
private final ImmutableSet<Object>[] sets = new ImmutableSet[0x1000];
private final Object[] queries = new Object[0x1000];
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 43
@SuppressWarnings("unchecked")
private final ImmutableSet<Object>[] sets = new ImmutableSet[0x1000];
private final Object[] queries = new Object[0x1000];
@BeforeExperiment
void setUp() {
if (emptySetProportion + singletonSetProportion > 1.01) {
throw new SkipThisScenarioException();
Reported by PMD.
Line: 45
private final Object[] queries = new Object[0x1000];
@BeforeExperiment
void setUp() {
if (emptySetProportion + singletonSetProportion > 1.01) {
throw new SkipThisScenarioException();
}
Reported by PMD.
Line: 47
@BeforeExperiment
void setUp() {
if (emptySetProportion + singletonSetProportion > 1.01) {
throw new SkipThisScenarioException();
}
Random rng = new Random();
for (int i = 0; i < 0x1000; i++) {
Reported by PMD.
Line: 59
} else if (setSize < emptySetProportion + singletonSetProportion) {
sets[i] = ImmutableSet.of(PRESENT);
} else {
sets[i] = ImmutableSet.of(PRESENT, new Object());
}
if (rng.nextDouble() < hitRate) {
queries[i] = PRESENT;
} else {
Reported by PMD.
Line: 51
throw new SkipThisScenarioException();
}
Random rng = new Random();
for (int i = 0; i < 0x1000; i++) {
double setSize = rng.nextDouble();
if (setSize < emptySetProportion) {
sets[i] = ImmutableSet.of();
} else if (setSize < emptySetProportion + singletonSetProportion) {
Reported by PMD.
Line: 72
@Benchmark
public boolean contains(int reps) {
ImmutableSet<Object>[] sets = this.sets;
Object[] queries = this.queries;
boolean result = false;
for (int i = 0; i < reps; i++) {
int j = i & 0xFFF;
result ^= sets[j].contains(queries[j]);
Reported by PMD.