core updates
Project: http://git-wip-us.apache.org/repos/asf/bval/repo Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/99eb42a2 Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/99eb42a2 Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/99eb42a2 Branch: refs/heads/bv2 Commit: 99eb42a254809cc42b607040f1514915f131a622 Parents: 29a6ded Author: Matt Benson <[email protected]> Authored: Wed Nov 15 14:57:26 2017 -0600 Committer: Matt Benson <[email protected]> Committed: Wed Nov 15 16:53:42 2017 -0600 ---------------------------------------------------------------------- .../bval/routines/EMailValidationUtils.java | 7 +- .../java/org/apache/bval/util/BValVersion.java | 12 +- .../java/org/apache/bval/util/ObjectUtils.java | 20 +-- .../java/org/apache/bval/util/StringUtils.java | 67 +++---- .../java/org/apache/bval/util/Validate.java | 26 ++- .../apache/bval/util/reflection/Reflection.java | 173 ++++++++++++++++--- .../apache/bval/util/reflection/TypeUtils.java | 65 +++---- 7 files changed, 221 insertions(+), 149 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java b/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java index 1158c7f..0835bae 100644 --- a/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java +++ b/bval-core/src/main/java/org/apache/bval/routines/EMailValidationUtils.java @@ -29,12 +29,11 @@ public class EMailValidationUtils { private static String ATOM = "[^\\x00-\\x1F\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\\"\\.\\[\\]\\s]"; private static String DOMAIN = "(" + ATOM + "+(\\." + ATOM + "+)*"; private static String IP_DOMAIN = "\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\]"; - public static final java.util.regex.Pattern DEFAULT_EMAIL_PATTERN; + public static final Pattern DEFAULT_EMAIL_PATTERN; static { - DEFAULT_EMAIL_PATTERN = - java.util.regex.Pattern.compile("^" + ATOM + "+(\\." + ATOM + "+)*@" + DOMAIN + "|" + IP_DOMAIN + ")$", - java.util.regex.Pattern.CASE_INSENSITIVE); + DEFAULT_EMAIL_PATTERN = Pattern.compile("^" + ATOM + "+(\\." + ATOM + "+)*@" + DOMAIN + "|" + IP_DOMAIN + ")$", + Pattern.CASE_INSENSITIVE); } /** http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/util/BValVersion.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/util/BValVersion.java b/bval-core/src/main/java/org/apache/bval/util/BValVersion.java index b0c451f..13d1fa3 100644 --- a/bval-core/src/main/java/org/apache/bval/util/BValVersion.java +++ b/bval-core/src/main/java/org/apache/bval/util/BValVersion.java @@ -54,21 +54,17 @@ public class BValVersion { static { Properties revisionProps = new Properties(); - try { - InputStream in = BValVersion.class.getResourceAsStream("/META-INF/org.apache.bval.revision.properties"); + try (InputStream in = BValVersion.class.getResourceAsStream("/META-INF/org.apache.bval.revision.properties")) { if (in != null) { - try { - revisionProps.load(in); - } finally { - in.close(); - } + revisionProps.load(in); } } catch (IOException ioe) { } String vers = revisionProps.getProperty("project.version"); - if (vers == null || "".equals(vers.trim())) + if (vers == null || "".equals(vers.trim())) { vers = "0.0.0"; + } VERSION_NUMBER = vers; StringTokenizer tok = new StringTokenizer(VERSION_NUMBER, ".-"); http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/util/ObjectUtils.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/util/ObjectUtils.java b/bval-core/src/main/java/org/apache/bval/util/ObjectUtils.java index 0464eeb..b7f2fac 100644 --- a/bval-core/src/main/java/org/apache/bval/util/ObjectUtils.java +++ b/bval-core/src/main/java/org/apache/bval/util/ObjectUtils.java @@ -18,6 +18,8 @@ package org.apache.bval.util; import java.lang.annotation.Annotation; import java.lang.reflect.Array; +import java.util.function.Predicate; +import java.util.stream.Stream; public final class ObjectUtils { public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0]; @@ -44,7 +46,7 @@ public final class ObjectUtils { * @return {@code object} if it is not {@code null}, defaultValue otherwise */ public static <T> T defaultIfNull(final T object, final T defaultValue) { - return object != null ? object : defaultValue; + return object == null ? defaultValue : object; } public static <T> boolean isNotEmpty(final T[] array) { @@ -68,29 +70,19 @@ public final class ObjectUtils { if (array == null) { return false; } - for (Object o : array) { - if (o.equals(objectToFind)) { - return true; - } - } - return false; + return Stream.of(array).anyMatch(Predicate.isEqual(objectToFind)); } public static <T> T[] arrayAdd(T[] array, T objectToAdd) { - Class<?> type; - if (array != null) { - type = array.getClass().getComponentType(); - } else if (objectToAdd != null) { - type = objectToAdd.getClass(); - } else { + if (array == null && objectToAdd == null) { throw new IllegalArgumentException("Arguments cannot both be null"); } final int arrayLength = Array.getLength(array); + @SuppressWarnings("unchecked") T[] newArray = (T[]) Array.newInstance(array.getClass().getComponentType(), arrayLength + 1); System.arraycopy(array, 0, newArray, 0, arrayLength); newArray[newArray.length - 1] = objectToAdd; return newArray; - } } http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/util/StringUtils.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/util/StringUtils.java b/bval-core/src/main/java/org/apache/bval/util/StringUtils.java index f7add27..6b9c25d 100644 --- a/bval-core/src/main/java/org/apache/bval/util/StringUtils.java +++ b/bval-core/src/main/java/org/apache/bval/util/StringUtils.java @@ -17,8 +17,6 @@ package org.apache.bval.util; import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; import java.util.List; public final class StringUtils { @@ -93,49 +91,24 @@ public final class StringUtils { return true; } - public static String join(Collection<?> values, String joinToken) { - if (values == null) { - return null; - } - if (values.size() == 0) { - return ""; - } - if (values.size() == 1) { - return values.iterator().next().toString(); - } - if (joinToken == null) { - joinToken = "null"; // backward compat with commons-lang StringUtils... - } - - StringBuilder sb = new StringBuilder(values.size() * (16 + joinToken.length())); - Iterator<?> it = values.iterator(); - sb.append(it.next()); - while (it.hasNext()) { - sb.append(joinToken).append(it.next()); - } - return sb.toString(); - } - - public static String joinArray(Object[] values, String joinToken) { - if (values == null) { - return null; - } - if (values.length == 0) { - return ""; - } - if (values.length == 1) { - return values[0].toString(); - } - if (joinToken == null) { - joinToken = "null"; // backward compat with commons-lang StringUtils... - } - - StringBuilder sb = new StringBuilder(values.length * (16 + joinToken.length())); - sb.append(values[0]); - for (int i = 1; i < values.length; i++) { - sb.append(joinToken).append(values[i]); - } - return sb.toString(); + /** + * Taken from commons-lang3. + * <p>Checks if a CharSequence is not empty (""), not null and not whitespace only.</p> + * + * <pre> + * StringUtils.isNotBlank(null) = false + * StringUtils.isNotBlank("") = false + * StringUtils.isNotBlank(" ") = false + * StringUtils.isNotBlank("bob") = true + * StringUtils.isNotBlank(" bob ") = true + * </pre> + * + * @param cs the CharSequence to check, may be null + * @return {@code true} if the CharSequence is + * not empty and not null and not whitespace + */ + public static boolean isNotBlank(final CharSequence cs) { + return !isBlank(cs); } /** @@ -149,12 +122,12 @@ public final class StringUtils { * <p>Splits the provided text into an array, separator is whitespace. */ public static String[] split(String str, Character token) { - if (str == null || str.length() == 0) { + if (str == null || str.isEmpty()) { return ObjectUtils.EMPTY_STRING_ARRAY; } // split on token - List<String> ret = new ArrayList<String>(); + List<String> ret = new ArrayList<>(); StringBuilder sb = new StringBuilder(str.length()); for (int pos = 0; pos < str.length(); pos++) { char c = str.charAt(pos); http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/util/Validate.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/util/Validate.java b/bval-core/src/main/java/org/apache/bval/util/Validate.java index f0e0611..5e78402 100644 --- a/bval-core/src/main/java/org/apache/bval/util/Validate.java +++ b/bval-core/src/main/java/org/apache/bval/util/Validate.java @@ -16,9 +16,10 @@ */ package org.apache.bval.util; +import java.util.Objects; + /** - * Some used Validate from commons. - * + * Some used validations from commons. */ public final class Validate { private Validate() { @@ -29,10 +30,7 @@ public final class Validate { } public static <T> T notNull(final T object, final String message, final Object... values) { - if (object == null) { - throw new NullPointerException(String.format(message, values)); - } - return object; + return Objects.requireNonNull(object, () -> String.format(message, values)); } public static void isTrue(final boolean expression, final String message, final Object... values) { @@ -41,4 +39,20 @@ public final class Validate { } } + public static <T> T[] noNullElements(final T[] array, final String message, final Object... values) { + Validate.notNull(array); + for (int i = 0; i < array.length; i++) { + if (array[i] == null) { + final Object[] values2 = ObjectUtils.arrayAdd(values, Integer.valueOf(i)); + throw new IllegalArgumentException(String.format(message, values2)); + } + } + return array; + } + + public static void validState(final boolean expression, final String message, final Object... values) { + if (expression == false) { + throw new IllegalStateException(String.format(message, values)); + } + } } http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java b/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java index 674cf94..221a277 100644 --- a/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java +++ b/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java @@ -24,8 +24,16 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; import org.apache.commons.weaver.privilizer.Privilizing; @@ -33,36 +41,44 @@ import org.apache.commons.weaver.privilizer.Privilizing; * Security-agnostic "blueprint" class for reflection-related operations. Intended for use by Apache BVal code. */ public class Reflection { + /** + * Inclusivity literals for {@link #hierarchy(Class, Interfaces)}. + * Taken from commons-lang3. + */ + public enum Interfaces { + INCLUDE, EXCLUDE + } + private static final Object[][] NATIVE_CODES = new Object[][]{ - {byte.class, "byte", "B"}, - {char.class, "char", "C"}, - {double.class, "double", "D"}, - {float.class, "float", "F"}, - {int.class, "int", "I"}, - {long.class, "long", "J"}, - {short.class, "short", "S"}, - {boolean.class, "boolean", "Z"}, - {void.class, "void", "V"} + { byte.class, "byte", "B" }, + { char.class, "char", "C" }, + { double.class, "double", "D" }, + { float.class, "float", "F" }, + { int.class, "int", "I" }, + { long.class, "long", "J" }, + { short.class, "short", "S" }, + { boolean.class, "boolean", "Z" }, + { void.class, "void", "V" } }; /** * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. */ - private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_MAP = new HashMap<Class<?>, Class<?>>(); + private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_MAP; static { - PRIMITIVE_WRAPPER_MAP.put(Boolean.TYPE, Boolean.class); - PRIMITIVE_WRAPPER_MAP.put(Byte.TYPE, Byte.class); - PRIMITIVE_WRAPPER_MAP.put(Character.TYPE, Character.class); - PRIMITIVE_WRAPPER_MAP.put(Short.TYPE, Short.class); - PRIMITIVE_WRAPPER_MAP.put(Integer.TYPE, Integer.class); - PRIMITIVE_WRAPPER_MAP.put(Long.TYPE, Long.class); - PRIMITIVE_WRAPPER_MAP.put(Double.TYPE, Double.class); - PRIMITIVE_WRAPPER_MAP.put(Float.TYPE, Float.class); - PRIMITIVE_WRAPPER_MAP.put(Void.TYPE, Void.TYPE); + final Map<Class<?>, Class<?>> m = new HashMap<>(); + m.put(Boolean.TYPE, Boolean.class); + m.put(Byte.TYPE, Byte.class); + m.put(Character.TYPE, Character.class); + m.put(Short.TYPE, Short.class); + m.put(Integer.TYPE, Integer.class); + m.put(Long.TYPE, Long.class); + m.put(Double.TYPE, Double.class); + m.put(Float.TYPE, Float.class); + m.put(Void.TYPE, Void.TYPE); + PRIMITIVE_WRAPPER_MAP = Collections.unmodifiableMap(m); } - - /** * <p>Converts the specified primitive Class object to its corresponding * wrapper Class object.</p> @@ -129,8 +145,7 @@ public class Reflection { return cl == null ? clazz.getClassLoader() : cl; } - public static Class<?> toClass(String className) throws ClassNotFoundException - { + public static Class<?> toClass(String className) throws ClassNotFoundException { ClassLoader cl = getClassLoader(Reflection.class); return toClass(className, cl); } @@ -142,7 +157,7 @@ public class Reflection { * * @throws RuntimeException on load error */ - public static Class toClass(String className, ClassLoader loader) throws ClassNotFoundException { + public static Class<?> toClass(String className, ClassLoader loader) throws ClassNotFoundException { return toClass(className, false, loader); } @@ -153,7 +168,7 @@ public class Reflection { * * @throws RuntimeException on load error */ - public static Class toClass(String className, boolean resolve, ClassLoader loader) throws ClassNotFoundException { + public static Class<?> toClass(String className, boolean resolve, ClassLoader loader) throws ClassNotFoundException { if (className == null) { throw new NullPointerException("className == null"); } @@ -171,7 +186,7 @@ public class Reflection { for (int i = 0; !primitive && (i < NATIVE_CODES.length); i++) { if (NATIVE_CODES[i][1].equals(className)) { if (dims == 0) { - return (Class) NATIVE_CODES[i][0]; + return (Class<?>) NATIVE_CODES[i][0]; } className = (String) NATIVE_CODES[i][2]; primitive = true; @@ -296,6 +311,22 @@ public class Reflection { } /** + * Perform a search against the class hierarchy. + * @param clazz + * @param search + * @return T or {@code null} + */ + public static <T> T find(final Class<?> clazz, Function<Class<?>, T> search) { + for (Class<?> t : hierarchy(clazz, Interfaces.INCLUDE)) { + final T value = search.apply(t); + if (value != null) { + return value; + } + } + return null; + } + + /** * Construct a new instance of {@code cls} using its default constructor. * @param cls * @return T @@ -333,4 +364,94 @@ public class Reflection { return true; } + /** + * Get an {@link Iterable} that can iterate over a class hierarchy in ascending (subclass to superclass) order. + * Taken from commons-lang3. + * + * @param type the type to get the class hierarchy from + * @param interfacesBehavior switch indicating whether to include or exclude interfaces + * @return Iterable an Iterable over the class hierarchy of the given class + */ + public static Iterable<Class<?>> hierarchy(final Class<?> type, final Interfaces interfacesBehavior) { + if (type == null) { + return Collections.emptySet(); + } + final Iterable<Class<?>> classes = new Iterable<Class<?>>() { + + @Override + public Iterator<Class<?>> iterator() { + return new Iterator<Class<?>>() { + Optional<Class<?>> next; + { + next = Optional.of(type); + } + + @Override + public boolean hasNext() { + return next.isPresent(); + } + + @Override + public Class<?> next() { + final Class<?> result = next.orElseThrow(NoSuchElementException::new); + next = Optional.ofNullable(result.getSuperclass()); + return result; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + }; + if (interfacesBehavior != Interfaces.INCLUDE) { + return classes; + } + return new Iterable<Class<?>>() { + + @Override + public Iterator<Class<?>> iterator() { + final Set<Class<?>> seenInterfaces = new HashSet<Class<?>>(); + final Iterator<Class<?>> wrapped = classes.iterator(); + + return new Iterator<Class<?>>() { + Iterator<Class<?>> interfaces = Collections.emptyIterator(); + + @Override + public boolean hasNext() { + return interfaces.hasNext() || wrapped.hasNext(); + } + + @Override + public Class<?> next() { + if (interfaces.hasNext()) { + final Class<?> nextInterface = interfaces.next(); + seenInterfaces.add(nextInterface); + return nextInterface; + } + final Class<?> nextSuperclass = wrapped.next(); + final Set<Class<?>> currentInterfaces = new LinkedHashSet<>(); + walkInterfaces(currentInterfaces, nextSuperclass); + interfaces = currentInterfaces.iterator(); + return nextSuperclass; + } + + private void walkInterfaces(final Set<Class<?>> addTo, final Class<?> c) { + for (final Class<?> iface : c.getInterfaces()) { + if (!seenInterfaces.contains(iface)) { + addTo.add(iface); + } + walkInterfaces(addTo, iface); + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + }; + } } http://git-wip-us.apache.org/repos/asf/bval/blob/99eb42a2/bval-core/src/main/java/org/apache/bval/util/reflection/TypeUtils.java ---------------------------------------------------------------------- diff --git a/bval-core/src/main/java/org/apache/bval/util/reflection/TypeUtils.java b/bval-core/src/main/java/org/apache/bval/util/reflection/TypeUtils.java index 4734906..b8b044d 100644 --- a/bval-core/src/main/java/org/apache/bval/util/reflection/TypeUtils.java +++ b/bval-core/src/main/java/org/apache/bval/util/reflection/TypeUtils.java @@ -28,8 +28,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.stream.Stream; +import org.apache.bval.util.ObjectUtils; import org.apache.bval.util.Validate; /** @@ -148,13 +151,7 @@ public class TypeUtils { */ @Override public int hashCode() { - int result = 71 << 4; - result |= raw.hashCode(); - result <<= 4; - result |= useOwner == null ? 0 : useOwner.hashCode(); - result <<= 8; - result |= Arrays.hashCode(typeArguments); - return result; + return Objects.hash(raw, useOwner, typeArguments); } } @@ -162,7 +159,8 @@ public class TypeUtils { * WildcardType implementation class. */ private static final class WildcardTypeImpl implements WildcardType { - private static final Type[] EMPTY_BOUNDS = new Type[0]; + private static final Type[] EMPTY_UPPER_BOUNDS = { Object.class }; + private static final Type[] EMPTY_LOWER_BOUNDS = new Type[0]; private final Type[] upperBounds; private final Type[] lowerBounds; @@ -173,8 +171,8 @@ public class TypeUtils { * @param lowerBounds of this type */ private WildcardTypeImpl(final Type[] upperBounds, final Type[] lowerBounds) { - this.upperBounds = upperBounds != null ? upperBounds : EMPTY_BOUNDS; - this.lowerBounds = lowerBounds != null ? lowerBounds : EMPTY_BOUNDS; + this.upperBounds = ObjectUtils.isEmpty(upperBounds) ? EMPTY_UPPER_BOUNDS : upperBounds; + this.lowerBounds = lowerBounds == null ? EMPTY_LOWER_BOUNDS : lowerBounds; } /** @@ -214,11 +212,7 @@ public class TypeUtils { */ @Override public int hashCode() { - int result = 73 << 8; - result |= Arrays.hashCode(upperBounds); - result <<= 8; - result |= Arrays.hashCode(lowerBounds); - return result; + return Objects.hash(upperBounds, lowerBounds); } } @@ -320,19 +314,13 @@ public class TypeUtils { if (type instanceof TypeVariable<?>) { // if any of the bounds are assignable to the class, then the // type is assignable to the class. - for (final Type bound : ((TypeVariable<?>) type).getBounds()) { - if (isAssignable(bound, toClass)) { - return true; - } - } - - return false; + return Stream.of(((TypeVariable<?>) type).getBounds()).anyMatch(bound -> isAssignable(bound, toClass)); } // the only classes to which a generic array type can be assigned // are class Object and array classes if (type instanceof GenericArrayType) { - return toClass.equals(Object.class) + return Object.class.equals(toClass) || toClass.isArray() && isAssignable(((GenericArrayType) type).getGenericComponentType(), toClass .getComponentType()); @@ -554,25 +542,15 @@ public class TypeUtils { if (type instanceof WildcardType) { // so long as one of the upper bounds is assignable, it's good - for (final Type bound : getImplicitUpperBounds((WildcardType) type)) { - if (isAssignable(bound, toGenericArrayType)) { - return true; - } - } - - return false; + return Stream.of(getImplicitUpperBounds((WildcardType) type)) + .anyMatch(bound -> isAssignable(bound, toGenericArrayType)); } if (type instanceof TypeVariable<?>) { // probably should remove the following logic and just return false. // type variables cannot specify arrays as bounds. - for (final Type bound : getImplicitBounds((TypeVariable<?>) type)) { - if (isAssignable(bound, toGenericArrayType)) { - return true; - } - } - - return false; + return Stream.of(getImplicitBounds((TypeVariable<?>) type)) + .anyMatch(bound -> isAssignable(bound, toGenericArrayType)); } if (type instanceof ParameterizedType) { @@ -871,8 +849,7 @@ public class TypeUtils { getRawType(parameterizedOwnerType), subtypeVarAssigns); } else { // no owner, prep the type variable assignments map - typeVarAssigns = subtypeVarAssigns == null ? new HashMap<TypeVariable<?>, Type>() - : new HashMap<TypeVariable<?>, Type>(subtypeVarAssigns); + typeVarAssigns = subtypeVarAssigns == null ? new HashMap<>() : new HashMap<>(subtypeVarAssigns); } // get the subject parameterized type's arguments @@ -917,7 +894,7 @@ public class TypeUtils { if (toClass.isPrimitive()) { // dealing with widening here. No type arguments to be // harvested with these two types. - return new HashMap<TypeVariable<?>, Type>(); + return new HashMap<>(); } // work with wrapper the wrapper class instead of the primitive @@ -925,8 +902,8 @@ public class TypeUtils { } // create a copy of the incoming map, or an empty one if it's null - final HashMap<TypeVariable<?>, Type> typeVarAssigns = subtypeVarAssigns == null ? new HashMap<TypeVariable<?>, Type>() - : new HashMap<TypeVariable<?>, Type>(subtypeVarAssigns); + final Map<TypeVariable<?>, Type> typeVarAssigns = + subtypeVarAssigns == null ? new HashMap<>() : new HashMap<>(subtypeVarAssigns); // has target class been reached? if (toClass.equals(cls)) { @@ -1030,7 +1007,7 @@ public class TypeUtils { return bounds; } - final Set<Type> types = new HashSet<Type>(bounds.length); + final Set<Type> types = new HashSet<>(bounds.length); for (final Type type1 : bounds) { boolean subtypeFound = false; @@ -1243,7 +1220,7 @@ public class TypeUtils { if (p.getOwnerType() == null) { parameterizedTypeArguments = typeArguments; } else { - parameterizedTypeArguments = new HashMap<TypeVariable<?>, Type>(typeArguments); + parameterizedTypeArguments = new HashMap<>(typeArguments); parameterizedTypeArguments.putAll(TypeUtils.getTypeArguments(p)); } final Type[] args = p.getActualTypeArguments();
