You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/08/25 16:44:52 UTC
[4/8] groovy git commit: Minor refactoring: Explicit type can be
replaced with <>
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index d54e405..6b1aab4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -212,7 +212,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
// NioGroovyMethods.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
@@ -510,7 +510,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));
}
@@ -528,7 +528,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 {
@@ -679,7 +679,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 {
@@ -1172,7 +1172,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();
}
/**
@@ -1232,7 +1232,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) {
@@ -1302,8 +1302,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);
}
@@ -1386,9 +1386,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;
}
@@ -1435,7 +1435,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> {
@@ -1610,7 +1610,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) {
@@ -1702,8 +1702,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> {
@@ -1714,7 +1714,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();
}
@@ -1757,7 +1757,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);
}
/**
@@ -1947,8 +1947,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);
}
@@ -2056,8 +2056,8 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
@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);
}
@@ -2413,7 +2413,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;
}
@@ -2426,7 +2426,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;
}
@@ -2480,7 +2480,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);
}
/**
@@ -2614,7 +2614,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);
}
/**
@@ -2794,7 +2794,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)) {
@@ -3171,7 +3171,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
*/
@Deprecated
public static <T> List<T> toList(Collection<T> self) {
- List<T> answer = new ArrayList<T>(self.size());
+ List<T> answer = new ArrayList<>(self.size());
answer.addAll(self);
return answer;
}
@@ -3185,7 +3185,7 @@ 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());
}
@@ -3217,7 +3217,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());
}
@@ -3369,7 +3369,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 {
@@ -3378,7 +3378,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));
}
@@ -3440,7 +3440,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);
}
/**
@@ -3467,7 +3467,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);
}
/**
@@ -3487,7 +3487,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);
}
/**
@@ -3500,7 +3500,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);
}
/**
@@ -3548,7 +3548,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
*/
@Deprecated
public static <S,T> List<T> collect(Collection<S> self, @ClosureParams(FirstParam.FirstGenericType.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);
}
/**
@@ -3766,7 +3766,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<Collection<? extends T>> projection) {
- return (List<T>) collectMany(self, new ArrayList<T>(), projection);
+ return (List<T>) collectMany(self, new ArrayList<>(), projection);
}
/**
@@ -3835,7 +3835,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<Collection<? extends T>> projection) {
- return collectMany(self, new ArrayList<T>(), projection);
+ return collectMany(self, new ArrayList<>(), projection);
}
/**
@@ -3909,7 +3909,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);
}
/**
@@ -3985,7 +3985,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);
}
/**
@@ -4524,7 +4524,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);
}
/**
@@ -4537,7 +4537,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);
}
/**
@@ -4627,7 +4627,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);
@@ -4648,7 +4648,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);
}
/**
@@ -4670,7 +4670,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) {
@@ -4755,8 +4755,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));
}
/**
@@ -5173,14 +5173,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();
@@ -5317,8 +5317,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());
}
@@ -5386,7 +5386,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());
}
@@ -5475,7 +5475,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);
@@ -5557,7 +5557,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 -> a << [(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));
}
@@ -5709,7 +5709,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);
@@ -5736,7 +5736,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);
@@ -5767,7 +5767,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();
@@ -5813,7 +5813,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));
}
@@ -5866,7 +5866,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));
}
@@ -5885,7 +5885,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
if (answer.containsKey(value)) {
answer.get(value).add(element);
} else {
- List<T> groupedElements = new ArrayList<T>();
+ List<T> groupedElements = new ArrayList<>();
groupedElements.add(element);
answer.put(value, groupedElements);
}
@@ -6504,7 +6504,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);
}
/**
@@ -6563,7 +6563,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);
}
/**
@@ -7048,7 +7048,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;
@@ -7281,7 +7281,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;
@@ -7541,7 +7541,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @return a new eager or lazy list of the values at the given indices
*/
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 Range || value instanceof Collection) {
answer.addAll((List<T>) InvokerHelper.invokeMethod(self, "getAt", value));
@@ -7577,7 +7577,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;
@@ -7595,7 +7595,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());
}
/**
@@ -7625,7 +7625,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.0
*/
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 Range || value instanceof Collection) {
answer.addAll((List<T>)InvokerHelper.invokeMethod(self, "getAt", value));
@@ -7647,7 +7647,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));
@@ -7672,7 +7672,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));
@@ -7698,7 +7698,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));
@@ -7765,7 +7765,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<>();
}
/**
@@ -7793,7 +7793,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));
}
/**
@@ -8160,7 +8160,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);
}
@@ -8190,7 +8190,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));
}
/**
@@ -8203,7 +8203,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));
}
/**
@@ -8228,7 +8228,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));
}
/**
@@ -8241,7 +8241,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));
}
/**
@@ -8254,7 +8254,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));
}
/**
@@ -8267,7 +8267,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));
}
/**
@@ -8733,7 +8733,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();
@@ -8794,7 +8794,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);
}
/**
@@ -8813,7 +8813,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>> {
@@ -8831,7 +8831,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() {
@@ -8854,7 +8854,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() {
@@ -8920,7 +8920,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);
- Collections.sort(answer, new NumberAwareComparator<T>());
+ Collections.sort(answer, new NumberAwareComparator<>());
return answer;
}
@@ -8937,7 +8937,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) {
@@ -8959,7 +8959,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;
}
@@ -8977,7 +8977,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);
}
/**
@@ -8989,7 +8989,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;
}
@@ -9014,7 +9014,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;
}
@@ -9282,9 +9282,9 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
// use a comparator of one item or two
int params = closure.getMaximumNumberOfParameters();
if (params == 1) {
- Collections.sort(list, new OrderBy<T>(closure));
+ Collections.sort(list, new OrderBy<>(closure));
} else {
- Collections.sort(list, new ClosureComparator<T>(closure));
+ Collections.sort(list, new ClosureComparator<>(closure));
}
return list;
}
@@ -9330,7 +9330,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<>());
}
/**
@@ -9376,7 +9376,7 @@ 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);
}
@@ -9393,7 +9393,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<>());
}
/**
@@ -9428,7 +9428,7 @@ 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);
}
@@ -9441,7 +9441,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<>());
}
/**
@@ -9482,7 +9482,7 @@ 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);
}
@@ -9501,11 +9501,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) {
@@ -9532,7 +9532,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());
}
@@ -9559,7 +9559,7 @@ 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);
}
@@ -9571,7 +9571,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);
}
/**
@@ -9582,7 +9582,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);
}
/**
@@ -10026,7 +10026,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;
@@ -10083,7 +10083,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> {
@@ -10235,7 +10235,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, num < 0 ? 0 : num) : new ArrayList<T>();
+ Collection<T> result = self instanceof Collection ? createSimilarCollection((Collection<T>) self, num < 0 ? 0 : num) : new ArrayList<>();
addAll(result, take(self.iterator(), num));
return result;
}
@@ -10325,7 +10325,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> {
@@ -10414,7 +10414,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) {
@@ -10729,7 +10729,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> {
@@ -10741,7 +10741,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();
}
@@ -10967,7 +10967,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> {
@@ -11175,7 +11175,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> {
@@ -11806,7 +11806,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());
@@ -11839,7 +11839,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);
@@ -11857,7 +11857,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));
}
/**
@@ -12134,7 +12134,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;
}
@@ -12332,7 +12332,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) {
@@ -12586,10 +12586,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 (Integer 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());
}
@@ -12767,7 +12767,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();
@@ -12984,13 +12984,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 (Number.class.isInstance(head)) {
- answer = new TreeSet<T>(numberComparator);
+ answer = new TreeSet<>(numberComparator);
answer.addAll(self);
for (T t : self) {
if (Number.class.isInstance(t)) {
@@ -13006,7 +13006,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
}
}
} else {
- answer = new TreeSet<T>(numberComparator);
+ answer = new TreeSet<>(numberComparator);
answer.addAll(self);
answer.removeAll(removeMe);
}
@@ -13017,7 +13017,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;
@@ -14418,7 +14418,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;
}
@@ -14451,7 +14451,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());
}
@@ -14466,7 +14466,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());
}
@@ -16740,7 +16740,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);
}
/**
@@ -16849,7 +16849,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);
}
/**
@@ -16865,7 +16865,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);
}
/**
@@ -16921,7 +16921,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);
@@ -16990,7 +16990,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);
}
/**
@@ -17053,7 +17053,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) {
@@ -17449,7 +17449,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
if (self instanceof BufferedIterator) {
return (BufferedIterator<T>) self;
} else {
- return new IteratorBufferedIterator<T>(self);
+ return new IteratorBufferedIterator<>(self);
}
}
@@ -17465,7 +17465,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());
}
/**
@@ -17480,7 +17480,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);
}
/**
@@ -17548,7 +17548,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);
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
index 3838fdc..76aa1a3 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
@@ -192,7 +192,7 @@ public class DefaultGroovyMethodsSupport {
if (iterable instanceof Collection) {
return createSimilarCollection((Collection<T>) iterable);
} else {
- return new ArrayList<T>();
+ return new ArrayList<>();
}
}
@@ -210,23 +210,23 @@ public class DefaultGroovyMethodsSupport {
if (orig instanceof Queue) {
return createSimilarQueue((Queue<T>) orig);
}
- return new ArrayList<T>(newCapacity);
+ return new ArrayList<>(newCapacity);
}
protected static <T> List<T> createSimilarList(List<T> orig, int newCapacity) {
if (orig instanceof LinkedList)
- return new LinkedList<T>();
+ return new LinkedList<>();
if (orig instanceof Stack)
- return new Stack<T>();
+ return new Stack<>();
if (orig instanceof Vector)
- return new Vector<T>();
+ return new Vector<>();
if (orig instanceof CopyOnWriteArrayList)
- return new CopyOnWriteArrayList<T>();
+ return new CopyOnWriteArrayList<>();
- return new ArrayList<T>(newCapacity);
+ return new ArrayList<>(newCapacity);
}
@SuppressWarnings("unchecked")
@@ -246,10 +246,10 @@ public class DefaultGroovyMethodsSupport {
}
} else {
if (orig instanceof CopyOnWriteArraySet) {
- return new CopyOnWriteArraySet<T>();
+ return new CopyOnWriteArraySet<>();
} else {
// Do not use HashSet
- return new LinkedHashSet<T>();
+ return new LinkedHashSet<>();
}
}
}
@@ -258,25 +258,25 @@ public class DefaultGroovyMethodsSupport {
protected static <T> Queue<T> createSimilarQueue(Queue<T> orig) {
if (orig instanceof ArrayBlockingQueue) {
ArrayBlockingQueue queue = (ArrayBlockingQueue) orig;
- return new ArrayBlockingQueue<T>(queue.size() + queue.remainingCapacity());
+ return new ArrayBlockingQueue<>(queue.size() + queue.remainingCapacity());
} else if (orig instanceof ArrayDeque) {
- return new ArrayDeque<T>();
+ return new ArrayDeque<>();
} else if (orig instanceof ConcurrentLinkedQueue) {
- return new ConcurrentLinkedQueue<T>();
+ return new ConcurrentLinkedQueue<>();
} else if (orig instanceof DelayQueue) {
return new DelayQueue();
} else if (orig instanceof LinkedBlockingDeque) {
- return new LinkedBlockingDeque<T>();
+ return new LinkedBlockingDeque<>();
} else if (orig instanceof LinkedBlockingQueue) {
- return new LinkedBlockingQueue<T>();
+ return new LinkedBlockingQueue<>();
} else if (orig instanceof PriorityBlockingQueue) {
- return new PriorityBlockingQueue<T>();
+ return new PriorityBlockingQueue<>();
} else if (orig instanceof PriorityQueue) {
return new PriorityQueue<T>(11, ((PriorityQueue) orig).comparator());
} else if (orig instanceof SynchronousQueue) {
- return new SynchronousQueue<T>();
+ return new SynchronousQueue<>();
} else {
- return new LinkedList<T>();
+ return new LinkedList<>();
}
}
@@ -291,20 +291,20 @@ public class DefaultGroovyMethodsSupport {
}
} else {
if (orig instanceof ConcurrentHashMap) {
- return new ConcurrentHashMap<K, V>();
+ return new ConcurrentHashMap<>();
} else if (orig instanceof Hashtable) {
if (orig instanceof Properties) {
return (Map<K, V>) new Properties();
} else {
- return new Hashtable<K, V>();
+ return new Hashtable<>();
}
} else if (orig instanceof IdentityHashMap) {
- return new IdentityHashMap<K, V>();
+ return new IdentityHashMap<>();
} else if (orig instanceof WeakHashMap) {
- return new WeakHashMap<K, V>();
+ return new WeakHashMap<>();
} else {
// Do not use HashMap
- return new LinkedHashMap<K, V>();
+ return new LinkedHashMap<>();
}
}
}
@@ -317,28 +317,28 @@ public class DefaultGroovyMethodsSupport {
// fall back to some defaults
if (orig instanceof SortedMap) {
if (orig instanceof ConcurrentSkipListMap) {
- return new ConcurrentSkipListMap<K, V>(orig);
+ return new ConcurrentSkipListMap<>(orig);
} else {
- return new TreeMap<K, V>(orig);
+ return new TreeMap<>(orig);
}
} else {
if (orig instanceof ConcurrentHashMap) {
- return new ConcurrentHashMap<K, V>(orig);
+ return new ConcurrentHashMap<>(orig);
} else if (orig instanceof Hashtable) {
if (orig instanceof Properties) {
Map<K, V> map = (Map<K, V>) new Properties();
map.putAll(orig);
return map;
} else {
- return new Hashtable<K, V>(orig);
+ return new Hashtable<>(orig);
}
} else if (orig instanceof IdentityHashMap) {
- return new IdentityHashMap<K, V>(orig);
+ return new IdentityHashMap<>(orig);
} else if (orig instanceof WeakHashMap) {
- return new WeakHashMap<K, V>(orig);
+ return new WeakHashMap<>(orig);
} else {
// Do not use HashMap
- return new LinkedHashMap<K, V>(orig);
+ return new LinkedHashMap<>(orig);
}
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
index 8843f11..6bcbfd6 100644
--- a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
+++ b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
@@ -174,7 +174,7 @@ public class GroovyCategorySupport {
// Precondition: accessorName.length() > prefixLength
private Map<String, String> putPropertyAccessor(int prefixLength, String accessorName, Map<String, String> map) {
if (map == null) {
- map = new HashMap<String, String>();
+ map = new HashMap<>();
}
String property = accessorName.substring(prefixLength, prefixLength+1).toLowerCase() + accessorName.substring(prefixLength+1);
map.put(property, accessorName);
@@ -183,7 +183,7 @@ public class GroovyCategorySupport {
private void use(Class categoryClass) {
CachedClass cachedClass = ReflectionCache.getCachedClass(categoryClass);
- LinkedList<CachedClass> classStack = new LinkedList<CachedClass>();
+ LinkedList<CachedClass> classStack = new LinkedList<>();
for (CachedClass superClass = cachedClass; superClass.getTheClass()!=Object.class; superClass = superClass.getCachedSuperClass()) {
classStack.add(superClass);
}
@@ -327,7 +327,7 @@ public class GroovyCategorySupport {
private static class MyThreadLocal extends ThreadLocal<SoftReference> {
- final ConcurrentHashMap<String,AtomicInteger> usage = new ConcurrentHashMap<String,AtomicInteger> ();
+ final ConcurrentHashMap<String,AtomicInteger> usage = new ConcurrentHashMap<>();
public ThreadCategoryInfo getInfo() {
final SoftReference reference = get();
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
index f65c85f..6bf3280 100644
--- a/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
@@ -800,7 +800,7 @@ public class IOGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.0
*/
public static List<String> readLines(Reader reader) throws IOException {
- IteratorClosureAdapter<String> closure = new IteratorClosureAdapter<String>(reader);
+ IteratorClosureAdapter<String> closure = new IteratorClosureAdapter<>(reader);
eachLine(reader, closure);
return closure.asList();
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
index c876f43..05e8837 100644
--- a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -784,8 +784,8 @@ public class InvokerHelper {
return argBuf.toString();
}
- private static Set<String> DEFAULT_IMPORT_PKGS = new HashSet<String>();
- private static Set<String> DEFAULT_IMPORT_CLASSES = new HashSet<String>();
+ private static Set<String> DEFAULT_IMPORT_PKGS = new HashSet<>();
+ private static Set<String> DEFAULT_IMPORT_CLASSES = new HashSet<>();
static {
for (String pkgName : ResolveVisitor.DEFAULT_IMPORTS) {
DEFAULT_IMPORT_PKGS.add(pkgName.substring(0, pkgName.length() - 1));
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/IteratorClosureAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/IteratorClosureAdapter.java b/src/main/java/org/codehaus/groovy/runtime/IteratorClosureAdapter.java
index ea08d2f..77b1d60 100644
--- a/src/main/java/org/codehaus/groovy/runtime/IteratorClosureAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/IteratorClosureAdapter.java
@@ -31,7 +31,7 @@ import java.util.List;
public class IteratorClosureAdapter<T> extends Closure {
private static final long serialVersionUID = -7485077849389539770L;
- private final List<T> list = new ArrayList<T>();
+ private final List<T> list = new ArrayList<>();
private MetaClass metaClass = InvokerHelper.getMetaClass(getClass());
public IteratorClosureAdapter(Object delegate) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
index f2ae80a..fb4a5ba 100644
--- a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
@@ -650,7 +650,7 @@ public class MetaClassHelper {
for (int i = offset; i < arguments.length; i++) {
if (arguments[i] != null) {
Class tmpClass;
- Set<Class> intfs = new HashSet<Class>();
+ Set<Class> intfs = new HashSet<>();
tmpClass = arguments[i].getClass();
for (; tmpClass != Object.class; tmpClass = tmpClass.getSuperclass()) {
intfs.addAll(Arrays.asList(tmpClass.getInterfaces()));
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/MethodRankHelper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/MethodRankHelper.java b/src/main/java/org/codehaus/groovy/runtime/MethodRankHelper.java
index 689245c..9baedaf 100644
--- a/src/main/java/org/codehaus/groovy/runtime/MethodRankHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/MethodRankHelper.java
@@ -73,7 +73,7 @@ public class MethodRankHelper{
*/
public static String getMethodSuggestionString(String methodName, Class type, Object[] arguments){
ClassInfo ci = ClassInfo.getClassInfo(type);
- List<MetaMethod> methods = new ArrayList<MetaMethod>(ci.getMetaClass().getMethods());
+ List<MetaMethod> methods = new ArrayList<>(ci.getMetaClass().getMethods());
methods.addAll(ci.getMetaClass().getMetaMethods());
List<MetaMethod> sugg = rankMethods(methodName,arguments,methods);
StringBuilder sb = new StringBuilder();
@@ -111,8 +111,8 @@ public class MethodRankHelper{
}
private static List<Pair<Class,Class>> getConflictClasses(List<MetaMethod> sugg, Class[] argumentClasses) {
- List<Pair<Class,Class>> ret = new LinkedList<Pair<Class,Class>>();
- Set<Class> recordedClasses = new HashSet<Class>();
+ List<Pair<Class,Class>> ret = new LinkedList<>();
+ Set<Class> recordedClasses = new HashSet<>();
for (MetaMethod method : sugg) {
Class[] para = method.getNativeParameterTypes();
for (Class aPara : para) {
@@ -121,7 +121,7 @@ public class MethodRankHelper{
if (argumentClass == null) continue;
if (argumentClass == aPara) continue;
if (argumentClass.getName().equals(aPara.getName())) {
- ret.add(new Pair<Class, Class>(argumentClass, aPara));
+ ret.add(new Pair<>(argumentClass, aPara));
}
}
recordedClasses.add(aPara);
@@ -176,7 +176,7 @@ public class MethodRankHelper{
public static String getPropertySuggestionString(String fieldName, Class type){
ClassInfo ci = ClassInfo.getClassInfo(type);
List<MetaProperty> fi = ci.getMetaClass().getProperties();
- List<RankableField> rf = new ArrayList<RankableField>(fi.size());
+ List<RankableField> rf = new ArrayList<>(fi.size());
StringBuilder sb = new StringBuilder();
sb.append("\nPossible solutions: ");
@@ -229,7 +229,7 @@ public class MethodRankHelper{
* @return a sorted lists of Methods
*/
private static List<MetaMethod> rankMethods(String name, Object[] original, List<MetaMethod> methods) {
- List<RankableMethod> rm = new ArrayList<RankableMethod>(methods.size());
+ List<RankableMethod> rm = new ArrayList<>(methods.size());
if (original==null) original = EMPTY_OBJECT_ARRAY;
Class[] ta = new Class[original.length];
@@ -244,7 +244,7 @@ public class MethodRankHelper{
}
Collections.sort(rm);
- List<MetaMethod> l = new ArrayList<MetaMethod>(rm.size());
+ List<MetaMethod> l = new ArrayList<>(rm.size());
for (RankableMethod m : rm) {
if (l.size() > MAX_RECOMENDATIONS) break;
if (m.score > MAX_METHOD_SCORE) break;
@@ -304,7 +304,7 @@ public class MethodRankHelper{
rc[i] = new RankableConstructor(ta, candidates[i]);
}
Arrays.sort(rc);
- List<Constructor> l = new ArrayList<Constructor>();
+ List<Constructor> l = new ArrayList<>();
int index = 0;
while (l.size() < MAX_RECOMENDATIONS && index < rc.length && rc[index].score < MAX_CONSTRUCTOR_SCORE) {
l.add(rc[index].c);
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
index 3c709d5..c554cab 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
@@ -90,19 +90,19 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
private static final String CLOSURES_MAP_FIELD = "$closures$delegate$map";
private static final String DELEGATE_OBJECT_FIELD = "$delegate";
- private static List<Method> OBJECT_METHODS = getInheritedMethods(Object.class, new ArrayList<Method>());
- private static List<Method> GROOVYOBJECT_METHODS = getInheritedMethods(GroovyObject.class, new ArrayList<Method>());
+ private static List<Method> OBJECT_METHODS = getInheritedMethods(Object.class, new ArrayList<>());
+ private static List<Method> GROOVYOBJECT_METHODS = getInheritedMethods(GroovyObject.class, new ArrayList<>());
private static final AtomicLong pxyCounter = new AtomicLong();
private static final Set<String> GROOVYOBJECT_METHOD_NAMESS;
private static final Object[] EMPTY_ARGS = new Object[0];
static {
- List<String> names = new ArrayList<String>();
+ List<String> names = new ArrayList<>();
for (Method method : GroovyObject.class.getMethods()) {
names.add(method.getName());
}
- GROOVYOBJECT_METHOD_NAMESS = new HashSet<String>(names);
+ GROOVYOBJECT_METHOD_NAMESS = new HashSet<>(names);
}
private final Class superClass;
@@ -145,8 +145,8 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
final Class delegateClass) {
super(CompilerConfiguration.ASM_API_VERSION, new ClassWriter(0));
this.loader = proxyLoader != null ? createInnerLoader(proxyLoader, interfaces) : findClassLoader(superClass, interfaces);
- this.visitedMethods = new LinkedHashSet<Object>();
- this.delegatedClosures = closureMap.isEmpty() ? EMPTY_DELEGATECLOSURE_MAP : new HashMap<String, Boolean>();
+ this.visitedMethods = new LinkedHashSet<>();
+ this.delegatedClosures = closureMap.isEmpty() ? EMPTY_DELEGATECLOSURE_MAP : new HashMap<>();
boolean wildcard = false;
for (Map.Entry<Object, Object> entry : closureMap.entrySet()) {
String name = entry.getKey().toString();
@@ -170,7 +170,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
this.superClass = fixedSuperClass;
// create the base list of classes which have possible methods to be overloaded
- this.classList = new LinkedHashSet<Class>();
+ this.classList = new LinkedHashSet<>();
this.classList.add(superClass);
if (generateDelegateField) {
classList.add(delegateClass);
@@ -205,7 +205,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
return superClass;
}
Class result = Object.class;
- Set<ClassNode> traits = new LinkedHashSet<ClassNode>();
+ Set<ClassNode> traits = new LinkedHashSet<>();
// check if it's a trait
collectTraits(superClass, traits);
if (interfaces != null) {
@@ -239,7 +239,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
if (annotation != null) {
ClassNode trait = ClassHelper.make(clazz);
traits.add(trait.getPlainNodeReference());
- LinkedHashSet<ClassNode> selfTypes = new LinkedHashSet<ClassNode>();
+ LinkedHashSet<ClassNode> selfTypes = new LinkedHashSet<>();
Traits.collectSelfTypes(trait, selfTypes, true, true);
for (ClassNode selfType : selfTypes) {
if (Traits.isTrait(selfType)) {
@@ -264,9 +264,9 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
}
private static Set<String> createDelegateMethodList(Class superClass, Class delegateClass, Class[] interfaces) {
- Set<String> selectedMethods = new HashSet<String>();
- List<Method> interfaceMethods = new ArrayList<Method>();
- List<Method> superClassMethods = new ArrayList<Method>();
+ Set<String> selectedMethods = new HashSet<>();
+ List<Method> interfaceMethods = new ArrayList<>();
+ List<Method> superClassMethods = new ArrayList<>();
Collections.addAll(superClassMethods, superClass.getDeclaredMethods());
if (interfaces != null) {
for (Class thisInterface : interfaces) {
@@ -278,7 +278,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
}
}
}
- List<Method> additionalMethods = getInheritedMethods(delegateClass, new ArrayList<Method>());
+ List<Method> additionalMethods = getInheritedMethods(delegateClass, new ArrayList<>());
for (Method method : additionalMethods) {
if (method.getName().indexOf('$') != -1)
continue;
@@ -330,7 +330,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
- Set<String> interfacesSet = new LinkedHashSet<String>();
+ Set<String> interfacesSet = new LinkedHashSet<>();
if (interfaces != null) Collections.addAll(interfacesSet, interfaces);
for (Class extraInterface : classList) {
if (extraInterface.isInterface()) interfacesSet.add(BytecodeHelper.getClassInternalName(extraInterface));
@@ -889,7 +889,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
for (Class c : interfaces) {
if (c.getClassLoader() != parent) {
if (internalClassLoaders == null)
- internalClassLoaders = new ArrayList<ClassLoader>(interfaces.length);
+ internalClassLoaders = new ArrayList<>(interfaces.length);
if (!internalClassLoaders.contains(c.getClassLoader())) {
internalClassLoaders.add(c.getClassLoader());
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
index a47adab..f262889 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
@@ -1423,7 +1423,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
*/
public static void traverse(final File self, @ClosureParams(value=SimpleType.class, options="java.io.File") final Closure closure)
throws FileNotFoundException, IllegalArgumentException {
- traverse(self, new HashMap<String, Object>(), closure);
+ traverse(self, new HashMap<>(), closure);
}
/**
@@ -1709,7 +1709,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
same++;
}
- List<String> relativePathStack = new ArrayList<String>();
+ List<String> relativePathStack = new ArrayList<>();
// if "from" part is longer, fill it up with ".."
// to reach path which is equal to both paths
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java b/src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java
index fc34ccd..13556c0 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StackTraceUtils.java
@@ -68,7 +68,7 @@ public class StackTraceUtils {
"gjdk.groovy.,"
).split("(\\s|,)+");
- private static final List<Closure> tests = new ArrayList<Closure>();
+ private static final List<Closure> tests = new ArrayList<>();
/**
* Adds a groovy.lang.Closure to test whether the stack trace
@@ -103,7 +103,7 @@ public class StackTraceUtils {
// Note that this getBoolean access may well be synced...
if (!SystemUtil.getBooleanSafe("groovy.full.stacktrace")) {
StackTraceElement[] trace = t.getStackTrace();
- List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>();
+ List<StackTraceElement> newTrace = new ArrayList<>();
for (StackTraceElement stackTraceElement : trace) {
if (isApplicationClass(stackTraceElement.getClassName())) {
newTrace.add(stackTraceElement);
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 35d9ab6..194de39 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -1151,7 +1151,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
public static List<String> findAll(CharSequence self, Pattern pattern) {
Matcher matcher = pattern.matcher(self.toString());
boolean hasGroup = hasGroup(matcher);
- List<String> list = new ArrayList<String>();
+ List<String> list = new ArrayList<>();
for (Iterator iter = iterator(matcher); iter.hasNext();) {
if (hasGroup) {
list.add((String) ((List) iter.next()).get(0));
@@ -1159,7 +1159,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
list.add((String) iter.next());
}
}
- return new ArrayList<String>(list);
+ return new ArrayList<>(list);
}
/**
@@ -1596,7 +1596,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
}
int count = matcher.groupCount();
- List<String> groups = new ArrayList<String>();
+ List<String> groups = new ArrayList<>();
for (int i = 0; i <= count; i++) {
groups.add(matcher.group(i));
}
@@ -1933,7 +1933,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
if (hasGroup(matcher)) {
// are we using groups?
// yes, so return the specified group as list
- List<String> list = new ArrayList<String>(matcher.groupCount());
+ List<String> list = new ArrayList<>(matcher.groupCount());
for (int i = 0; i <= matcher.groupCount(); i++) {
list.add(matcher.group(i));
}
@@ -3588,7 +3588,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
public static List<String> toList(CharSequence self) {
String s = self.toString();
int size = s.length();
- List<String> answer = new ArrayList<String>(size);
+ List<String> answer = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
answer.add(s.substring(i, i + 1));
}
@@ -3634,7 +3634,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.8.2
*/
public static Set<String> toSet(CharSequence self) {
- return new HashSet<String>(toList(self));
+ return new HashSet<>(toList(self));
}
/**
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteClassLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteClassLoader.java b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteClassLoader.java
index ad62e5f..ed090c2 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteClassLoader.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteClassLoader.java
@@ -26,7 +26,7 @@ import java.util.Set;
public class CallSiteClassLoader extends ClassLoaderForClassArtifacts {
- private static final Set<String> KNOWN_CLASSES = new HashSet<String>();
+ private static final Set<String> KNOWN_CLASSES = new HashSet<>();
static {
Collections.addAll(KNOWN_CLASSES
, "org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite"
http://git-wip-us.apache.org/repos/asf/groovy/blob/72fd4078/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java b/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
index 01161ce..5bcedec 100644
--- a/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
+++ b/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
@@ -33,7 +33,7 @@ import java.util.List;
* @since 2.0.0
*/
public class ExtensionModuleRegistry {
- private final List<ExtensionModule> modules = new LinkedList<ExtensionModule>();
+ private final List<ExtensionModule> modules = new LinkedList<>();
public ExtensionModuleRegistry() {
}
@@ -47,7 +47,7 @@ public class ExtensionModuleRegistry {
}
public List<ExtensionModule> getModules() {
- return new ArrayList<ExtensionModule>(modules);
+ return new ArrayList<>(modules);
}
public boolean hasModule(final String moduleName) {