Skip to content

Commit 8174fc8

Browse files
committed
Cleanups (templating etc) for Java 7
1 parent 9b34c09 commit 8174fc8

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class IsArrayContainingInAnyOrder<E> extends TypeSafeMatcher<E[]> {
1616
private final Collection<Matcher<? super E>> matchers;
1717

1818
public IsArrayContainingInAnyOrder(Collection<Matcher<? super E>> matchers) {
19-
this.iterableMatcher = new IsIterableContainingInAnyOrder<E>(matchers);
19+
this.iterableMatcher = new IsIterableContainingInAnyOrder<>(matchers);
2020
this.matchers = matchers;
2121
}
2222

@@ -56,6 +56,7 @@ public void describeTo(Description description) {
5656
* @param itemMatchers
5757
* a list of matchers, each of which must be satisfied by an entry in an examined array
5858
*/
59+
@SafeVarargs
5960
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) {
6061
return arrayContainingInAnyOrder(Arrays.asList(itemMatchers));
6162
}
@@ -81,7 +82,7 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... i
8182
* a list of matchers, each of which must be satisfied by an item provided by an examined array
8283
*/
8384
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> itemMatchers) {
84-
return new IsArrayContainingInAnyOrder<E>(itemMatchers);
85+
return new IsArrayContainingInAnyOrder<>(itemMatchers);
8586
}
8687

8788
/**
@@ -102,11 +103,12 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? su
102103
* @param items
103104
* the items that must equal the entries of an examined array, in any order
104105
*/
106+
@SafeVarargs
105107
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
106-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
108+
List<Matcher<? super E>> matchers = new ArrayList<>();
107109
for (E item : items) {
108110
matchers.add(equalTo(item));
109111
}
110-
return new IsArrayContainingInAnyOrder<E>(matchers);
112+
return new IsArrayContainingInAnyOrder<>(matchers);
111113
}
112114
}

hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public IsIterableContainingInAnyOrder(Collection<Matcher<? super T>> matchers) {
2020

2121
@Override
2222
protected boolean matchesSafely(Iterable<? extends T> items, Description mismatchDescription) {
23-
final Matching<T> matching = new Matching<T>(matchers, mismatchDescription);
23+
final Matching<T> matching = new Matching<>(matchers, mismatchDescription);
2424
for (T item : items) {
2525
if (! matching.matches(item)) {
2626
return false;
@@ -42,7 +42,7 @@ private static class Matching<S> {
4242
private final Description mismatchDescription;
4343

4444
public Matching(Collection<Matcher<? super S>> matchers, Description mismatchDescription) {
45-
this.matchers = new ArrayList<Matcher<? super S>>(matchers);
45+
this.matchers = new ArrayList<>(matchers);
4646
this.mismatchDescription = mismatchDescription;
4747
}
4848

@@ -96,6 +96,7 @@ private boolean isMatched(S item) {
9696
* @param itemMatchers
9797
* a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable}
9898
*/
99+
@SafeVarargs
99100
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers) {
100101
return containsInAnyOrder(Arrays.asList(itemMatchers));
101102
}
@@ -120,13 +121,14 @@ public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? su
120121
* @param items
121122
* the items that must equal the items provided by an examined {@link Iterable} in any order
122123
*/
124+
@SafeVarargs
123125
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(T... items) {
124-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
126+
List<Matcher<? super T>> matchers = new ArrayList<>();
125127
for (T item : items) {
126128
matchers.add(equalTo(item));
127129
}
128130

129-
return new IsIterableContainingInAnyOrder<T>(matchers);
131+
return new IsIterableContainingInAnyOrder<>(matchers);
130132
}
131133

132134
/**
@@ -148,7 +150,7 @@ public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(T... items)
148150
* a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable}
149151
*/
150152
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Collection<Matcher<? super T>> itemMatchers) {
151-
return new IsIterableContainingInAnyOrder<T>(itemMatchers);
153+
return new IsIterableContainingInAnyOrder<>(itemMatchers);
152154
}
153155
}
154156

hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010

11-
import static java.util.Arrays.asList;
11+
import static java.util.Collections.singletonList;
1212
import static org.hamcrest.core.IsEqual.equalTo;
1313

1414
public class IsIterableContainingInOrder<E> extends TypeSafeDiagnosingMatcher<Iterable<? extends E>> {
@@ -20,7 +20,7 @@ public IsIterableContainingInOrder(List<Matcher<? super E>> matchers) {
2020

2121
@Override
2222
protected boolean matchesSafely(Iterable<? extends E> iterable, Description mismatchDescription) {
23-
final MatchSeries<E> matchSeries = new MatchSeries<E>(matchers, mismatchDescription);
23+
final MatchSeries<E> matchSeries = new MatchSeries<>(matchers, mismatchDescription);
2424
for (E item : iterable) {
2525
if (!matchSeries.matches(item)) {
2626
return false;
@@ -92,8 +92,9 @@ private void describeMismatch(Matcher<? super F> matcher, F item) {
9292
* @param items
9393
* the items that must equal the items provided by an examined {@link Iterable}
9494
*/
95+
@SafeVarargs
9596
public static <E> Matcher<Iterable<? extends E>> contains(E... items) {
96-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
97+
List<Matcher<? super E>> matchers = new ArrayList<>();
9798
for (E item : items) {
9899
matchers.add(equalTo(item));
99100
}
@@ -114,7 +115,7 @@ public static <E> Matcher<Iterable<? extends E>> contains(E... items) {
114115
*/
115116
@SuppressWarnings("unchecked")
116117
public static <E> Matcher<Iterable<? extends E>> contains(final Matcher<? super E> itemMatcher) {
117-
return contains(new ArrayList<Matcher<? super E>>(asList(itemMatcher)));
118+
return contains(new ArrayList<Matcher<? super E>>(singletonList(itemMatcher)));
118119
}
119120

120121
/**
@@ -128,6 +129,7 @@ public static <E> Matcher<Iterable<? extends E>> contains(final Matcher<? super
128129
* @param itemMatchers
129130
* the matchers that must be satisfied by the items provided by an examined {@link Iterable}
130131
*/
132+
@SafeVarargs
131133
public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>... itemMatchers) {
132134
// required for JDK 1.6
133135
//noinspection RedundantTypeArguments
@@ -148,6 +150,6 @@ public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>...
148150
* an examined {@link Iterable}
149151
*/
150152
public static <E> Matcher<Iterable<? extends E>> contains(List<Matcher<? super E>> itemMatchers) {
151-
return new IsIterableContainingInOrder<E>(itemMatchers);
153+
return new IsIterableContainingInOrder<>(itemMatchers);
152154
}
153155
}

0 commit comments

Comments
 (0)