Skip to content

Commit

Permalink
Build Truth with -source 7 -target 7, and take advantage of the diamo…
Browse files Browse the repository at this point in the history
…nd operator.

RELNOTES=Truth is now built with `-target 7`. However, it continues to depend on only "Java-6-like" APIs so that it continues to work on old versions of Android.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179451537
  • Loading branch information
cpovirk authored and ronshapiro committed Dec 19, 2017
1 parent 74f246e commit 1688736
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 56 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/com/google/common/truth/GraphMatching.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static class HopcroftKarp<U, V> {
* graph described by the given multimap.
*/
static <U, V> HopcroftKarp<U, V> overBipartiteGraph(Multimap<U, V> graph) {
return new HopcroftKarp<U, V>(graph);
return new HopcroftKarp<>(graph);
}

private HopcroftKarp(Multimap<U, V> graph) {
Expand All @@ -88,7 +88,7 @@ ImmutableBiMap<U, V> perform() {
while (true) {
// Perform the BFS as described below. This finds the length of the shortest augmenting path
// and a guide which locates all the augmenting paths of that length.
Map<U, Integer> layers = new HashMap<U, Integer>();
Map<U, Integer> layers = new HashMap<>();
Optional<Integer> freeRhsVertexLayer = breadthFirstSearch(matching, layers);
if (!freeRhsVertexLayer.isPresent()) {
// The BFS failed, i.e. we found no augmenting paths. So we're done.
Expand Down Expand Up @@ -128,7 +128,7 @@ ImmutableBiMap<U, V> perform() {
* absent value if the BFS was exhausted without finding any free RHS vertex
*/
private Optional<Integer> breadthFirstSearch(BiMap<U, V> matching, Map<U, Integer> layers) {
Queue<U> queue = new ArrayDeque<U>();
Queue<U> queue = new ArrayDeque<>();
Optional<Integer> freeRhsVertexLayer = Optional.absent();

// Enqueue all free LHS vertices and assign them to layer 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public final void containsNoneIn(Object[] excluded) {

private void containsNone(String failVerb, Iterable<?> excluded) {
Collection<?> actual = iterableToCollection(actual());
Collection<Object> present = new ArrayList<Object>();
Collection<Object> present = new ArrayList<>();
for (Object item : Sets.newLinkedHashSet(excluded)) {
if (actual.contains(item)) {
present.add(item);
Expand Down Expand Up @@ -685,7 +685,7 @@ private void pairwiseCheck(PairwiseChecker checker) {
*/
public <A, E> UsingCorrespondence<A, E> comparingElementsUsing(
Correspondence<A, E> correspondence) {
return new UsingCorrespondence<A, E>(correspondence);
return new UsingCorrespondence<>(correspondence);
}

/**
Expand Down Expand Up @@ -717,7 +717,7 @@ public void contains(@Nullable E expected) {

/** Checks that none of the actual elements correspond to the given element. */
public void doesNotContain(@Nullable E excluded) {
List<A> matchingElements = new ArrayList<A>();
List<A> matchingElements = new ArrayList<>();
for (A actual : getCastActual()) {
if (correspondence.compare(actual, excluded)) {
matchingElements.add(actual);
Expand Down Expand Up @@ -1195,7 +1195,7 @@ public void containsNoneIn(E[] excluded) {

private void containsNone(String excludedPrefix, Iterable<? extends E> excluded) {
Collection<A> actual = iterableToCollection(getCastActual());
Collection<E> present = new ArrayList<E>();
Collection<E> present = new ArrayList<>();
for (E excludedItem : Sets.newLinkedHashSet(excluded)) {
for (A actualItem : actual) {
if (correspondence.compare(actualItem, excludedItem)) {
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/com/google/common/truth/MapSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void containsEntry(@Nullable Object key, @Nullable Object value) {
"Not true that %s contains entry <%s>. However, it has a mapping from <%s> to <%s>",
actualAsString(), entry, key, actual().get(key));
} else if (actual().containsValue(value)) {
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
for (Entry<?, ?> actualEntry : actual().entrySet()) {
if (Objects.equal(actualEntry.getValue(), value)) {
keys.add(actualEntry.getKey());
Expand Down Expand Up @@ -266,22 +266,22 @@ static <K, A, E> MapDifference<K, A, E> create(
Map<? extends K, ? extends A> actual,
Map<? extends K, ? extends E> expected,
ValueTester<? super A, ? super E> valueTester) {
Map<K, A> unexpected = new LinkedHashMap<K, A>(actual);
Map<K, E> missing = new LinkedHashMap<K, E>();
Map<K, ValueDifference<A, E>> wrongValues = new LinkedHashMap<K, ValueDifference<A, E>>();
Map<K, A> unexpected = new LinkedHashMap<>(actual);
Map<K, E> missing = new LinkedHashMap<>();
Map<K, ValueDifference<A, E>> wrongValues = new LinkedHashMap<>();
for (Entry<? extends K, ? extends E> expectedEntry : expected.entrySet()) {
K expectedKey = expectedEntry.getKey();
E expectedValue = expectedEntry.getValue();
if (actual.containsKey(expectedKey)) {
A actualValue = unexpected.remove(expectedKey);
if (!valueTester.test(actualValue, expectedValue)) {
wrongValues.put(expectedKey, new ValueDifference<A, E>(actualValue, expectedValue));
wrongValues.put(expectedKey, new ValueDifference<>(actualValue, expectedValue));
}
} else {
missing.put(expectedKey, expectedValue);
}
}
return new MapDifference<K, A, E>(missing, unexpected, wrongValues);
return new MapDifference<>(missing, unexpected, wrongValues);
}

private MapDifference(
Expand Down Expand Up @@ -450,7 +450,7 @@ public void inOrder() {}
*/
public <A, E> UsingCorrespondence<A, E> comparingValuesUsing(
Correspondence<A, E> correspondence) {
return new UsingCorrespondence<A, E>(correspondence);
return new UsingCorrespondence<>(correspondence);
}

/**
Expand Down Expand Up @@ -487,7 +487,7 @@ public void containsEntry(@Nullable Object expectedKey, @Nullable E expectedValu
actualAsString(), expectedKey, correspondence, expectedValue, actualValue);
} else {
// Did not find matching key.
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
for (Entry<?, A> actualEntry : getCastSubject().entrySet()) {
if (correspondence.compare(actualEntry.getValue(), expectedValue)) {
keys.add(actualEntry.getKey());
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/com/google/common/truth/MultimapSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void containsEntry(@Nullable Object key, @Nullable Object value) {
"Not true that %s contains entry <%s>. However, it has a mapping from <%s> to <%s>",
actualAsString(), entry, key, actual().asMap().get(key));
} else if (actual().containsValue(value)) {
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
for (Entry<?, ?> actualEntry : actual().entries()) {
if (Objects.equal(actualEntry.getValue(), value)) {
keys.add(actualEntry.getKey());
Expand Down Expand Up @@ -398,7 +398,7 @@ private static List<?> difference(List<?> minuend, List<?> subtrahend) {
}

private static <K, V> String countDuplicatesMultimap(Multimap<K, V> multimap) {
List<String> entries = new ArrayList<String>();
List<String> entries = new ArrayList<>();
for (K key : multimap.keySet()) {
entries.add(key + "=" + SubjectUtils.countDuplicates(multimap.get(key)));
}
Expand Down Expand Up @@ -454,7 +454,7 @@ private static <K, V> String countDuplicatesMultimap(Multimap<K, V> multimap) {
*/
public <A, E> UsingCorrespondence<A, E> comparingValuesUsing(
Correspondence<A, E> correspondence) {
return new UsingCorrespondence<A, E>(correspondence);
return new UsingCorrespondence<>(correspondence);
}

/**
Expand Down Expand Up @@ -493,7 +493,7 @@ public void containsEntry(@Nullable Object expectedKey, @Nullable E expectedValu
actualAsString(), expectedKey, correspondence, expectedValue, actualValues);
} else {
// Did not find matching key.
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
for (Entry<?, A> actualEntry : getCastActual().entries()) {
if (correspondence.compare(actualEntry.getValue(), expectedValue)) {
keys.add(actualEntry.getKey());
Expand Down Expand Up @@ -521,7 +521,7 @@ public void containsEntry(@Nullable Object expectedKey, @Nullable E expectedValu
public void doesNotContainEntry(@Nullable Object excludedKey, @Nullable E excludedValue) {
if (actual().containsKey(excludedKey)) {
Collection<A> actualValues = getCastActual().asMap().get(excludedKey);
List<A> matchingValues = new ArrayList<A>();
List<A> matchingValues = new ArrayList<>();
for (A actualValue : actualValues) {
if (correspondence.compare(actualValue, excludedValue)) {
matchingValues.add(actualValue);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/common/truth/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static boolean isInstanceOfTypeJava(Object instance, Class<?> clazz) {
*/
static boolean isInstanceOfTypeGWT(Object instance, Class<?> clazz) {
String className = clazz.getName();
Set<String> types = new LinkedHashSet<String>();
Set<String> types = new LinkedHashSet<>();
types.add(instance.getClass().getCanonicalName());
addTypeNames(instance.getClass(), types);
return types.contains(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void isEqualTo(Object expected, double tolerance) {
Doubles.asList(expectedArray), Doubles.asList(actual));
return;
}
List<Integer> unequalIndices = new ArrayList<Integer>();
List<Integer> unequalIndices = new ArrayList<>();
for (int i = 0; i < expectedArray.length; i++) {
if (!equalWithinTolerance(actual[i], expectedArray[i], tolerance)) {
unequalIndices.add(i);
Expand Down Expand Up @@ -191,7 +191,7 @@ public void isNotEqualTo(Object expectedArray, double tolerance) {
if (expected.length != actual.length) {
return; // Unequal-lengthed arrays are not equal.
}
List<Integer> unequalIndices = new ArrayList<Integer>();
List<Integer> unequalIndices = new ArrayList<>();
for (int i = 0; i < expected.length; i++) {
if (!equalWithinTolerance(actual[i], expected[i], tolerance)) {
unequalIndices.add(i);
Expand Down Expand Up @@ -283,7 +283,7 @@ public TolerantPrimitiveDoubleArrayComparison hasValuesWithin(
public void ofElementsIn(Iterable<? extends Number> expected) {
checkTolerance(tolerance);
double[] actual = checkNotNull(actual());
List<Integer> mismatches = new ArrayList<Integer>();
List<Integer> mismatches = new ArrayList<>();
int expectedCount = 0;
for (Number expectedValue : expected) {
// if expected is longer than actual, we can skip the excess values: this case is covered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void isEqualTo(Object expected, float tolerance) {
Floats.asList(expectedArray), Floats.asList(actual));
return;
}
List<Integer> unequalIndices = new ArrayList<Integer>();
List<Integer> unequalIndices = new ArrayList<>();
for (int i = 0; i < expectedArray.length; i++) {
if (!equalWithinTolerance(actual[i], expectedArray[i], tolerance)) {
unequalIndices.add(i);
Expand Down Expand Up @@ -191,7 +191,7 @@ public void isNotEqualTo(Object expectedArray, float tolerance) {
if (expected.length != actual.length) {
return; // Unequal-lengthed arrays are not equal.
}
List<Integer> unequalIndices = new ArrayList<Integer>();
List<Integer> unequalIndices = new ArrayList<>();
for (int i = 0; i < expected.length; i++) {
if (!equalWithinTolerance(actual[i], expected[i], tolerance)) {
unequalIndices.add(i);
Expand Down Expand Up @@ -283,7 +283,7 @@ public TolerantPrimitiveFloatArrayComparison hasValuesWithin(
public void ofElementsIn(Iterable<? extends Number> expected) {
checkTolerance(tolerance);
float[] actual = checkNotNull(actual());
List<Integer> mismatches = new ArrayList<Integer>();
List<Integer> mismatches = new ArrayList<>();
int expectedCount = 0;
for (Number expectedValue : expected) {
// if expected is longer than actual, we can skip the excess values: this case is covered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void hasFirstEntry(@Nullable Object key, @Nullable Object value) {
+ "but the key is mapped to <%s>, and the first entry is <%s>",
actualAsString(), expectedEntry, actualAsNavigableMap().get(key), actualFirstEntry);
} else if (actualAsNavigableMap().containsValue(value)) {
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
for (Entry<?, ?> actualEntry : actualAsNavigableMap().entrySet()) {
if (Objects.equal(actualEntry.getValue(), value)) {
keys.add(actualEntry.getKey());
Expand Down Expand Up @@ -174,7 +174,7 @@ public void hasLastEntry(@Nullable Object key, @Nullable Object value) {
+ "but the key is mapped to <%s>, and the last entry is <%s>",
actualAsString(), expectedEntry, actualAsNavigableMap().get(key), actualLastEntry);
} else if (actualAsNavigableMap().containsValue(value)) {
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
for (Entry<?, ?> actualEntry : actualAsNavigableMap().entrySet()) {
if (Objects.equal(actualEntry.getValue(), value)) {
keys.add(actualEntry.getKey());
Expand Down Expand Up @@ -220,7 +220,7 @@ static <K, V> NavigableMap<K, V> wrapIfNecessary(SortedMap<K, V> map) {
if (map instanceof NavigableMap) {
return (NavigableMap<K, V>) map;
}
return new SortedMapAsNavigableMap<K, V>(map);
return new SortedMapAsNavigableMap<>(map);
}

SortedMapAsNavigableMap(SortedMap<K, V> delegate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ static void cleanStackTrace(Throwable throwable) {
}

private final Throwable throwable;
private final List<StackTraceElementWrapper> cleanedStackTrace =
new ArrayList<StackTraceElementWrapper>();
private final List<StackTraceElementWrapper> cleanedStackTrace = new ArrayList<>();
private StackTraceElementWrapper lastStackFrameElementWrapper = null;
private StackFrameType currentStreakType = null;
private int currentStreakLength = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public final SortedSetSubject that(@Nullable SortedSet<?> actual) {
}

public final <T> ObjectArraySubject<T> that(@Nullable T[] actual) {
return new ObjectArraySubject<T>(metadata(), actual);
return new ObjectArraySubject<>(metadata(), actual);
}

public final PrimitiveBooleanArraySubject that(@Nullable boolean[] actual) {
Expand Down Expand Up @@ -221,7 +221,7 @@ public final StandardSubjectBuilder withMessage(
*/
public final <S extends Subject<S, A>, A> SimpleSubjectBuilder<S, A> about(
Subject.Factory<S, A> factory) {
return new SimpleSubjectBuilder<S, A>(metadata(), factory);
return new SimpleSubjectBuilder<>(metadata(), factory);
}

public final <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT about(
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/com/google/common/truth/ExpectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void run() {
expect.that(3).isEqualTo(4);
}
};
List<Future<?>> results = new ArrayList<Future<?>>();
List<Future<?>> results = new ArrayList<>();
ExecutorService executor = newFixedThreadPool(10);
for (int i = 0; i < 1000; i++) {
results.add(executor.submit(task));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private class Matching {

/** Constructs the first non-empty matching in the sequence. */
Matching() {
this.edgeStack = new ArrayDeque<Edge>();
this.edgeStack = new ArrayDeque<>();
this.selectedEdges = HashBiMap.create();
if (!edges.isEmpty()) {
Edge firstEdge = new Edge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ public void isEqualToNonMap() {
private static class BrokenMap<K, V> extends ForwardingMap<K, V> {

static <K, V> Map<K, V> wrapWithAlwaysTrueEquals(Map<K, V> delegate) {
return new BrokenMap<K, V>(delegate, true);
return new BrokenMap<>(delegate, true);
}

static <K, V> Map<K, V> wrapWithAlwaysFalseEquals(Map<K, V> delegate) {
return new BrokenMap<K, V>(delegate, false);
return new BrokenMap<>(delegate, false);
}

private final Map<K, V> delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/** In-memory implementation of {@link HrDatabase}, suitable for testing. */
public final class FakeHrDatabase implements HrDatabase {
private final Map<Long, Employee> employees = new HashMap<Long, Employee>();
private final Map<Long, Employee> employees = new HashMap<>();

public void put(Employee employee) {
employees.put(employee.id(), employee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Subject.Factory<MapWithMessageValuesSubject<K, M>, Map<K, M>> mapWithProtoValues
@Override
public MapWithMessageValuesSubject<K, M> createSubject(
FailureMetadata metadata, Map<K, M> actual) {
return new MapWithMessageValuesSubject<K, M>(metadata, config, actual);
return new MapWithMessageValuesSubject<>(metadata, config, actual);
}
};
}
Expand Down Expand Up @@ -211,7 +211,7 @@ MapWithProtoValuesFluentAssertion<M> usingConfig(FluentEqualityConfig newConfig)
if (internalCustomName() != null) {
newSubject = newSubject.named(internalCustomName());
}
return new MapWithProtoValuesFluentAssertionImpl<M>(newSubject);
return new MapWithProtoValuesFluentAssertionImpl<>(newSubject);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.truth.extensions.proto.MessageDifferencer.FieldComparator.ComparisonResult;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor.JavaType;
import com.google.protobuf.Message;
import com.google.protobuf.TextFormat;
import com.google.protobuf.UnknownFieldSet;
import com.google.protobuf.WireFormat;
import com.google.common.truth.extensions.proto.MessageDifferencer.FieldComparator.ComparisonResult;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -101,7 +101,7 @@ public MultipleFieldsMapKeyComparator(List<FieldDescriptor> key) {
}

public MultipleFieldsMapKeyComparator(FieldDescriptor fieldDescriptor) {
keyFields = new LinkedList<FieldDescriptor>();
keyFields = new LinkedList<>();
keyFields.add(fieldDescriptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private MultimapWithMessageValuesSubject(
@Override
public MultimapWithMessageValuesSubject<K, M> createSubject(
FailureMetadata metadata, Multimap<K, M> actual) {
return new MultimapWithMessageValuesSubject<K, M>(metadata, config, actual);
return new MultimapWithMessageValuesSubject<>(metadata, config, actual);
}
};
}
Expand Down Expand Up @@ -168,7 +168,7 @@ static <M extends Message> Subject.Factory<IterableValuesForKey<M>, Iterable<M>>
return new Subject.Factory<IterableValuesForKey<M>, Iterable<M>>() {
@Override
public IterableValuesForKey<M> createSubject(FailureMetadata metadata, Iterable<M> actual) {
return new IterableValuesForKey<M>(metadata, actual, stringRepresentation);
return new IterableValuesForKey<>(metadata, actual, stringRepresentation);
}
};
}
Expand Down Expand Up @@ -254,7 +254,7 @@ MultimapWithProtoValuesFluentAssertion<M> usingConfig(FluentEqualityConfig newCo
if (internalCustomName() != null) {
newSubject = newSubject.named(internalCustomName());
}
return new MultimapWithProtoValuesFluentAssertionImpl<M>(newSubject);
return new MultimapWithProtoValuesFluentAssertionImpl<>(newSubject);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private MessageDifferencer makeDifferencer() {
* #isEqualTo(Object)}.
*/
private class Reporter implements MessageDifferencer.Reporter {
private final List<ReporterRecord> records = new ArrayList<ReporterRecord>();
private final List<ReporterRecord> records = new ArrayList<>();
private boolean anyFailures = false;
private boolean anyNotices = false;

Expand Down
Loading

0 comments on commit 1688736

Please sign in to comment.