[groovy] branch GROOVY_3_0_X updated: Refactor DGM (add Diamond usage) (closes #1202)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[groovy] branch GROOVY_3_0_X updated: Refactor DGM (add Diamond usage) (closes #1202)

paulk
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 88e1306  Refactor DGM (add Diamond usage) (closes #1202)
88e1306 is described below

commit 88e13066b1d624b82d67cfab9bdcfb54d1f031b3
Author: Dario Arena <[hidden email]>
AuthorDate: Sun Mar 22 13:23:59 2020 +0100

    Refactor DGM (add Diamond usage) (closes #1202)
---
 .../groovy/runtime/DefaultGroovyMethods.java       | 291 ++++++++++-----------
 1 file changed, 145 insertions(+), 146 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index e548382..51757aa 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -216,7 +216,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 //            NioExtensions.class
     };
     private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-    private static final NumberAwareComparator<Comparable> COMPARABLE_NUMBER_AWARE_COMPARATOR = new NumberAwareComparator<Comparable>();
+    private static final NumberAwareComparator<Comparable> COMPARABLE_NUMBER_AWARE_COMPARATOR = new NumberAwareComparator<>();
 
     /**
      * Identity check. Since == is overridden in Groovy with the meaning of equality
@@ -326,7 +326,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * <pre>
      * def fullName = person.with(false){ "$firstName $lastName" }
      * </pre>
-     * Alternatively, 'with' is an alias for 'with(false)', so the boolean parameter can be ommitted instead.
+     * Alternatively, 'with' is an alias for 'with(false)', so the boolean parameter can be omitted instead.
      *
      * @param self      the object to have a closure act upon
      * @param returning if true, return the self object; otherwise, the result of calling the closure
@@ -512,7 +512,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     public static List<PropertyValue> getMetaPropertyValues(Object self) {
         MetaClass metaClass = InvokerHelper.getMetaClass(self);
         List<MetaProperty> mps = metaClass.getProperties();
-        List<PropertyValue> props = new ArrayList<PropertyValue>(mps.size());
+        List<PropertyValue> props = new ArrayList<>(mps.size());
         for (MetaProperty mp : mps) {
             props.add(new PropertyValue(self, mp));
         }
@@ -530,7 +530,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static Map getProperties(Object self) {
         List<PropertyValue> metaProps = getMetaPropertyValues(self);
-        Map<String, Object> props = new LinkedHashMap<String, Object>(metaProps.size());
+        Map<String, Object> props = new LinkedHashMap<>(metaProps.size());
 
         for (PropertyValue mp : metaProps) {
             try {
@@ -681,7 +681,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         } catch (ClassCastException e) {
             throw new IllegalArgumentException("Expecting a Closure to be the last argument");
         }
-        List<Class> list = new ArrayList<Class>(array.length - 1);
+        List<Class> list = new ArrayList<>(array.length - 1);
         for (int i = 0; i < array.length - 1; ++i) {
             Class categoryClass;
             try {
@@ -1218,7 +1218,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.5
      */
     public static <T> Iterator<T> unique(Iterator<T> self) {
-        return uniqueItems(new IteratorIterableAdapter<T>(self)).listIterator();
+        return uniqueItems(new IteratorIterableAdapter<>(self)).listIterator();
     }
 
     /**
@@ -1278,7 +1278,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     }
 
     private static <T> List<T> uniqueItems(Iterable<T> self) {
-        List<T> answer = new ArrayList<T>();
+        List<T> answer = new ArrayList<>();
         for (T t : self) {
             boolean duplicated = false;
             for (T t2 : answer) {
@@ -1348,8 +1348,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> Iterator<T> unique(Iterator<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure condition) {
         Comparator<T> comparator = condition.getMaximumNumberOfParameters() == 1
-                ? new OrderBy<T>(condition, true)
-                : new ClosureComparator<T>(condition);
+                ? new OrderBy<>(condition, true)
+                : new ClosureComparator<>(condition);
         return unique(self, comparator);
     }
 
@@ -1432,9 +1432,9 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         // use a comparator of one item or two
         int params = closure.getMaximumNumberOfParameters();
         if (params == 1) {
-            self = unique(self, mutate, new OrderBy<T>(closure, true));
+            self = unique(self, mutate, new OrderBy<>(closure, true));
         } else {
-            self = unique(self, mutate, new ClosureComparator<T>(closure));
+            self = unique(self, mutate, new ClosureComparator<>(closure));
         }
         return self;
     }
@@ -1481,7 +1481,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.5
      */
     public static <T> Iterator<T> unique(Iterator<T> self, Comparator<T> comparator) {
-        return uniqueItems(new IteratorIterableAdapter<T>(self), comparator).listIterator();
+        return uniqueItems(new IteratorIterableAdapter<>(self), comparator).listIterator();
     }
 
     private static final class IteratorIterableAdapter<T> implements Iterable<T> {
@@ -1656,7 +1656,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     }
 
     private static <T> List<T> uniqueItems(Iterable<T> self, Comparator<T> comparator) {
-        List<T> answer = new ArrayList<T>();
+        List<T> answer = new ArrayList<>();
         for (T t : self) {
             boolean duplicated = false;
             for (T t2 : answer) {
@@ -1748,8 +1748,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> Iterator<T> toUnique(Iterator<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure condition) {
         return toUnique(self, condition.getMaximumNumberOfParameters() == 1
-                ? new OrderBy<T>(condition, true)
-                : new ClosureComparator<T>(condition));
+                ? new OrderBy<>(condition, true)
+                : new ClosureComparator<>(condition));
     }
 
     private static final class ToUniqueIterator<E> implements Iterator<E> {
@@ -1760,7 +1760,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 
         private ToUniqueIterator(Iterator<E> delegate, Comparator<E> comparator) {
             this.delegate = delegate;
-            seen = new TreeSet<E>(comparator);
+            seen = new TreeSet<>(comparator);
             advance();
         }
 
@@ -1803,7 +1803,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> Iterator<T> toUnique(Iterator<T> self, Comparator<T> comparator) {
-        return new ToUniqueIterator<T>(self, comparator);
+        return new ToUniqueIterator<>(self, comparator);
     }
 
     /**
@@ -1993,8 +1993,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> Collection<T> toUnique(Iterable<T> self, @ClosureParams(value = FromString.class, options = {"T", "T,T"}) Closure condition) {
         Comparator<T> comparator = condition.getMaximumNumberOfParameters() == 1
-                ? new OrderBy<T>(condition, true)
-                : new ClosureComparator<T>(condition);
+                ? new OrderBy<>(condition, true)
+                : new ClosureComparator<>(condition);
         return toUnique(self, comparator);
     }
 
@@ -2057,7 +2057,6 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      *        If {@code null}, the Comparable natural ordering of the elements will be used.
      * @return the unique items from the array
      */
-    @SuppressWarnings("unchecked")
     public static <T> T[] toUnique(T[] self, Comparator<T> comparator) {
         Collection<T> items = toUnique(toList(self), comparator);
         T[] result = createSimilarArray(self, items.size());
@@ -2099,11 +2098,10 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @param condition a Closure used to determine unique items
      * @return the unique items from the array
      */
-    @SuppressWarnings("unchecked")
     public static <T> T[] toUnique(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure condition) {
         Comparator<T> comparator = condition.getMaximumNumberOfParameters() == 1
-                ? new OrderBy<T>(condition, true)
-                : new ClosureComparator<T>(condition);
+                ? new OrderBy<>(condition, true)
+                : new ClosureComparator<>(condition);
         return toUnique(self, comparator);
     }
 
@@ -2459,7 +2457,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.0
      */
     public static <T> List<T> reverseEach(List<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) {
-        each(new ReverseListIterator<T>(self), closure);
+        each(new ReverseListIterator<>(self), closure);
         return self;
     }
 
@@ -2472,7 +2470,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.2
      */
     public static <T> T[] reverseEach(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
-        each(new ReverseListIterator<T>(Arrays.asList(self)), closure);
+        each(new ReverseListIterator<>(Arrays.asList(self)), closure);
         return self;
     }
 
@@ -2526,7 +2524,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> boolean every(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
-        return every(new ArrayIterator<T>(self), predicate);
+        return every(new ArrayIterator<>(self), predicate);
     }
 
     /**
@@ -2660,7 +2658,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> boolean any(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
-        return any(new ArrayIterator<T>(self), predicate);
+        return any(new ArrayIterator<>(self), predicate);
     }
 
     /**
@@ -2840,7 +2838,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.0
      */
     public static <T> Collection<T> grep(T[] self, Object filter) {
-        Collection<T> answer = new ArrayList<T>();
+        Collection<T> answer = new ArrayList<>();
         BooleanReturningMethodInvoker bmi = new BooleanReturningMethodInvoker("isCase");
         for (T element : self) {
             if (bmi.invoke(filter, element)) {
@@ -2941,7 +2939,6 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @see Closure#IDENTITY
      * @since 2.0
      */
-    @SuppressWarnings("unchecked")
     public static <T> Collection<T> grep(T[] self) {
         return grep(self, Closure.IDENTITY);
     }
@@ -3231,7 +3228,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.0
      */
     public static <T> List<T> toList(Iterator<T> self) {
-        List<T> answer = new ArrayList<T>();
+
+        List<T> answer = new ArrayList<>();
         while (self.hasNext()) {
             answer.add(self.next());
         }
@@ -3263,7 +3261,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.0
      */
     public static <T> List<T> toList(Enumeration<T> self) {
-        List<T> answer = new ArrayList<T>();
+        List<T> answer = new ArrayList<>();
         while (self.hasMoreElements()) {
             answer.add(self.nextElement());
         }
@@ -3415,7 +3413,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> List<List<T>> collate(Iterable<T> self, int size, int step, boolean keepRemainder) {
         List<T> selfList = asList(self);
-        List<List<T>> answer = new ArrayList<List<T>>();
+        List<List<T>> answer = new ArrayList<>();
         if (size <= 0) {
             answer.add(selfList);
         } else {
@@ -3424,7 +3422,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
                 if (!keepRemainder && pos > selfList.size() - size) {
                     break ;
                 }
-                List<T> element = new ArrayList<T>() ;
+                List<T> element = new ArrayList<>() ;
                 for (int offs = pos; offs < pos + size && offs < selfList.size(); offs++) {
                     element.add(selfList.get(offs));
                 }
@@ -3486,7 +3484,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T> List<T> collect(Object self, Closure<T> transform) {
-        return (List<T>) collect(self, new ArrayList<T>(), transform);
+        return (List<T>) collect(self, new ArrayList<>(), transform);
     }
 
     /**
@@ -3513,7 +3511,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <S,T> List<T> collect(S[] self, @ClosureParams(FirstParam.Component.class) Closure<T> transform) {
-        return collect(new ArrayIterator<S>(self), transform);
+        return collect(new ArrayIterator<>(self), transform);
     }
 
     /**
@@ -3533,7 +3531,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <S,T> Collection<T> collect(S[] self, Collection<T> collector, @ClosureParams(FirstParam.Component.class) Closure<? extends T> transform) {
-        return collect(new ArrayIterator<S>(self), collector, transform);
+        return collect(new ArrayIterator<>(self), collector, transform);
     }
 
     /**
@@ -3546,7 +3544,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <S,T> List<T> collect(Iterator<S> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> transform) {
-        return (List<T>) collect(self, new ArrayList<T>(), transform);
+        return (List<T>) collect(self, new ArrayList<>(), transform);
     }
 
     /**
@@ -3812,7 +3810,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.2.0
      */
     public static <T,E> List<T> collectMany(Iterable<E> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<? extends Collection<? extends T>> projection) {
-        return (List<T>) collectMany(self, new ArrayList<T>(), projection);
+        return (List<T>) collectMany(self, new ArrayList<>(), projection);
     }
 
     /**
@@ -3881,7 +3879,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.8
      */
     public static <T,K,V> Collection<T> collectMany(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<? extends Collection<? extends T>> projection) {
-        return collectMany(self, new ArrayList<T>(), projection);
+        return collectMany(self, new ArrayList<>(), projection);
     }
 
     /**
@@ -3955,7 +3953,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T,K,V> List<T> collect(Map<K,V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<T> transform) {
-        return (List<T>) collect(self, new ArrayList<T>(self.size()), transform);
+        return (List<T>) collect(self, new ArrayList<>(self.size()), transform);
     }
 
     /**
@@ -4031,7 +4029,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.7
      */
     public static <K, V, E> Map<K, V> collectEntries(Iterator<E> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<?> transform) {
-        return collectEntries(self, new LinkedHashMap<K, V>(), transform);
+        return collectEntries(self, new LinkedHashMap<>(), transform);
     }
 
     /**
@@ -4570,7 +4568,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <S, T, U extends T, V extends T> T findResult(S[] self, U defaultResult, @ClosureParams(FirstParam.Component.class) Closure<V> condition) {
-        return findResult(new ArrayIterator<S>(self), defaultResult, condition);
+        return findResult(new ArrayIterator<>(self), defaultResult, condition);
     }
 
     /**
@@ -4583,7 +4581,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <S, T> T findResult(S[] self, @ClosureParams(FirstParam.Component.class) Closure<T> condition) {
-        return findResult(new ArrayIterator<S>(self), condition);
+        return findResult(new ArrayIterator<>(self), condition);
     }
 
     /**
@@ -4673,7 +4671,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T, U> Collection<T> findResults(Iterator<U> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> filteringTransform) {
-        List<T> result = new ArrayList<T>();
+        List<T> result = new ArrayList<>();
         while (self.hasNext()) {
             U value = self.next();
             T transformed = filteringTransform.call(value);
@@ -4694,7 +4692,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T, U> Collection<T> findResults(U[] self, @ClosureParams(FirstParam.Component.class) Closure<T> filteringTransform) {
-        return findResults(new ArrayIterator<U>(self), filteringTransform);
+        return findResults(new ArrayIterator<>(self), filteringTransform);
     }
 
     /**
@@ -4716,7 +4714,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.1
      */
     public static <T, K, V> Collection<T> findResults(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<T> filteringTransform) {
-        List<T> result = new ArrayList<T>();
+        List<T> result = new ArrayList<>();
         for (Map.Entry<K, V> entry : self.entrySet()) {
             T transformed = callClosureForMapEntry(filteringTransform, entry);
             if (transformed != null) {
@@ -4801,8 +4799,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.0
      */
     public static <T> Collection<T> findAll(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
-        Collection<T> answer = new ArrayList<T>();
-        return findAll(condition, answer, new ArrayIterator<T>(self));
+        Collection<T> answer = new ArrayList<>();
+        return findAll(condition, answer, new ArrayIterator<>(self));
     }
 
     /**
@@ -5219,14 +5217,14 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> Collection<Collection<T>> split(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
-        List<T> accept = new ArrayList<T>();
-        List<T> reject = new ArrayList<T>();
-        Iterator<T> iter = new ArrayIterator<T>(self);
+        List<T> accept = new ArrayList<>();
+        List<T> reject = new ArrayList<>();
+        Iterator<T> iter = new ArrayIterator<>(self);
         return split(closure, accept, reject, iter);
     }
 
     private static <T> Collection<Collection<T>> split(Closure closure, Collection<T> accept, Collection<T> reject, Iterator<T> iter) {
-        List<Collection<T>> answer = new ArrayList<Collection<T>>();
+        List<Collection<T>> answer = new ArrayList<>();
         BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
         while (iter.hasNext()) {
             T value = iter.next();
@@ -5363,8 +5361,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.7.0
      */
     public static <T> Set<List<T>> permutations(Iterable<T> self) {
-        Set<List<T>> ans = new HashSet<List<T>>();
-        PermutationGenerator<T> generator = new PermutationGenerator<T>(self);
+        Set<List<T>> ans = new HashSet<>();
+        PermutationGenerator<T> generator = new PermutationGenerator<>(self);
         while (generator.hasNext()) {
             ans.add(generator.next());
         }
@@ -5432,7 +5430,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.7.0
      */
     public static <T> Iterator<List<T>> eachPermutation(Iterable<T> self, Closure closure) {
-        Iterator<List<T>> generator = new PermutationGenerator<T>(self);
+        Iterator<List<T>> generator = new PermutationGenerator<>(self);
         while (generator.hasNext()) {
             closure.call(generator.next());
         }
@@ -5521,7 +5519,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.2.0
      */
     public static <K, T> Map<K, List<T>> groupBy(Iterable<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<K> closure) {
-        Map<K, List<T>> answer = new LinkedHashMap<K, List<T>>();
+        Map<K, List<T>> answer = new LinkedHashMap<>();
         for (T element : self) {
             K value = closure.call(element);
             groupAnswer(answer, element, value);
@@ -5603,7 +5601,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         System.arraycopy(closures, 1, tail, 0, closures.length - 1); // Arrays.copyOfRange only since JDK 1.6
 
         // inject([:]) { a,e {@code ->} a {@code <<} [(e.key): e.value.groupBy(tail)] }
-        Map<Object, Map> acc = new LinkedHashMap<Object, Map>();
+        Map<Object, Map> acc = new LinkedHashMap<>();
         for (Map.Entry<Object, List> item : first.entrySet()) {
             acc.put(item.getKey(), groupBy((Iterable)item.getValue(), tail));
         }
@@ -5755,7 +5753,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.0
      */
     public static <K,E> Map<K, Integer> countBy(Iterator<E> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<K> closure) {
-        Map<K, Integer> answer = new LinkedHashMap<K, Integer>();
+        Map<K, Integer> answer = new LinkedHashMap<>();
         while (self.hasNext()) {
             K value = closure.call(self.next());
             countAnswer(answer, value);
@@ -5782,7 +5780,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.2
      */
     public static <G, K, V> Map<G, List<Map.Entry<K, V>>> groupEntriesBy(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<G> closure) {
-        final Map<G, List<Map.Entry<K, V>>> answer = new LinkedHashMap<G, List<Map.Entry<K, V>>>();
+        final Map<G, List<Map.Entry<K, V>>> answer = new LinkedHashMap<>();
         for (Map.Entry<K, V> entry : self.entrySet()) {
             G value = callClosureForMapEntry(closure, entry);
             groupAnswer(answer, entry, value);
@@ -5813,7 +5811,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <G, K, V> Map<G, Map<K, V>> groupBy(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<G> closure) {
         final Map<G, List<Map.Entry<K, V>>> initial = groupEntriesBy(self, closure);
-        final Map<G, Map<K, V>> answer = new LinkedHashMap<G, Map<K, V>>();
+        final Map<G, Map<K, V>> answer = new LinkedHashMap<>();
         for (Map.Entry<G, List<Map.Entry<K, V>>> outer : initial.entrySet()) {
             G key = outer.getKey();
             List<Map.Entry<K, V>> entries = outer.getValue();
@@ -5859,7 +5857,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         final Object[] tail = new Object[closures.length - 1];
         System.arraycopy(closures, 1, tail, 0, closures.length - 1); // Arrays.copyOfRange only since JDK 1.6
 
-        Map<Object, Map> acc = new LinkedHashMap<Object, Map>();
+        Map<Object, Map> acc = new LinkedHashMap<>();
         for (Map.Entry<Object, Map> item: first.entrySet()) {
             acc.put(item.getKey(), groupBy(item.getValue(), tail));
         }
@@ -5912,7 +5910,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.0
      */
     public static <K,U,V> Map<K, Integer> countBy(Map<U,V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<K> closure) {
-        Map<K, Integer> answer = new LinkedHashMap<K, Integer>();
+        Map<K, Integer> answer = new LinkedHashMap<>();
         for (Map.Entry<U,V> entry : self.entrySet()) {
             countAnswer(answer, callClosureForMapEntry(closure, entry));
         }
@@ -5928,7 +5926,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.0
      */
     protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) {
-        List<T> groupedElements = answer.computeIfAbsent(value, k -> new ArrayList<T>());
+        List<T> groupedElements = answer.computeIfAbsent(value, k -> new ArrayList<>());
 
         groupedElements.add(element);
     }
@@ -6548,7 +6546,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.7.1
      */
     public static <T> Object sum(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
-        return sum(new ArrayIterator<T>(self), null, closure, true);
+        return sum(new ArrayIterator<>(self), null, closure, true);
     }
 
     /**
@@ -6607,7 +6605,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.7.1
      */
     public static <T> Object sum(T[] self, Object initialValue, @ClosureParams(FirstParam.Component.class) Closure closure) {
-        return sum(new ArrayIterator<T>(self), initialValue, closure, false);
+        return sum(new ArrayIterator<>(self), initialValue, closure, false);
     }
 
     /**
@@ -6851,7 +6849,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 3.0.0
      */
     public static <T> Object average(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
-        return average(new ArrayIterator<T>(self), closure);
+        return average(new ArrayIterator<>(self), closure);
     }
 
     /**
@@ -7334,7 +7332,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     public static <T> T min(Iterable<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
         int params = closure.getMaximumNumberOfParameters();
         if (params != 1) {
-            return min(self, new ClosureComparator<T>(closure));
+            return min(self, new ClosureComparator<>(closure));
         }
         boolean first = true;
         T answer = null;
@@ -7567,7 +7565,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     public static <T> T max(Iterable<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
         int params = closure.getMaximumNumberOfParameters();
         if (params != 1) {
-            return max(self, new ClosureComparator<T>(closure));
+            return max(self, new ClosureComparator<>(closure));
         }
         boolean first = true;
         T answer = null;
@@ -7828,7 +7826,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     @SuppressWarnings("unchecked")
     public static <T> List<T> getAt(ListWithDefault<T> self, Collection indices) {
-        List<T> answer = ListWithDefault.newInstance(new ArrayList<T>(indices.size()), self.isLazyDefaultValues(), self.getInitClosure());
+        List<T> answer = ListWithDefault.newInstance(new ArrayList<>(indices.size()), self.isLazyDefaultValues(), self.getInitClosure());
         for (Object value : indices) {
             if (value instanceof Collection) {
                 answer.addAll((List<T>) InvokerHelper.invokeMethod(self, "getAt", value));
@@ -7864,7 +7862,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
             answer =  ListWithDefault.newInstance(reverse(answer), self.isLazyDefaultValues(), self.getInitClosure());
         } else {
             // instead of using the SubList backed by the parent list, a new ArrayList instance is used
-            answer =  ListWithDefault.newInstance(new ArrayList<T>(answer), self.isLazyDefaultValues(), self.getInitClosure());
+            answer =  ListWithDefault.newInstance(new ArrayList<>(answer), self.isLazyDefaultValues(), self.getInitClosure());
         }
 
         return answer;
@@ -7884,7 +7882,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      *
      */
     public static <T> List<T> getAt(ListWithDefault<T> self, EmptyRange range) {
-        return ListWithDefault.newInstance(new ArrayList<T>(), self.isLazyDefaultValues(), self.getInitClosure());
+        return ListWithDefault.newInstance(new ArrayList<>(), self.isLazyDefaultValues(), self.getInitClosure());
     }
 
     /**
@@ -7917,7 +7915,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     @SuppressWarnings("unchecked")
     public static <T> List<T> getAt(List<T> self, Collection indices) {
-        List<T> answer = new ArrayList<T>(indices.size());
+        List<T> answer = new ArrayList<>(indices.size());
         for (Object value : indices) {
             if (value instanceof Collection) {
                 answer.addAll((List<T>)InvokerHelper.invokeMethod(self, "getAt", value));
@@ -7939,7 +7937,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T> List<T> getAt(T[] self, Collection indices) {
-        List<T> answer = new ArrayList<T>(indices.size());
+        List<T> answer = new ArrayList<>(indices.size());
         for (Object value : indices) {
             if (value instanceof Range) {
                 answer.addAll(getAt(self, (Range) value));
@@ -7964,7 +7962,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <K, V> Map<K, V> subMap(Map<K, V> map, Collection<K> keys) {
-        Map<K, V> answer = new LinkedHashMap<K, V>(keys.size());
+        Map<K, V> answer = new LinkedHashMap<>(keys.size());
         for (K key : keys) {
             if (map.containsKey(key)) {
                 answer.put(key, map.get(key));
@@ -7990,7 +7988,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.1.0
      */
     public static <K, V> Map<K, V> subMap(Map<K, V> map, K[] keys) {
-        Map<K, V> answer = new LinkedHashMap<K, V>(keys.length);
+        Map<K, V> answer = new LinkedHashMap<>(keys.length);
         for (K key : keys) {
             if (map.containsKey(key)) {
                 answer.put(key, map.get(key));
@@ -8057,7 +8055,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.0
      */
     public static <T> List<T> getAt(T[] array, EmptyRange range) {
-        return new ArrayList<T>();
+        return new ArrayList<>();
     }
 
     /**
@@ -8085,7 +8083,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T> List<T> toList(T[] array) {
-        return new ArrayList<T>(Arrays.asList(array));
+        return new ArrayList<>(Arrays.asList(array));
     }
 
     /**
@@ -8470,7 +8468,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static List getAt(Collection coll, String property) {
-        List<Object> answer = new ArrayList<Object>(coll.size());
+        List<Object> answer = new ArrayList<>(coll.size());
         return getAtIterable(coll, property, answer);
     }
 
@@ -8500,7 +8498,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <K, V> Map<K, V> asImmutable(Map<K, V> self) {
-        return asUnmodifiable(new LinkedHashMap<K, V>(self));
+        return asUnmodifiable(new LinkedHashMap<>(self));
     }
 
     /**
@@ -8513,7 +8511,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <K, V> SortedMap<K, V> asImmutable(SortedMap<K, V> self) {
-        return asUnmodifiable(new TreeMap<K, V>(self));
+        return asUnmodifiable(new TreeMap<>(self));
     }
 
     /**
@@ -8538,7 +8536,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T> List<T> asImmutable(List<T> self) {
-        return asUnmodifiable(new ArrayList<T>(self));
+        return asUnmodifiable(new ArrayList<>(self));
     }
 
     /**
@@ -8551,7 +8549,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T> Set<T> asImmutable(Set<T> self) {
-        return asUnmodifiable(new LinkedHashSet<T>(self));
+        return asUnmodifiable(new LinkedHashSet<>(self));
     }
 
     /**
@@ -8564,7 +8562,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static <T> SortedSet<T> asImmutable(SortedSet<T> self) {
-        return asUnmodifiable(new TreeSet<T>(self));
+        return asUnmodifiable(new TreeSet<>(self));
     }
 
     /**
@@ -8577,7 +8575,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.0
      */
     public static <T> Collection<T> asImmutable(Collection<T> self) {
-        return asUnmodifiable((Collection<T>) new ArrayList<T>(self));
+        return asUnmodifiable((Collection<T>)new ArrayList<>(self));
     }
 
     /**
@@ -9043,7 +9041,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <E> Map<Integer, E> indexed(Iterable<E> self, int offset) {
-        Map<Integer, E> result = new LinkedHashMap<Integer, E>();
+        Map<Integer, E> result = new LinkedHashMap<>();
         Iterator<Tuple2<Integer, E>> indexed = indexed(self.iterator(), offset);
         while (indexed.hasNext()) {
             Tuple2<Integer, E> next = indexed.next();
@@ -9104,7 +9102,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <E> Iterator<Tuple2<E, Integer>> withIndex(Iterator<E> self, int offset) {
-        return new ZipPostIterator<E>(self, offset);
+        return new ZipPostIterator<>(self, offset);
     }
 
     /**
@@ -9123,7 +9121,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <E> Iterator<Tuple2<Integer, E>> indexed(Iterator<E> self, int offset) {
-        return new ZipPreIterator<E>(self, offset);
+        return new ZipPreIterator<>(self, offset);
     }
 
     private static final class ZipPostIterator<E> implements Iterator<Tuple2<E, Integer>> {
@@ -9141,7 +9139,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 
         public Tuple2<E, Integer> next() {
             if (!hasNext()) throw new NoSuchElementException();
-            return new Tuple2<E, Integer>(delegate.next(), index++);
+            return new Tuple2<>(delegate.next(), index++);
         }
 
         public void remove() {
@@ -9164,7 +9162,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 
         public Tuple2<Integer, E> next() {
             if (!hasNext()) throw new NoSuchElementException();
-            return new Tuple2<Integer, E>(index++, delegate.next());
+            return new Tuple2<>(index++, delegate.next());
         }
 
         public void remove() {
@@ -9230,7 +9228,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> List<T> sort(Iterable<T> self, boolean mutate) {
         List<T> answer = mutate ? asList(self) : toList(self);
-        answer.sort(new NumberAwareComparator<T>());
+        answer.sort(new NumberAwareComparator<>());
         return answer;
     }
 
@@ -9247,7 +9245,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.6.0
      */
     public static <K, V> Map<K, V> sort(Map<K, V> self, @ClosureParams(value=FromString.class, options={"Map.Entry<K,V>","Map.Entry<K,V>,Map.Entry<K,V>"}) Closure closure) {
-        Map<K, V> result = new LinkedHashMap<K, V>();
+        Map<K, V> result = new LinkedHashMap<>();
         List<Map.Entry<K, V>> entries = asList((Iterable<Map.Entry<K, V>>) self.entrySet());
         sort((Iterable<Map.Entry<K, V>>) entries, closure);
         for (Map.Entry<K, V> entry : entries) {
@@ -9269,7 +9267,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.7.2
      */
     public static <K, V> Map<K, V> sort(Map<K, V> self, Comparator<? super K> comparator) {
-        Map<K, V> result = new TreeMap<K, V>(comparator);
+        Map<K, V> result = new TreeMap<>(comparator);
         result.putAll(self);
         return result;
     }
@@ -9287,7 +9285,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.7.2
      */
     public static <K, V> Map<K, V> sort(Map<K, V> self) {
-        return new TreeMap<K, V>(self);
+        return new TreeMap<>(self);
     }
 
     /**
@@ -9299,7 +9297,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.5
      */
     public static <T> T[] sort(T[] self) {
-        Arrays.sort(self, new NumberAwareComparator<T>());
+        Arrays.sort(self, new NumberAwareComparator<>());
         return self;
     }
 
@@ -9324,7 +9322,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> T[] sort(T[] self, boolean mutate) {
         T[] answer = mutate ? self : self.clone();
-        Arrays.sort(answer, new NumberAwareComparator<T>());
+        Arrays.sort(answer, new NumberAwareComparator<>());
         return answer;
     }
 
@@ -9474,7 +9472,6 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @return the sorted array
      * @since 1.5.5
      */
-    @SuppressWarnings("unchecked")
     public static <T> T[] sort(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
         return sort(self, false, closure);
     }
@@ -9592,9 +9589,9 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         // use a comparator of one item or two
         int params = closure.getMaximumNumberOfParameters();
         if (params == 1) {
-            list.sort(new OrderBy<T>(closure));
+            list.sort(new OrderBy<>(closure));
         } else {
-            list.sort(new ClosureComparator<T>(closure));
+            list.sort(new ClosureComparator<>(closure));
         }
         return list;
     }
@@ -9640,7 +9637,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> List<T> toSorted(Iterable<T> self) {
-        return toSorted(self, new NumberAwareComparator<T>());
+        return toSorted(self, new NumberAwareComparator<>());
     }
 
     /**
@@ -9686,7 +9683,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> List<T> toSorted(Iterable<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
-        Comparator<T> comparator = (closure.getMaximumNumberOfParameters() == 1) ? new OrderBy<T>(closure) : new ClosureComparator<T>(closure);
+        Comparator<T> comparator = (closure.getMaximumNumberOfParameters() == 1) ? new OrderBy<>(closure) : new ClosureComparator<>(
+            closure);
         return toSorted(self, comparator);
     }
 
@@ -9703,7 +9701,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> Iterator<T> toSorted(Iterator<T> self) {
-        return toSorted(self, new NumberAwareComparator<T>());
+        return toSorted(self, new NumberAwareComparator<>());
     }
 
     /**
@@ -9738,7 +9736,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> Iterator<T> toSorted(Iterator<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
-        Comparator<T> comparator = (closure.getMaximumNumberOfParameters() == 1) ? new OrderBy<T>(closure) : new ClosureComparator<T>(closure);
+        Comparator<T> comparator = (closure.getMaximumNumberOfParameters() == 1) ? new OrderBy<>(closure) : new ClosureComparator<>(
+            closure);
         return toSorted(self, comparator);
     }
 
@@ -9751,7 +9750,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> T[] toSorted(T[] self) {
-        return toSorted(self, new NumberAwareComparator<T>());
+        return toSorted(self, new NumberAwareComparator<>());
     }
 
     /**
@@ -9792,7 +9791,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> T[] toSorted(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure condition) {
-        Comparator<T> comparator = (condition.getMaximumNumberOfParameters() == 1) ? new OrderBy<T>(condition) : new ClosureComparator<T>(condition);
+        Comparator<T> comparator = (condition.getMaximumNumberOfParameters() == 1) ? new OrderBy<>(condition) : new ClosureComparator<>(
+            condition);
         return toSorted(self, comparator);
     }
 
@@ -9811,11 +9811,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <K, V> Map<K, V> toSorted(Map<K, V> self) {
-        return toSorted(self, new NumberAwareValueComparator<K, V>());
+        return toSorted(self, new NumberAwareValueComparator<>());
     }
 
     private static class NumberAwareValueComparator<K, V> implements Comparator<Map.Entry<K, V>> {
-        private final Comparator<V> delegate = new NumberAwareComparator<V>();
+        private final Comparator<V> delegate = new NumberAwareComparator<>();
 
         @Override
         public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {
@@ -9842,7 +9842,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <K, V> Map<K, V> toSorted(Map<K, V> self, Comparator<Map.Entry<K, V>> comparator) {
         List<Map.Entry<K, V>> sortedEntries = toSorted(self.entrySet(), comparator);
-        Map<K, V> result = new LinkedHashMap<K, V>();
+        Map<K, V> result = new LinkedHashMap<>();
         for (Map.Entry<K, V> entry : sortedEntries) {
             result.put(entry.getKey(), entry.getValue());
         }
@@ -9869,7 +9869,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <K, V> Map<K, V> toSorted(Map<K, V> self, @ClosureParams(value=FromString.class, options={"Map.Entry<K,V>","Map.Entry<K,V>,Map.Entry<K,V>"}) Closure condition) {
-        Comparator<Map.Entry<K,V>> comparator = (condition.getMaximumNumberOfParameters() == 1) ? new OrderBy<Map.Entry<K,V>>(condition) : new ClosureComparator<Map.Entry<K,V>>(condition);
+        Comparator<Map.Entry<K,V>> comparator = (condition.getMaximumNumberOfParameters() == 1) ? new OrderBy<>(
+            condition) : new ClosureComparator<>(condition);
         return toSorted(self, comparator);
     }
 
@@ -9881,7 +9882,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <T> Set<T> toSorted(SortedSet<T> self) {
-        return new LinkedHashSet<T>(self);
+        return new LinkedHashSet<>(self);
     }
 
     /**
@@ -9892,7 +9893,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.4.0
      */
     public static <K, V> Map<K, V> toSorted(SortedMap<K, V> self) {
-        return new LinkedHashMap<K, V>(self);
+        return new LinkedHashMap<>(self);
     }
 
     /**
@@ -10274,7 +10275,6 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @throws NoSuchElementException if the array is empty and you try to access the tail()
      * @since 1.7.3
      */
-    @SuppressWarnings("unchecked")
     public static <T> T[] tail(T[] self) {
         if (self.length == 0) {
             throw new NoSuchElementException("Cannot access tail() for an empty array");
@@ -10336,7 +10336,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
             Collection<T> selfCol = (Collection<T>) self;
             result = createSimilarCollection(selfCol, selfCol.size() - 1);
         } else {
-            result = new ArrayList<T>();
+            result = new ArrayList<>();
         }
         addAll(result, init(self.iterator()));
         return result;
@@ -10393,7 +10393,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         if (!self.hasNext()) {
             throw new NoSuchElementException("Cannot access init() for an empty Iterator");
         }
-        return new InitIterator<T>(self);
+        return new InitIterator<>(self);
     }
 
     private static final class InitIterator<E> implements Iterator<E> {
@@ -10545,7 +10545,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.7
      */
     public static <T> Collection<T> take(Iterable<T> self, int num) {
-        Collection<T> result = self instanceof Collection ? createSimilarCollection((Collection<T>) self, Math.max(num, 0)) : new ArrayList<T>();
+        Collection<T> result = self instanceof Collection ? createSimilarCollection((Collection<T>) self, Math.max(num, 0)) : new ArrayList<>();
         addAll(result, take(self.iterator(), num));
         return result;
     }
@@ -10635,7 +10635,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.1
      */
     public static <T> Iterator<T> take(Iterator<T> self, int num) {
-        return new TakeIterator<T>(self, num);
+        return new TakeIterator<>(self, num);
     }
 
     private static final class TakeIterator<E> implements Iterator<E> {
@@ -10724,7 +10724,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> Collection<T> takeRight(Iterable<T> self, int num) {
         if (num <= 0 || !self.iterator().hasNext()) {
-            return self instanceof Collection ? createSimilarCollection((Collection<T>) self, 0) : new ArrayList<T>();
+            return self instanceof Collection ? createSimilarCollection((Collection<T>) self, 0) : new ArrayList<>();
         }
         Collection<T> selfCol = self instanceof Collection ? (Collection<T>) self : toList(self);
         if (selfCol.size() <= num) {
@@ -11039,7 +11039,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         if (num <= 0) {
             return self;
         }
-        return new DropRightIterator<T>(self, num);
+        return new DropRightIterator<>(self, num);
     }
 
     private static final class DropRightIterator<E> implements Iterator<E> {
@@ -11051,7 +11051,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         private DropRightIterator(Iterator<E> delegate, int num) {
             this.delegate = delegate;
             this.num = num;
-            discards = new LinkedList<E>();
+            discards = new LinkedList<>();
             advance();
         }
 
@@ -11277,7 +11277,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.7
      */
     public static <T> Iterator<T> takeWhile(Iterator<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure condition) {
-        return new TakeWhileIterator<T>(self, condition);
+        return new TakeWhileIterator<>(self, condition);
     }
 
     private static final class TakeWhileIterator<E> implements Iterator<E> {
@@ -11485,7 +11485,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.7
      */
     public static <T> Iterator<T> dropWhile(Iterator<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<?> condition) {
-        return new DropWhileIterator<T>(self, condition);
+        return new DropWhileIterator<>(self, condition);
     }
 
     private static final class DropWhileIterator<E> implements Iterator<E> {
@@ -12288,7 +12288,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
             return self;
         }
         int size = self.size();
-        List<T> answer = new ArrayList<T>(size);
+        List<T> answer = new ArrayList<>(size);
         ListIterator<T> iter = self.listIterator(size);
         while (iter.hasPrevious()) {
             answer.add(iter.previous());
@@ -12304,7 +12304,6 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @see #reverse(Object[], boolean)
      * @since 1.5.5
      */
-    @SuppressWarnings("unchecked")
     public static <T> T[] reverse(T[] self) {
         return reverse(self, false);
     }
@@ -12321,7 +12320,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     @SuppressWarnings("unchecked")
     public static <T> T[] reverse(T[] self, boolean mutate) {
         if (!mutate) {
-            return (T[]) toList(new ReverseListIterator<T>(Arrays.asList(self))).toArray();
+            return (T[]) toList(new ReverseListIterator<>(Arrays.asList(self))).toArray();
         }
         List<T> items = Arrays.asList(self);
         Collections.reverse(items);
@@ -12339,7 +12338,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.5
      */
     public static <T> Iterator<T> reverse(Iterator<T> self) {
-        return new ReverseListIterator<T>(toList(self));
+        return new ReverseListIterator<>(toList(self));
     }
 
     /**
@@ -12616,7 +12615,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.1
      */
     public static <T> List<T> plus(List<T> self, int index, List<T> additions) {
-        final List<T> answer = new ArrayList<T>(self);
+        final List<T> answer = new ArrayList<>(self);
         answer.addAll(index, additions);
         return answer;
     }
@@ -12814,7 +12813,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 
         Collection<T> result = createSimilarCollection(left, Math.min(left.size(), right.size()));
         //creates the collection to look for values.
-        Collection<T> pickFrom = new TreeSet<T>(comparator);
+        Collection<T> pickFrom = new TreeSet<>(comparator);
         pickFrom.addAll(left);
 
         for (final T t : right) {
@@ -13068,10 +13067,10 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.2
      */
     public static <T> List<List<T>> chop(Iterator<T> self, int... chopSizes) {
-        List<List<T>> result = new ArrayList<List<T>>();
+        List<List<T>> result = new ArrayList<>();
         for (int nextSize : chopSizes) {
             int size = nextSize;
-            List<T> next = new ArrayList<T>();
+            List<T> next = new ArrayList<>();
             while (size-- != 0 && self.hasNext()) {
                 next.add(self.next());
             }
@@ -13249,7 +13248,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
             return false;
         }
         final Iterator<T> it1 = self.iterator();
-        Collection<T> otherItems = new HashSet<T>(other);
+        Collection<T> otherItems = new HashSet<>(other);
         while (it1.hasNext()) {
             final Object o1 = it1.next();
             final Iterator<T> it2 = otherItems.iterator();
@@ -13466,13 +13465,13 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         // since AbstractCollection only does a remove on the first
         // element it encounters.
 
-        Comparator<T> numberComparator = new NumberAwareComparator<T>();
+        Comparator<T> numberComparator = new NumberAwareComparator<>();
 
         if (nlgnSort && (head instanceof Comparable)) {
             //n*LOG(n) version
             Set<T> answer;
             if (head instanceof Number) {
-                answer = new TreeSet<T>(numberComparator);
+                answer = new TreeSet<>(numberComparator);
                 answer.addAll(self);
                 for (T t : self) {
                     if (t instanceof Number) {
@@ -13488,7 +13487,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
                     }
                 }
             } else {
-                answer = new TreeSet<T>(numberComparator);
+                answer = new TreeSet<>(numberComparator);
                 answer.addAll(self);
                 answer.removeAll(removeMe);
             }
@@ -13499,7 +13498,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
             }
         } else {
             //n*n version
-            List<T> tmpAnswer = new LinkedList<T>(self);
+            List<T> tmpAnswer = new LinkedList<>(self);
             for (Iterator<T> iter = tmpAnswer.iterator(); iter.hasNext();) {
                 T element = iter.next();
                 boolean elementRemoved = false;
@@ -14900,7 +14899,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.0
      */
     public static <T> Set<T> toSet(Collection<T> self) {
-        Set<T> answer = new HashSet<T>(self.size());
+        Set<T> answer = new HashSet<>(self.size());
         answer.addAll(self);
         return answer;
     }
@@ -14933,7 +14932,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.0
      */
     public static <T> Set<T> toSet(Iterator<T> self) {
-        Set<T> answer = new HashSet<T>();
+        Set<T> answer = new HashSet<>();
         while (self.hasNext()) {
             answer.add(self.next());
         }
@@ -14948,7 +14947,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.8.0
      */
     public static <T> Set<T> toSet(Enumeration<T> self) {
-        Set<T> answer = new HashSet<T>();
+        Set<T> answer = new HashSet<>();
         while (self.hasMoreElements()) {
             answer.add(self.nextElement());
         }
@@ -17265,7 +17264,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> int findIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
-        return findIndexOf(new ArrayIterator<T>(self), startIndex, condition);
+        return findIndexOf(new ArrayIterator<>(self), startIndex, condition);
     }
 
     /**
@@ -17383,7 +17382,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> int findLastIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
-        return findLastIndexOf(new ArrayIterator<T>(self), 0, condition);
+        return findLastIndexOf(new ArrayIterator<>(self), 0, condition);
     }
 
     /**
@@ -17399,7 +17398,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      */
     public static <T> int findLastIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
         // TODO could be made more efficient by using a reverse index
-        return findLastIndexOf(new ArrayIterator<T>(self), startIndex, condition);
+        return findLastIndexOf(new ArrayIterator<>(self), startIndex, condition);
     }
 
     /**
@@ -17455,7 +17454,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> List<Number> findIndexValues(Iterator<T> self, Number startIndex, @ClosureParams(FirstParam.FirstGenericType.class) Closure condition) {
-        List<Number> result = new ArrayList<Number>();
+        List<Number> result = new ArrayList<>();
         long count = 0;
         long startCount = startIndex.longValue();
         BooleanClosureWrapper bcw = new BooleanClosureWrapper(condition);
@@ -17524,7 +17523,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> List<Number> findIndexValues(T[] self, Number startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
-        return findIndexValues(new ArrayIterator<T>(self), startIndex, condition);
+        return findIndexValues(new ArrayIterator<>(self), startIndex, condition);
     }
 
     /**
@@ -17587,7 +17586,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
             }
             if (type.isInterface()) {
                 try {
-                    List<Class> interfaces = new ArrayList<Class>();
+                    List<Class> interfaces = new ArrayList<>();
                     interfaces.add(type);
                     return (T) ProxyGenerator.INSTANCE.instantiateDelegate(interfaces, obj);
                 } catch (GroovyRuntimeException cause) {
@@ -17982,7 +17981,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         if (self instanceof BufferedIterator) {
             return (BufferedIterator<T>) self;
         } else {
-            return new IteratorBufferedIterator<T>(self);
+            return new IteratorBufferedIterator<>(self);
         }
     }
 
@@ -17998,7 +17997,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> BufferedIterator<T> bufferedIterator(Iterable<T> self) {
-        return new IteratorBufferedIterator<T>(self.iterator());
+        return new IteratorBufferedIterator<>(self.iterator());
     }
 
     /**
@@ -18013,7 +18012,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.5.0
      */
     public static <T> BufferedIterator<T> bufferedIterator(List<T> self) {
-        return new ListBufferedIterator<T>(self);
+        return new ListBufferedIterator<>(self);
     }
 
     /**
@@ -18081,7 +18080,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @return a proxy implementing the trait interfaces
      */
     public static Object withTraits(Object self, Class<?>... traits) {
-        List<Class> interfaces = new ArrayList<Class>();
+        List<Class> interfaces = new ArrayList<>();
         Collections.addAll(interfaces, traits);
         return ProxyGenerator.INSTANCE.instantiateDelegate(interfaces, self);
     }