Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static final class EntryComparator<K extends @Nullable Object, V extends
@Override
@SuppressWarnings("unchecked") // no less safe than putting it in the map!
public int compare(Entry<K, V> a, Entry<K, V> b) {
return (keyComparator == null)
return keyComparator == null
? ((Comparable) a.getKey()).compareTo(b.getKey())
: keyComparator.compare(a.getKey(), b.getKey());
}
Expand Down Expand Up @@ -440,7 +440,7 @@ public boolean equals(@Nullable Object o) {
public int hashCode() {
K k = getKey();
V v = getValue();
return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
return (k == null ? 0 : k.hashCode()) ^ (v == null ? 0 : v.hashCode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public void testEntrySetRetainAll() {
Set<Entry<K, V>> entriesToRetain =
singleton(mapEntry(originalEntry.getKey(), originalEntry.getValue()));
if (supportsRemove) {
boolean shouldRemove = (entrySet.size() > entriesToRetain.size());
boolean shouldRemove = entrySet.size() > entriesToRetain.size();
boolean didRemove = entrySet.retainAll(entriesToRetain);
assertEquals(shouldRemove, didRemove);
assertEquals(entriesToRetain.size(), map.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public boolean equals(@Nullable Object object) {
public int hashCode() {
int hashCodeSum = 0;
for (Object o : this) {
hashCodeSum += (o == null) ? 0 : o.hashCode();
hashCodeSum += o == null ? 0 : o.hashCode();
}
return hashCodeSum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public Test testsForEnumSet() {
new TestEnumSetGenerator() {
@Override
public Set<AnEnum> create(AnEnum[] elements) {
return (elements.length == 0)
return elements.length == 0
? EnumSet.noneOf(AnEnum.class)
: EnumSet.copyOf(MinimalCollection.of(elements));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> pare
new ForwardingTestMultisetGenerator<E>(delegate) {
@Override
public SortedMultiset<E> create(Object... entries) {
return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
return SerializableTester.reserialize((SortedMultiset<E>) super.create(entries));
}
})
.named(parentBuilder.getName() + " reserialized")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ListHashCodeTester<E> extends AbstractListTester<E> {
public void testHashCode() {
int expectedHashCode = 1;
for (E element : getOrderedElements()) {
expectedHashCode = 31 * expectedHashCode + ((element == null) ? 0 : element.hashCode());
expectedHashCode = 31 * expectedHashCode + (element == null ? 0 : element.hashCode());
}
assertEquals(
"A List's hashCode() should be computed from those of its elements.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SetHashCodeTester<E> extends AbstractSetTester<E> {
public void testHashCode() {
int expectedHashCode = 0;
for (E element : getSampleElements()) {
expectedHashCode += ((element == null) ? 0 : element.hashCode());
expectedHashCode += element == null ? 0 : element.hashCode();
}
assertEquals(
"A Set's hashCode() should be the sum of those of its elements.",
Expand All @@ -55,7 +55,7 @@ public void testHashCode_containingNull() {
Collection<E> elements = getSampleElements(getNumElements() - 1);
int expectedHashCode = 0;
for (E element : elements) {
expectedHashCode += ((element == null) ? 0 : element.hashCode());
expectedHashCode += element == null ? 0 : element.hashCode();
}

elements.add(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ private static <T> void setImplementation(Class<T> type, Class<? extends T> impl
}
if (type.isEnum()) {
T[] enumConstants = type.getEnumConstants();
return (enumConstants == null || enumConstants.length == 0) ? null : enumConstants[0];
return enumConstants == null || enumConstants.length == 0 ? null : enumConstants[0];
}
if (type.isArray()) {
return createEmptyArray(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ long manual(int reps) {
for (int i = 0; i < reps; i++) {
long start = System.nanoTime();
// here is where you would do something
total += (System.nanoTime() - start);
total += System.nanoTime() - start;
}
return total;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ boolean removeExactly(@Nullable Object element, int occurrences) {
@Override
public int setCount(E element, int count) {
checkNonnegative(count, "count");
return (count == 0) ? removeAllOccurrences(element) : unbox(countMap.put(element, count));
return count == 0 ? removeAllOccurrences(element) : unbox(countMap.put(element, count));
}

/**
Expand Down Expand Up @@ -546,7 +546,7 @@ public int hashCode() {

/** We use a special form of unboxing that treats null as zero. */
private static int unbox(@Nullable Integer i) {
return (i == null) ? 0 : i;
return i == null ? 0 : i;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ boolean doEquals(byte[] a, byte[] b) {
}
boolean areEqual = true;
for (int i = 0; i < a.length; i++) {
areEqual &= (a[i] == b[i]);
areEqual &= a[i] == b[i];
}
return areEqual;
}
Expand All @@ -85,7 +85,7 @@ boolean doEquals(byte[] a, byte[] b) {
for (int i = 0; i < a.length; i++) {
result = (byte) (result | a[i] ^ b[i]);
}
return (result == 0);
return result == 0;
}
},
XORING_TO_INT {
Expand All @@ -98,7 +98,7 @@ boolean doEquals(byte[] a, byte[] b) {
for (int i = 0; i < a.length; i++) {
result |= a[i] ^ b[i];
}
return (result == 0);
return result == 0;
}
},
MESSAGE_DIGEST_IS_EQUAL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int ternaryLtIntAddOutsideTernary(int reps) {
int x = xInts[j];
int y = yInts[j];
int z = constant[j];
tmp += z + ((x < y) ? 1 : 0);
tmp += z + (x < y ? 1 : 0);
}
return tmp;
}
Expand All @@ -109,7 +109,7 @@ int ternaryLtIntAddInsideTernary(int reps) {
int x = xInts[j];
int y = yInts[j];
int z = constant[j];
tmp += (x < y) ? z + 1 : z;
tmp += x < y ? z + 1 : z;
}
return tmp;
}
Expand Down Expand Up @@ -148,7 +148,7 @@ int ternaryLtLongAddOutsideTernary(int reps) {
long x = xLongs[j];
long y = yLongs[j];
int z = constant[j];
tmp += z + ((x < y) ? 1 : 0);
tmp += z + (x < y ? 1 : 0);
}
return tmp;
}
Expand All @@ -161,7 +161,7 @@ int ternaryLtLongAddInsideTernary(int reps) {
long x = xLongs[j];
long y = yLongs[j];
int z = constant[j];
tmp += (x < y) ? z + 1 : z;
tmp += x < y ? z + 1 : z;
}
return tmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class MonitorBasedArrayBlockingQueue<E> extends AbstractQueue<E>

/** Circularly increment i. */
final int inc(int i) {
return (++i == items.length) ? 0 : i;
return ++i == items.length ? 0 : i;
}

/**
Expand Down Expand Up @@ -629,7 +629,7 @@ public int drainTo(Collection<? super E> c, int maxElements) {
try {
int i = takeIndex;
int n = 0;
int max = (maxElements < count) ? maxElements : count;
int max = maxElements < count ? maxElements : count;
while (n < max) {
c.add(items[i]);
items[i] = null;
Expand Down Expand Up @@ -746,7 +746,7 @@ public void remove() {
int ti = takeIndex;
removeAt(i);
// back up cursor (reset to front if was first element)
nextIndex = (i == ti) ? takeIndex : i;
nextIndex = i == ti ? takeIndex : i;
checkNext();
} finally {
monitor.leave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MonitorBenchmark {
@SuppressWarnings("unchecked")
void setUp() throws Exception {
String prefix =
(useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void testCompositionWildcard() {
private static class HashCodeFunction implements Function<@Nullable Object, Integer> {
@Override
public Integer apply(@Nullable Object o) {
return (o == null) ? 0 : o.hashCode();
return o == null ? 0 : o.hashCode();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ public String load(String key) throws InterruptedException {
// doConcurrentGet alternates between calling getUnchecked and calling get, but an unchecked
// exception thrown by the loader is always wrapped as an UncheckedExecutionException.
assertThat(result.get(i)).isInstanceOf(UncheckedExecutionException.class);
assertThat(((UncheckedExecutionException) result.get(i))).hasCauseThat().isSameInstanceAs(e);
assertThat((UncheckedExecutionException) result.get(i)).hasCauseThat().isSameInstanceAs(e);
}

// subsequent calls should call the loader again, not get the old exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static <K, V> LocalCache<K, V> toLocalCache(Cache<K, V> cache) {
* without throwing an exception.
*/
static boolean hasLocalCache(Cache<?, ?> cache) {
return (checkNotNull(cache) instanceof LocalLoadingCache);
return checkNotNull(cache) instanceof LocalLoadingCache;
}

static void drainRecencyQueues(Cache<?, ?> cache) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ public void testExpand_cleanup() {
ReferenceEntry<Object, Object> entry = null;
for (int i = 0; i < originalCount; i++) {
Object key = new Object();
Object value = (i % 3 == 0) ? null : new Object();
Object value = i % 3 == 0 ? null : new Object();
int hash = map.hash(key);
if (i % 3 == 1) {
key = null;
Expand Down Expand Up @@ -3055,7 +3055,7 @@ public int hashCode() {

@Override
public boolean equals(@Nullable Object o) {
return (o instanceof SerializableCacheLoader);
return o instanceof SerializableCacheLoader;
}
}

Expand All @@ -3071,7 +3071,7 @@ public int hashCode() {

@Override
public boolean equals(@Nullable Object o) {
return (o instanceof SerializableRemovalListener);
return o instanceof SerializableRemovalListener;
}
}

Expand All @@ -3088,7 +3088,7 @@ public int hashCode() {

@Override
public boolean equals(@Nullable Object o) {
return (o instanceof SerializableTicker);
return o instanceof SerializableTicker;
}
}

Expand All @@ -3105,7 +3105,7 @@ public int hashCode() {

@Override
public boolean equals(@Nullable Object o) {
return (o instanceof SerializableWeigher);
return o instanceof SerializableWeigher;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void testTransformEntrySetContains() {
new Function<@Nullable Boolean, @Nullable Boolean>() {
@Override
public @Nullable Boolean apply(@Nullable Boolean from) {
return (from == null) ? true : null;
return from == null ? true : null;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Iterator<Integer> iterator() {
new AbstractSequentialIterator<Integer>(1) {
@Override
protected @Nullable Integer computeNext(Integer previous) {
return (previous == 1 << 30) ? null : previous * 2;
return previous == 1 << 30 ? null : previous * 2;
}
};
return powersOfTwo;
Expand Down Expand Up @@ -128,7 +128,7 @@ private static Iterator<Integer> newDoubler(int first, int last) {
return new AbstractSequentialIterator<Integer>(first) {
@Override
protected @Nullable Integer computeNext(Integer previous) {
return (previous == last) ? null : previous * 2;
return previous == last ? null : previous * 2;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private static Test testsForTransform() {
public Collection<@Nullable String> create(@Nullable String[] elements) {
List<@Nullable String> list = new ArrayList<>();
for (String element : elements) {
list.add((element == null) ? null : "q" + element);
list.add(element == null ? null : "q" + element);
}
return Collections2.transform(
list, from -> isNullOrEmpty(from) ? null : from.substring(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ public int[] call() throws Exception {
{
int newValue = random.nextInt(3);
int oldValue = multiset.setCount(key, newValue);
deltas[keyIndex] += (newValue - oldValue);
deltas[keyIndex] += newValue - oldValue;
break;
}
case SET_COUNT_IF:
{
int newValue = random.nextInt(3);
int oldValue = multiset.count(key);
if (multiset.setCount(key, oldValue, newValue)) {
deltas[keyIndex] += (newValue - oldValue);
deltas[keyIndex] += newValue - oldValue;
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static TestEnumMultisetGenerator enumMultisetGenerator() {
return new TestEnumMultisetGenerator() {
@Override
protected Multiset<AnEnum> create(AnEnum[] elements) {
return (elements.length == 0)
return elements.length == 0
? EnumMultiset.create(AnEnum.class)
: EnumMultiset.create(asList(elements));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void testCycle() {

int howManyChecked = 0;
for (String string : cycle) {
String expected = (howManyChecked % 2 == 0) ? "a" : "b";
String expected = howManyChecked % 2 == 0 ? "a" : "b";
assertEquals(expected, string);
if (howManyChecked++ == 5) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void testCycle() {

int howManyChecked = 0;
for (String string : cycle) {
String expected = (howManyChecked % 2 == 0) ? "a" : "b";
String expected = howManyChecked % 2 == 0 ? "a" : "b";
assertEquals(expected, string);
if (howManyChecked++ == 5) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class ListsTest extends TestCase {
private static final class RemoveFirstFunction implements Function<String, String>, Serializable {
@Override
public String apply(String from) {
return (from.length() == 0) ? from : from.substring(1);
return from.length() == 0 ? from : from.substring(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public void testExpand_cleanup() {
InternalEntry<Object, Object, ?> entry = null;
for (int i = 0; i < originalCount; i++) {
Object key = new Object();
Object value = (i % 3 == 0) ? null : new Object();
Object value = i % 3 == 0 ? null : new Object();
int hash = map.hash(key);
if (i % 3 == 1) {
key = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void testTransformEntrySetContains() {
new Function<@Nullable Boolean, @Nullable Boolean>() {
@Override
public @Nullable Boolean apply(@Nullable Boolean from) {
return (from == null) ? true : null;
return from == null ? true : null;
}
});

Expand Down
Loading