The following issues were found
guava-tests/benchmark/com/google/common/collect/MultisetIteratorBenchmark.java
13 issues
Line: 32
*/
public class MultisetIteratorBenchmark {
@Param({"0", "1", "16", "256", "4096", "65536"})
int size;
LinkedHashMultiset<Object> linkedHashMultiset;
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
Reported by PMD.
Line: 34
@Param({"0", "1", "16", "256", "4096", "65536"})
int size;
LinkedHashMultiset<Object> linkedHashMultiset;
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
Reported by PMD.
Line: 34
@Param({"0", "1", "16", "256", "4096", "65536"})
int size;
LinkedHashMultiset<Object> linkedHashMultiset;
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
Reported by PMD.
Line: 35
int size;
LinkedHashMultiset<Object> linkedHashMultiset;
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
@BeforeExperiment
Reported by PMD.
Line: 35
int size;
LinkedHashMultiset<Object> linkedHashMultiset;
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
@BeforeExperiment
Reported by PMD.
Line: 38
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
@BeforeExperiment
void setUp() {
hashMultiset = HashMultiset.create(size);
linkedHashMultiset = LinkedHashMultiset.create(size);
Reported by PMD.
Line: 38
HashMultiset<Object> hashMultiset;
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
@BeforeExperiment
void setUp() {
hashMultiset = HashMultiset.create(size);
linkedHashMultiset = LinkedHashMultiset.create(size);
Reported by PMD.
Line: 40
// TreeMultiset requires a Comparable element.
TreeMultiset<Integer> treeMultiset;
@BeforeExperiment
void setUp() {
hashMultiset = HashMultiset.create(size);
linkedHashMultiset = LinkedHashMultiset.create(size);
treeMultiset = TreeMultiset.create();
Reported by PMD.
Line: 51
int sizeRemaining = size;
// TODO(kevinb): generate better test contents for multisets
for (int i = 0; sizeRemaining > 0; i++) {
// The JVM will return interned values for small ints.
Integer value = random.nextInt(1000) + 128;
int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
sizeRemaining -= count;
hashMultiset.add(value, count);
Reported by PMD.
Line: 51
int sizeRemaining = size;
// TODO(kevinb): generate better test contents for multisets
for (int i = 0; sizeRemaining > 0; i++) {
// The JVM will return interned values for small ints.
Integer value = random.nextInt(1000) + 128;
int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
sizeRemaining -= count;
hashMultiset.add(value, count);
Reported by PMD.
guava-tests/benchmark/com/google/common/collect/IteratorBenchmark.java
13 issues
Line: 30
*
* @author David Richter
*/
public class IteratorBenchmark {
@Param({"0", "1", "16", "256", "4096", "65536"})
int size;
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
Reported by PMD.
Line: 32
*/
public class IteratorBenchmark {
@Param({"0", "1", "16", "256", "4096", "65536"})
int size;
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
Reported by PMD.
Line: 35
int size;
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 36
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
@BeforeExperiment
void setUp() {
array = new Object[size];
Reported by PMD.
Line: 36
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
@BeforeExperiment
void setUp() {
array = new Object[size];
Reported by PMD.
Line: 37
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
@BeforeExperiment
void setUp() {
array = new Object[size];
arrayList = Lists.newArrayListWithCapacity(size);
Reported by PMD.
Line: 37
// use concrete classes to remove any possible polymorphic overhead?
Object[] array;
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
@BeforeExperiment
void setUp() {
array = new Object[size];
arrayList = Lists.newArrayListWithCapacity(size);
Reported by PMD.
Line: 39
ArrayList<Object> arrayList;
LinkedList<Object> linkedList;
@BeforeExperiment
void setUp() {
array = new Object[size];
arrayList = Lists.newArrayListWithCapacity(size);
linkedList = Lists.newLinkedList();
Reported by PMD.
Line: 46
linkedList = Lists.newLinkedList();
for (int i = 0; i < size; i++) {
Object value = new Object();
array[i] = value;
arrayList.add(value);
linkedList.add(value);
}
}
Reported by PMD.
Line: 68
int arrayIndexedLength(int reps) {
int sum = 0;
for (int i = 0; i < reps; i++) {
for (int index = 0; index < array.length; index++) {
sum += array[index].hashCode();
}
}
return sum;
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/google/MultisetEqualsTester.java
12 issues
Line: 34
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetEqualsTester<E> extends AbstractMultisetTester<E> {
public void testEqualsSameContents() {
new EqualsTester()
.addEqualityGroup(
getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
.testEquals();
}
Reported by PMD.
Line: 37
public void testEqualsSameContents() {
new EqualsTester()
.addEqualityGroup(
getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
public void testNotEqualsEmpty() {
Reported by PMD.
Line: 37
public void testEqualsSameContents() {
new EqualsTester()
.addEqualityGroup(
getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
public void testNotEqualsEmpty() {
Reported by PMD.
Line: 41
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
public void testNotEqualsEmpty() {
new EqualsTester()
.addEqualityGroup(getMultiset())
.addEqualityGroup(getSubjectGenerator().create())
.testEquals();
Reported by PMD.
Line: 45
public void testNotEqualsEmpty() {
new EqualsTester()
.addEqualityGroup(getMultiset())
.addEqualityGroup(getSubjectGenerator().create())
.testEquals();
}
public void testHashCodeMatchesEntrySet() {
assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
Reported by PMD.
Line: 49
.testEquals();
}
public void testHashCodeMatchesEntrySet() {
assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
Reported by PMD.
Line: 50
}
public void testHashCodeMatchesEntrySet() {
assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEqualsMultisetWithNullValue() {
Reported by PMD.
Line: 50
}
public void testHashCodeMatchesEntrySet() {
assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEqualsMultisetWithNullValue() {
Reported by PMD.
Line: 50
}
public void testHashCodeMatchesEntrySet() {
assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEqualsMultisetWithNullValue() {
Reported by PMD.
Line: 53
assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEqualsMultisetWithNullValue() {
new EqualsTester()
.addEqualityGroup(getMultiset())
.addEqualityGroup(
Reported by PMD.
guava-tests/test/com/google/common/collect/AbstractBiMapTest.java
12 issues
Line: 31
// The next two tests verify that map entries are not accessed after they're
// removed, since IdentityHashMap throws an exception when that occurs.
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityKeySetIteratorRemove() {
BiMap<Integer, String> bimap =
new AbstractBiMap<Integer, String>(
new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
bimap.put(1, "one");
Reported by PMD.
Line: 32
// The next two tests verify that map entries are not accessed after they're
// removed, since IdentityHashMap throws an exception when that occurs.
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityKeySetIteratorRemove() {
BiMap<Integer, String> bimap =
new AbstractBiMap<Integer, String>(
new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
bimap.put(1, "one");
bimap.put(2, "two");
Reported by PMD.
Line: 39
bimap.put(1, "one");
bimap.put(2, "two");
bimap.put(3, "three");
Iterator<Integer> iterator = bimap.keySet().iterator();
iterator.next();
iterator.next();
iterator.remove();
iterator.next();
iterator.remove();
Reported by PMD.
Line: 45
iterator.remove();
iterator.next();
iterator.remove();
assertEquals(1, bimap.size());
assertEquals(1, bimap.inverse().size());
}
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityEntrySetIteratorRemove() {
Reported by PMD.
Line: 46
iterator.next();
iterator.remove();
assertEquals(1, bimap.size());
assertEquals(1, bimap.inverse().size());
}
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityEntrySetIteratorRemove() {
BiMap<Integer, String> bimap =
Reported by PMD.
Line: 46
iterator.next();
iterator.remove();
assertEquals(1, bimap.size());
assertEquals(1, bimap.inverse().size());
}
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityEntrySetIteratorRemove() {
BiMap<Integer, String> bimap =
Reported by PMD.
Line: 49
assertEquals(1, bimap.inverse().size());
}
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityEntrySetIteratorRemove() {
BiMap<Integer, String> bimap =
new AbstractBiMap<Integer, String>(
new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
bimap.put(1, "one");
Reported by PMD.
Line: 50
}
@SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
public void testIdentityEntrySetIteratorRemove() {
BiMap<Integer, String> bimap =
new AbstractBiMap<Integer, String>(
new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
bimap.put(1, "one");
bimap.put(2, "two");
Reported by PMD.
Line: 57
bimap.put(1, "one");
bimap.put(2, "two");
bimap.put(3, "three");
Iterator<Entry<Integer, String>> iterator = bimap.entrySet().iterator();
iterator.next();
iterator.next();
iterator.remove();
iterator.next();
iterator.remove();
Reported by PMD.
Line: 63
iterator.remove();
iterator.next();
iterator.remove();
assertEquals(1, bimap.size());
assertEquals(1, bimap.inverse().size());
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java
12 issues
Line: 53
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
public void testIterator() {
List<E> iteratorElements = new ArrayList<E>();
for (E element : collection) { // uses iterator()
iteratorElements.add(element);
}
Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);
Reported by PMD.
Line: 61
Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);
}
@CollectionFeature.Require(KNOWN_ORDER)
public void testIterationOrdering() {
List<E> iteratorElements = new ArrayList<E>();
for (E element : collection) { // uses iterator()
iteratorElements.add(element);
}
Reported by PMD.
Line: 71
assertEquals("Different ordered iteration", expected, iteratorElements);
}
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testIterator_nullElement() {
initCollectionWithNullElement();
List<E> iteratorElements = new ArrayList<E>();
for (E element : collection) { // uses iterator()
Reported by PMD.
Line: 82
Helpers.assertEqualIgnoringOrder(asList(createArrayWithNullElement()), iteratorElements);
}
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testIterator_removeAffectsBackingCollection() {
int originalSize = collection.size();
Iterator<E> iterator = collection.iterator();
Object element = iterator.next();
Reported by PMD.
Line: 84
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testIterator_removeAffectsBackingCollection() {
int originalSize = collection.size();
Iterator<E> iterator = collection.iterator();
Object element = iterator.next();
// If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
if (element instanceof Entry) {
Reported by PMD.
Line: 91
// If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
if (element instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) element;
element = mapEntry(entry.getKey(), entry.getValue());
}
assertTrue(collection.contains(element)); // sanity check
iterator.remove();
assertFalse(collection.contains(element));
assertEquals(originalSize - 1, collection.size());
Reported by PMD.
Line: 91
// If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
if (element instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) element;
element = mapEntry(entry.getKey(), entry.getValue());
}
assertTrue(collection.contains(element)); // sanity check
iterator.remove();
assertFalse(collection.contains(element));
assertEquals(originalSize - 1, collection.size());
Reported by PMD.
Line: 99
assertEquals(originalSize - 1, collection.size());
}
@CollectionFeature.Require({KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE})
public void testIterator_knownOrderRemoveSupported() {
runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
}
@CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)
Reported by PMD.
Line: 104
runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
}
@CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)
public void testIterator_knownOrderRemoveUnsupported() {
runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
}
@CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE)
Reported by PMD.
Line: 109
runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
}
@CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE)
public void testIterator_unknownOrderRemoveSupported() {
runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.UNKNOWN_ORDER, getSampleElements());
}
@CollectionFeature.Require(absent = {KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE})
Reported by PMD.
guava-tests/benchmark/com/google/common/hash/HashFunctionBenchmark.java
12 issues
Line: 42
private static final Random random = new Random(42);
@Param({"10", "1000", "100000", "1000000"})
private int size;
@Param HashFunctionEnum hashFunctionEnum;
private byte[] testBytes;
Reported by PMD.
Line: 44
@Param({"10", "1000", "100000", "1000000"})
private int size;
@Param HashFunctionEnum hashFunctionEnum;
private byte[] testBytes;
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 46
@Param HashFunctionEnum hashFunctionEnum;
private byte[] testBytes;
@BeforeExperiment
void setUp() {
testBytes = new byte[size];
random.nextBytes(testBytes);
Reported by PMD.
Line: 48
private byte[] testBytes;
@BeforeExperiment
void setUp() {
testBytes = new byte[size];
random.nextBytes(testBytes);
}
Reported by PMD.
Line: 59
HashFunction hashFunction = hashFunctionEnum.getHashFunction();
int result = 37;
for (int i = 0; i < reps; i++) {
result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
}
return result;
}
@Benchmark
Reported by PMD.
Line: 59
HashFunction hashFunction = hashFunctionEnum.getHashFunction();
int result = 37;
for (int i = 0; i < reps; i++) {
result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
}
return result;
}
@Benchmark
Reported by PMD.
Line: 59
HashFunction hashFunction = hashFunctionEnum.getHashFunction();
int result = 37;
for (int i = 0; i < reps; i++) {
result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
}
return result;
}
@Benchmark
Reported by PMD.
Line: 69
HashFunction hashFunction = hashFunctionEnum.getHashFunction();
int result = 37;
for (int i = 0; i < reps; i++) {
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
}
return result;
}
@Benchmark
Reported by PMD.
Line: 79
HashFunction hashFunction = hashFunctionEnum.getHashFunction();
int result = 37;
for (int i = 0; i < reps; i++) {
result ^= hashFunction.hashBytes(testBytes, 1, testBytes.length - 1).asBytes()[0];
}
return result;
}
}
Reported by PMD.
Line: 56
@Benchmark
int hasher(int reps) {
HashFunction hashFunction = hashFunctionEnum.getHashFunction();
int result = 37;
for (int i = 0; i < reps; i++) {
result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
}
return result;
Reported by PMD.
guava-tests/test/com/google/common/eventbus/AsyncEventBusTest.java
12 issues
Line: 33
private static final String EVENT = "Hello";
/** The executor we use to fake asynchronicity. */
private FakeExecutor executor;
private AsyncEventBus bus;
@Override
protected void setUp() throws Exception {
Reported by PMD.
Line: 35
/** The executor we use to fake asynchronicity. */
private FakeExecutor executor;
private AsyncEventBus bus;
@Override
protected void setUp() throws Exception {
super.setUp();
executor = new FakeExecutor();
Reported by PMD.
Line: 37
private AsyncEventBus bus;
@Override
protected void setUp() throws Exception {
super.setUp();
executor = new FakeExecutor();
bus = new AsyncEventBus(executor);
}
Reported by PMD.
Line: 44
bus = new AsyncEventBus(executor);
}
public void testBasicDistribution() {
StringCatcher catcher = new StringCatcher();
bus.register(catcher);
// We post the event, but our Executor will not deliver it until instructed.
bus.post(EVENT);
Reported by PMD.
Line: 44
bus = new AsyncEventBus(executor);
}
public void testBasicDistribution() {
StringCatcher catcher = new StringCatcher();
bus.register(catcher);
// We post the event, but our Executor will not deliver it until instructed.
bus.post(EVENT);
Reported by PMD.
Line: 52
bus.post(EVENT);
List<String> events = catcher.getEvents();
assertTrue("No events should be delivered synchronously.", events.isEmpty());
// Now we find the task in our Executor and explicitly activate it.
List<Runnable> tasks = executor.getTasks();
assertEquals("One event dispatch task should be queued.", 1, tasks.size());
Reported by PMD.
Line: 56
// Now we find the task in our Executor and explicitly activate it.
List<Runnable> tasks = executor.getTasks();
assertEquals("One event dispatch task should be queued.", 1, tasks.size());
tasks.get(0).run();
assertEquals("One event should be delivered.", 1, events.size());
assertEquals("Correct string should be delivered.", EVENT, events.get(0));
Reported by PMD.
Line: 58
List<Runnable> tasks = executor.getTasks();
assertEquals("One event dispatch task should be queued.", 1, tasks.size());
tasks.get(0).run();
assertEquals("One event should be delivered.", 1, events.size());
assertEquals("Correct string should be delivered.", EVENT, events.get(0));
}
Reported by PMD.
Line: 58
List<Runnable> tasks = executor.getTasks();
assertEquals("One event dispatch task should be queued.", 1, tasks.size());
tasks.get(0).run();
assertEquals("One event should be delivered.", 1, events.size());
assertEquals("Correct string should be delivered.", EVENT, events.get(0));
}
Reported by PMD.
Line: 60
tasks.get(0).run();
assertEquals("One event should be delivered.", 1, events.size());
assertEquals("Correct string should be delivered.", EVENT, events.get(0));
}
/**
* An {@link Executor} wanna-be that simply records the tasks it's given. Arguably the Worst
Reported by PMD.
guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java
12 issues
Line: 44
private static final int RANDOM_SEED = new Random().nextInt();
@Param({"10", "1000", "100000", "1000000"})
private int size;
private byte[] testBytes;
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 46
@Param({"10", "1000", "100000", "1000000"})
private int size;
private byte[] testBytes;
@BeforeExperiment
void setUp() {
testBytes = new byte[size];
new Random(RANDOM_SEED).nextBytes(testBytes);
Reported by PMD.
Line: 48
private byte[] testBytes;
@BeforeExperiment
void setUp() {
testBytes = new byte[size];
new Random(RANDOM_SEED).nextBytes(testBytes);
}
Reported by PMD.
Line: 62
}
@Benchmark
byte crc32Checksum(int reps) throws Exception {
byte result = 0x01;
for (int i = 0; i < reps; i++) {
CRC32 checksum = new CRC32();
checksum.update(testBytes);
result = (byte) (result ^ checksum.getValue());
Reported by PMD.
Line: 65
byte crc32Checksum(int reps) throws Exception {
byte result = 0x01;
for (int i = 0; i < reps; i++) {
CRC32 checksum = new CRC32();
checksum.update(testBytes);
result = (byte) (result ^ checksum.getValue());
}
return result;
}
Reported by PMD.
Line: 80
}
@Benchmark
byte adler32Checksum(int reps) throws Exception {
byte result = 0x01;
for (int i = 0; i < reps; i++) {
Adler32 checksum = new Adler32();
checksum.update(testBytes);
result = (byte) (result ^ checksum.getValue());
Reported by PMD.
Line: 83
byte adler32Checksum(int reps) throws Exception {
byte result = 0x01;
for (int i = 0; i < reps; i++) {
Adler32 checksum = new Adler32();
checksum.update(testBytes);
result = (byte) (result ^ checksum.getValue());
}
return result;
}
Reported by PMD.
Line: 95
private byte runHashFunction(int reps, HashFunction hashFunction) {
byte result = 0x01;
// Trick the JVM to prevent it from using the hash function non-polymorphically
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
for (int i = 0; i < reps; i++) {
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
}
return result;
Reported by PMD.
Line: 95
private byte runHashFunction(int reps, HashFunction hashFunction) {
byte result = 0x01;
// Trick the JVM to prevent it from using the hash function non-polymorphically
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
for (int i = 0; i < reps; i++) {
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
}
return result;
Reported by PMD.
Line: 96
byte result = 0x01;
// Trick the JVM to prevent it from using the hash function non-polymorphically
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
for (int i = 0; i < reps; i++) {
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
}
return result;
}
Reported by PMD.
guava-tests/benchmark/com/google/common/util/concurrent/MonitorBenchmark.java
12 issues
Line: 33
public class MonitorBenchmark {
@Param({"10", "100", "1000"})
int capacity;
@Param({"Array", "Priority"})
String queueType;
@Param boolean useMonitor;
Reported by PMD.
Line: 36
int capacity;
@Param({"Array", "Priority"})
String queueType;
@Param boolean useMonitor;
private BlockingQueue<String> queue;
private String[] strings;
Reported by PMD.
Line: 38
@Param({"Array", "Priority"})
String queueType;
@Param boolean useMonitor;
private BlockingQueue<String> queue;
private String[] strings;
@BeforeExperiment
Reported by PMD.
Line: 40
@Param boolean useMonitor;
private BlockingQueue<String> queue;
private String[] strings;
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws Exception {
Reported by PMD.
Line: 41
@Param boolean useMonitor;
private BlockingQueue<String> queue;
private String[] strings;
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws Exception {
String prefix =
Reported by PMD.
Line: 43
private BlockingQueue<String> queue;
private String[] strings;
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws Exception {
String prefix =
(useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
String className = prefix + queueType + "BlockingQueue";
Reported by PMD.
Line: 45
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws Exception {
String prefix =
(useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
String className = prefix + queueType + "BlockingQueue";
Constructor<?> constructor = Class.forName(className).getConstructor(int.class);
queue = (BlockingQueue<String>) constructor.newInstance(capacity);
Reported by PMD.
Line: 49
String prefix =
(useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
String className = prefix + queueType + "BlockingQueue";
Constructor<?> constructor = Class.forName(className).getConstructor(int.class);
queue = (BlockingQueue<String>) constructor.newInstance(capacity);
strings = new String[capacity];
for (int i = 0; i < capacity; i++) {
strings[i] = String.valueOf(Math.random());
Reported by PMD.
Line: 50
(useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
String className = prefix + queueType + "BlockingQueue";
Constructor<?> constructor = Class.forName(className).getConstructor(int.class);
queue = (BlockingQueue<String>) constructor.newInstance(capacity);
strings = new String[capacity];
for (int i = 0; i < capacity; i++) {
strings[i] = String.valueOf(Math.random());
}
Reported by PMD.
Line: 60
@Benchmark
void addsAndRemoves(int reps) {
int capacity = this.capacity;
BlockingQueue<String> queue = this.queue;
String[] strings = this.strings;
for (int i = 0; i < reps; i++) {
for (int j = 0; j < capacity; j++) {
queue.add(strings[j]);
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java
12 issues
Line: 40
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapGetTester<K, V> extends AbstractMapTester<K, V> {
@CollectionSize.Require(absent = ZERO)
public void testGet_yes() {
assertEquals("get(present) should return the associated value", v0(), get(k0()));
}
public void testGet_no() {
Reported by PMD.
Line: 45
assertEquals("get(present) should return the associated value", v0(), get(k0()));
}
public void testGet_no() {
assertNull("get(notPresent) should return null", get(k3()));
}
@MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
public void testGet_nullNotContainedButAllowed() {
Reported by PMD.
Line: 49
assertNull("get(notPresent) should return null", get(k3()));
}
@MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
public void testGet_nullNotContainedButAllowed() {
assertNull("get(null) should return null", get(null));
}
@MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
Reported by PMD.
Line: 54
assertNull("get(null) should return null", get(null));
}
@MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
public void testGet_nullNotContainedAndUnsupported() {
try {
assertNull("get(null) should return null or throw", get(null));
} catch (NullPointerException tolerated) {
}
Reported by PMD.
Line: 58
public void testGet_nullNotContainedAndUnsupported() {
try {
assertNull("get(null) should return null or throw", get(null));
} catch (NullPointerException tolerated) {
}
}
@MapFeature.Require(ALLOWS_NULL_KEYS)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 58
public void testGet_nullNotContainedAndUnsupported() {
try {
assertNull("get(null) should return null or throw", get(null));
} catch (NullPointerException tolerated) {
}
}
@MapFeature.Require(ALLOWS_NULL_KEYS)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 58
public void testGet_nullNotContainedAndUnsupported() {
try {
assertNull("get(null) should return null or throw", get(null));
} catch (NullPointerException tolerated) {
}
}
@MapFeature.Require(ALLOWS_NULL_KEYS)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 62
}
}
@MapFeature.Require(ALLOWS_NULL_KEYS)
@CollectionSize.Require(absent = ZERO)
public void testGet_nonNullWhenNullContained() {
initMapWithNullKey();
assertNull("get(notPresent) should return null", get(k3()));
}
Reported by PMD.
Line: 69
assertNull("get(notPresent) should return null", get(k3()));
}
@MapFeature.Require(ALLOWS_NULL_KEYS)
@CollectionSize.Require(absent = ZERO)
public void testGet_nullContained() {
initMapWithNullKey();
assertEquals("get(null) should return the associated value", getValueForNullKey(), get(null));
}
Reported by PMD.
Line: 76
assertEquals("get(null) should return the associated value", getValueForNullKey(), get(null));
}
public void testGet_wrongType() {
try {
assertNull("get(wrongType) should return null or throw", getMap().get(WrongType.VALUE));
} catch (ClassCastException tolerated) {
}
}
Reported by PMD.