Skip to content

Commit 671612a

Browse files
committed
Duplicated conversion to matchers
1 parent 81f5fe2 commit 671612a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher)
4242
* the element that should be present in examined arrays
4343
*/
4444
public static <T> Matcher<T[]> hasItemInArray(T element) {
45-
Matcher<? super T> matcher = equalTo(element);
46-
return hasItemInArray(matcher);
45+
return hasItemInArray(equalTo(element));
4746
}
4847

4948
/**
@@ -115,11 +114,7 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? su
115114
*/
116115
@SafeVarargs
117116
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
118-
final List<Matcher<? super E>> matchers = new ArrayList<>();
119-
for (E item : items) {
120-
matchers.add(equalTo(item));
121-
}
122-
return arrayContainingInAnyOrder(matchers);
117+
return arrayContainingInAnyOrder(asEqualMatchers(items));
123118
}
124119

125120
/**
@@ -134,13 +129,8 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
134129
*/
135130
@SafeVarargs
136131
public static <E> Matcher<E[]> arrayContaining(E... items) {
137-
List<Matcher<? super E>> matchers = new ArrayList<>();
138-
for (E item : items) {
139-
matchers.add(equalTo(item));
140-
}
141-
return arrayContaining(matchers);
132+
return arrayContaining(asEqualMatchers(items));
142133
}
143-
144134
/**
145135
* Creates a matcher for arrays that matches when each item in the examined array satisfies the
146136
* corresponding matcher in the specified matchers. For a positive match, the examined array
@@ -174,4 +164,13 @@ public static <E> Matcher<E[]> arrayContaining(List<Matcher<? super E>> itemMatc
174164
return new ArrayMatcher<>(new IsIterableContainingInOrder<>(itemMatchers), itemMatchers, "");
175165
}
176166

167+
168+
private static <E> List<Matcher<? super E>> asEqualMatchers(E[] items) {
169+
final List<Matcher<? super E>> matchers = new ArrayList<>();
170+
for (E item : items) {
171+
matchers.add(equalTo(item));
172+
}
173+
return matchers;
174+
}
177175
}
176+

0 commit comments

Comments
 (0)