diff --git a/src/main/java/org/apache/commons/lang3/CharSet.java b/src/main/java/org/apache/commons/lang3/CharSet.java index 27e946425..6cf0246f2 100644 --- a/src/main/java/org/apache/commons/lang3/CharSet.java +++ b/src/main/java/org/apache/commons/lang3/CharSet.java @@ -75,7 +75,7 @@ public class CharSet implements Serializable { * Subclasses can add more common patterns if desired * @since 2.0 */ - protected static final Map COMMON = Collections.synchronizedMap(new HashMap()); + protected static final Map COMMON = Collections.synchronizedMap(new HashMap<>()); static { COMMON.put(null, EMPTY); @@ -88,7 +88,7 @@ public class CharSet implements Serializable { } /** The set of CharRange objects. */ - private final Set set = Collections.synchronizedSet(new HashSet()); + private final Set set = Collections.synchronizedSet(new HashSet<>()); //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index be9f0ddb5..28500a554 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -1383,7 +1383,7 @@ public static Iterable> hierarchy(final Class type, final Interfaces @Override public Iterator> iterator() { - final MutableObject> next = new MutableObject>(type); + final MutableObject> next = new MutableObject<>(type); return new Iterator>() { @Override diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java index c3b4a033e..5874f5942 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java @@ -903,7 +903,7 @@ public static List getMethodsListWithAnnotation(final Class cls, Validate.isTrue(cls != null, "The class must not be null"); Validate.isTrue(annotationCls != null, "The annotation class must not be null"); final List> classes = (searchSupers ? getAllSuperclassesAndInterfaces(cls) - : new ArrayList>()); + : new ArrayList<>()); classes.add(0, cls); final List annotatedMethods = new ArrayList<>(); for (final Class acls : classes) { diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java index 037c3a4b7..0ec0fb6bc 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java @@ -864,7 +864,7 @@ private static Map, Type> getTypeArguments( getRawType(parameterizedOwnerType), subtypeVarAssigns); } else { // no owner, prep the type variable assignments map - typeVarAssigns = subtypeVarAssigns == null ? new HashMap, Type>() + typeVarAssigns = subtypeVarAssigns == null ? new HashMap<>() : new HashMap<>(subtypeVarAssigns); } @@ -918,7 +918,7 @@ private static Map, Type> getTypeArguments(Class cls, final C } // create a copy of the incoming map, or an empty one if it's null - final HashMap, Type> typeVarAssigns = subtypeVarAssigns == null ? new HashMap, Type>() + final HashMap, Type> typeVarAssigns = subtypeVarAssigns == null ? new HashMap<>() : new HashMap<>(subtypeVarAssigns); // has target class been reached? diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java index 2ec631fcb..e12ac3fbe 100644 --- a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java @@ -207,13 +207,13 @@ public void testHashCodeMulti_multiple_likeList() { final List list0 = new ArrayList<>(Arrays.asList(new Object[0])); assertEquals(list0.hashCode(), ObjectUtils.hashCodeMulti()); - final List list1 = new ArrayList(Arrays.asList("a")); + final List list1 = new ArrayList<>(Arrays.asList("a")); assertEquals(list1.hashCode(), ObjectUtils.hashCodeMulti("a")); - final List list2 = new ArrayList(Arrays.asList("a", "b")); + final List list2 = new ArrayList<>(Arrays.asList("a", "b")); assertEquals(list2.hashCode(), ObjectUtils.hashCodeMulti("a", "b")); - final List list3 = new ArrayList(Arrays.asList("a", "b", "c")); + final List list3 = new ArrayList<>(Arrays.asList("a", "b", "c")); assertEquals(list3.hashCode(), ObjectUtils.hashCodeMulti("a", "b", "c")); } diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java index 05f1da9a8..00c463a84 100644 --- a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java @@ -433,9 +433,9 @@ public void testObjectBuild() { @Test public void testObjectRecursiveGenericInteger() { - final TestRecursiveGenericObject o1_a = new TestRecursiveGenericObject(1); - final TestRecursiveGenericObject o1_b = new TestRecursiveGenericObject(1); - final TestRecursiveGenericObject o2 = new TestRecursiveGenericObject(2); + final TestRecursiveGenericObject o1_a = new TestRecursiveGenericObject<>(1); + final TestRecursiveGenericObject o1_b = new TestRecursiveGenericObject<>(1); + final TestRecursiveGenericObject o2 = new TestRecursiveGenericObject<>(2); assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1_a, o1_b).isEquals()); assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1_b, o1_a).isEquals()); @@ -447,9 +447,9 @@ public void testObjectRecursiveGenericInteger() { public void testObjectRecursiveGenericString() { // Note: Do not use literals, because string literals are always mapped by same object (internal() of String))! String s1_a = String.valueOf(1); - final TestRecursiveGenericObject o1_a = new TestRecursiveGenericObject(s1_a); - final TestRecursiveGenericObject o1_b = new TestRecursiveGenericObject(String.valueOf(1)); - final TestRecursiveGenericObject o2 = new TestRecursiveGenericObject(String.valueOf(2)); + final TestRecursiveGenericObject o1_a = new TestRecursiveGenericObject<>(s1_a); + final TestRecursiveGenericObject o1_b = new TestRecursiveGenericObject<>(String.valueOf(1)); + final TestRecursiveGenericObject o2 = new TestRecursiveGenericObject<>(String.valueOf(2)); // To trigger bug reported in LANG-1356, call hashCode only on string in instance o1_a s1_a.hashCode(); diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java index 6f076505f..daa5111ab 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java @@ -65,19 +65,19 @@ static class CollectionHolder> { @Test @Ignore public void testLinkedList() throws InterruptedException, ExecutionException { - this.testConcurrency(new CollectionHolder>(new LinkedList())); + this.testConcurrency(new CollectionHolder<>(new LinkedList<>())); } @Test @Ignore public void testArrayList() throws InterruptedException, ExecutionException { - this.testConcurrency(new CollectionHolder>(new ArrayList())); + this.testConcurrency(new CollectionHolder<>(new ArrayList<>())); } @Test @Ignore public void testCopyOnWriteArrayList() throws InterruptedException, ExecutionException { - this.testConcurrency(new CollectionHolder>(new CopyOnWriteArrayList())); + this.testConcurrency(new CollectionHolder<>(new CopyOnWriteArrayList<>())); } private void testConcurrency(final CollectionHolder> holder) throws InterruptedException, diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java index c0fa90112..49c131a58 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java @@ -104,7 +104,7 @@ public void test_toStringExcludeEmptyArray() { @Test public void test_toStringExcludeEmptyCollection() { - final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), new ArrayList()); + final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), new ArrayList<>()); this.validateSecretFieldPresent(toString); } diff --git a/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java b/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java index 83fa06836..12bcdb43f 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java @@ -68,17 +68,17 @@ static class CollectionHolder> { @Test public void testLinkedList() throws InterruptedException, ExecutionException { - this.testConcurrency(new CollectionHolder>(new LinkedList())); + this.testConcurrency(new CollectionHolder<>(new LinkedList<>())); } @Test public void testArrayList() throws InterruptedException, ExecutionException { - this.testConcurrency(new CollectionHolder>(new ArrayList())); + this.testConcurrency(new CollectionHolder<>(new ArrayList<>())); } @Test public void testCopyOnWriteArrayList() throws InterruptedException, ExecutionException { - this.testConcurrency(new CollectionHolder>(new CopyOnWriteArrayList())); + this.testConcurrency(new CollectionHolder<>(new CopyOnWriteArrayList<>())); } private void testConcurrency(final CollectionHolder> holder) throws InterruptedException, diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java index 6cbf1839e..004a92e1b 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java @@ -580,7 +580,7 @@ public void testCreateIfAbsentUncheckedException() EasyMock.replay(init); try { ConcurrentUtils.createIfAbsentUnchecked( - new ConcurrentHashMap(), "test", init); + new ConcurrentHashMap<>(), "test", init); fail("Exception not thrown!"); } catch (final ConcurrentRuntimeException crex) { assertEquals("Wrong cause", ex, crex.getCause()); diff --git a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java index 0496664c5..f5ea7a7ff 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java @@ -275,19 +275,19 @@ public static String numOverload(final Number... args) { // not only is the correct overloaded variant invoked, but that the varags arguments // are also delivered correctly to the method. public ImmutablePair varOverloadEcho(final String... args) { - return new ImmutablePair("String...", args); + return new ImmutablePair<>("String...", args); } public ImmutablePair varOverloadEcho(final Number... args) { - return new ImmutablePair("Number...", args); + return new ImmutablePair<>("Number...", args); } public static ImmutablePair varOverloadEchoStatic(final String... args) { - return new ImmutablePair("String...", args); + return new ImmutablePair<>("String...", args); } public static ImmutablePair varOverloadEchoStatic(final Number... args) { - return new ImmutablePair("Number...", args); + return new ImmutablePair<>("Number...", args); } static void verify(final ImmutablePair a, final ImmutablePair b) { @@ -441,13 +441,13 @@ public void testInvokeMethod() throws Exception { } catch (final NoSuchMethodException expected) { } - TestBean.verify(new ImmutablePair("String...", new String[]{"x", "y"}), + TestBean.verify(new ImmutablePair<>("String...", new String[]{"x", "y"}), MethodUtils.invokeMethod(testBean, "varOverloadEcho", "x", "y")); - TestBean.verify(new ImmutablePair("Number...", new Number[]{17, 23, 42}), + TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}), MethodUtils.invokeMethod(testBean, "varOverloadEcho", 17, 23, 42)); - TestBean.verify(new ImmutablePair("String...", new String[]{"x", "y"}), + TestBean.verify(new ImmutablePair<>("String...", new String[]{"x", "y"}), MethodUtils.invokeMethod(testBean, "varOverloadEcho", "x", "y")); - TestBean.verify(new ImmutablePair("Number...", new Number[]{17, 23, 42}), + TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}), MethodUtils.invokeMethod(testBean, "varOverloadEcho", 17, 23, 42)); } @@ -516,13 +516,13 @@ public void testInvokeStaticMethod() throws Exception { assertEquals("bar(int, String...)", MethodUtils.invokeStaticMethod( TestBean.class, "bar", NumberUtils.INTEGER_ONE, "a", "b")); - TestBean.verify(new ImmutablePair("String...", new String[]{"x", "y"}), + TestBean.verify(new ImmutablePair<>("String...", new String[]{"x", "y"}), MethodUtils.invokeStaticMethod(TestBean.class, "varOverloadEchoStatic", "x", "y")); - TestBean.verify(new ImmutablePair("Number...", new Number[]{17, 23, 42}), + TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}), MethodUtils.invokeStaticMethod(TestBean.class, "varOverloadEchoStatic", 17, 23, 42)); - TestBean.verify(new ImmutablePair("String...", new String[]{"x", "y"}), + TestBean.verify(new ImmutablePair<>("String...", new String[]{"x", "y"}), MethodUtils.invokeStaticMethod(TestBean.class, "varOverloadEchoStatic", "x", "y")); - TestBean.verify(new ImmutablePair("Number...", new Number[]{17, 23, 42}), + TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}), MethodUtils.invokeStaticMethod(TestBean.class, "varOverloadEchoStatic", 17, 23, 42)); try { diff --git a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java index a9bb9fab6..7bd5380ab 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java @@ -430,7 +430,7 @@ public void testIsAssignable() throws SecurityException, NoSuchMethodException, final Type dClassType = AClass.class.getField("dClass").getGenericType(); final Type eClassType = AClass.class.getField("eClass").getGenericType(); final Type fClassType = AClass.class.getField("fClass").getGenericType(); - final AClass aClass = new AClass(new AAClass()); + final AClass aClass = new AClass(new AAClass<>()); aClass.bClass = aClass.cClass; assertTrue(TypeUtils.isAssignable(cClassType, bClassType)); aClass.bClass = aClass.dClass;