Skip to content

Commit d03571a

Browse files
committed
Address warnings about verbose code that can be simplified with Java 7 language features
1 parent 026cf0b commit d03571a

44 files changed

Lines changed: 112 additions & 97 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hamcrest-core/src/main/java/org/hamcrest/Condition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
public abstract class Condition<T> {
14-
public static final NotMatched<Object> NOT_MATCHED = new NotMatched<Object>();
14+
public static final NotMatched<Object> NOT_MATCHED = new NotMatched<>();
1515

1616
public interface Step<I, O> {
1717
Condition<O> apply(I value, Description mismatch);
@@ -31,7 +31,7 @@ public static <T> Condition<T> notMatched() {
3131
}
3232

3333
public static <T> Condition<T> matched(final T theValue, final Description mismatch) {
34-
return new Matched<T>(theValue, mismatch);
34+
return new Matched<>(theValue, mismatch);
3535
}
3636

3737
private static final class Matched<T> extends Condition<T> {

hamcrest-core/src/main/java/org/hamcrest/core/CombinableMatcher.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public void describeTo(Description description) {
2828
}
2929

3030
public CombinableMatcher<T> and(Matcher<? super T> other) {
31-
return new CombinableMatcher<T>(new AllOf<T>(templatedListWith(other)));
31+
return new CombinableMatcher<>(new AllOf<>(templatedListWith(other)));
3232
}
3333

3434
public CombinableMatcher<T> or(Matcher<? super T> other) {
35-
return new CombinableMatcher<T>(new AnyOf<T>(templatedListWith(other)));
35+
return new CombinableMatcher<>(new AnyOf<>(templatedListWith(other)));
3636
}
3737

3838
private ArrayList<Matcher<? super T>> templatedListWith(Matcher<? super T> other) {
39-
ArrayList<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
39+
ArrayList<Matcher<? super T>> matchers = new ArrayList<>();
4040
matchers.add(matcher);
4141
matchers.add(other);
4242
return matchers;
@@ -48,7 +48,7 @@ private ArrayList<Matcher<? super T>> templatedListWith(Matcher<? super T> other
4848
* <pre>assertThat("fab", both(containsString("a")).and(containsString("b")))</pre>
4949
*/
5050
public static <LHS> CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher) {
51-
return new CombinableBothMatcher<LHS>(matcher);
51+
return new CombinableBothMatcher<>(matcher);
5252
}
5353

5454
public static final class CombinableBothMatcher<X> {
@@ -57,7 +57,7 @@ public CombinableBothMatcher(Matcher<? super X> matcher) {
5757
this.first = matcher;
5858
}
5959
public CombinableMatcher<X> and(Matcher<? super X> other) {
60-
return new CombinableMatcher<X>(first).and(other);
60+
return new CombinableMatcher<>(first).and(other);
6161
}
6262
}
6363

@@ -67,7 +67,7 @@ public CombinableMatcher<X> and(Matcher<? super X> other) {
6767
* <pre>assertThat("fan", either(containsString("a")).or(containsString("b")))</pre>
6868
*/
6969
public static <LHS> CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher) {
70-
return new CombinableEitherMatcher<LHS>(matcher);
70+
return new CombinableEitherMatcher<>(matcher);
7171
}
7272

7373
public static final class CombinableEitherMatcher<X> {
@@ -76,7 +76,7 @@ public CombinableEitherMatcher(Matcher<? super X> matcher) {
7676
this.first = matcher;
7777
}
7878
public CombinableMatcher<X> or(Matcher<? super X> other) {
79-
return new CombinableMatcher<X>(first).or(other);
79+
return new CombinableMatcher<>(first).or(other);
8080
}
8181
}
8282
}

hamcrest-core/src/main/java/org/hamcrest/core/DescribedAs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public void describeMismatch(Object item, Description description) {
6666
* optional values to insert into the tokenised description
6767
*/
6868
public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) {
69-
return new DescribedAs<T>(description, matcher, values);
69+
return new DescribedAs<>(description, matcher, values);
7070
}
7171
}

hamcrest-core/src/main/java/org/hamcrest/core/Every.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public void describeTo(Description description) {
3939
* the matcher to apply to every item provided by the examined {@link Iterable}
4040
*/
4141
public static <U> Matcher<Iterable<? extends U>> everyItem(final Matcher<U> itemMatcher) {
42-
return new Every<U>(itemMatcher);
42+
return new Every<>(itemMatcher);
4343
}
4444
}

hamcrest-core/src/main/java/org/hamcrest/core/IsAnything.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void describeTo(Description description) {
3636
* Creates a matcher that always matches, regardless of the examined object.
3737
*/
3838
public static Matcher<Object> anything() {
39-
return new IsAnything<Object>();
39+
return new IsAnything<>();
4040
}
4141

4242
/**
@@ -47,6 +47,6 @@ public static Matcher<Object> anything() {
4747
* a meaningful {@link String} used when describing itself
4848
*/
4949
public static Matcher<Object> anything(String description) {
50-
return new IsAnything<Object>(description);
50+
return new IsAnything<>(description);
5151
}
5252
}

hamcrest-core/src/main/java/org/hamcrest/core/IsEqual.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ private static boolean isArray(Object o) {
8686
*
8787
*/
8888
public static <T> Matcher<T> equalTo(T operand) {
89-
return new IsEqual<T>(operand);
89+
return new IsEqual<>(operand);
9090
}
9191

9292
/**
9393
* Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being
9494
* compared to be of the same static type.
9595
*/
9696
public static Matcher<Object> equalToObject(Object operand) {
97-
return new IsEqual<Object>(operand);
97+
return new IsEqual<>(operand);
9898
}
9999
}

hamcrest-core/src/main/java/org/hamcrest/core/IsNot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void describeTo(Description description) {
4040
* the matcher whose sense should be inverted
4141
*/
4242
public static <T> Matcher<T> not(Matcher<T> matcher) {
43-
return new IsNot<T>(matcher);
43+
return new IsNot<>(matcher);
4444
}
4545

4646
/**

hamcrest-core/src/main/java/org/hamcrest/core/IsNull.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void describeTo(Description description) {
2929
*
3030
*/
3131
public static Matcher<Object> nullValue() {
32-
return new IsNull<Object>();
32+
return new IsNull<>();
3333
}
3434

3535
/**
@@ -54,7 +54,7 @@ public static Matcher<Object> notNullValue() {
5454
* dummy parameter used to infer the generic type of the returned matcher
5555
*/
5656
public static <T> Matcher<T> nullValue(Class<T> type) {
57-
return new IsNull<T>();
57+
return new IsNull<>();
5858
}
5959

6060
/**

hamcrest-core/src/main/java/org/hamcrest/core/IsSame.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void describeTo(Description description) {
3737
* the target instance against which others should be assessed
3838
*/
3939
public static <T> Matcher<T> sameInstance(T target) {
40-
return new IsSame<T>(target);
40+
return new IsSame<>(target);
4141
}
4242

4343
/**
@@ -48,6 +48,6 @@ public static <T> Matcher<T> sameInstance(T target) {
4848
* the target instance against which others should be assessed
4949
*/
5050
public static <T> Matcher<T> theInstance(T target) {
51-
return new IsSame<T>(target);
51+
return new IsSame<>(target);
5252
}
5353
}

hamcrest-core/src/main/java/org/hamcrest/internal/NullSafety.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class NullSafety {
1010
@SuppressWarnings("unchecked")
1111
public static <E> List<Matcher<? super E>> nullSafe(Matcher<? super E>[] itemMatchers) {
12-
final List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>(itemMatchers.length);
12+
final List<Matcher<? super E>> matchers = new ArrayList<>(itemMatchers.length);
1313
for (final Matcher<? super E> itemMatcher : itemMatchers) {
1414
matchers.add((Matcher<? super E>) (itemMatcher == null ? IsNull.nullValue() : itemMatcher));
1515
}

0 commit comments

Comments
 (0)