Consistent use of ClassUtils.toClassArray (and related polishing)

This commit is contained in:
Juergen Hoeller
2018-02-22 14:27:57 +01:00
parent caed04473e
commit 8b071633d3
20 changed files with 110 additions and 104 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1064,11 +1064,12 @@ public abstract class ClassUtils {
}
/**
* Copy the given Collection into a Class array.
* The Collection must contain Class elements only.
* @param collection the Collection to copy
* @return the Class array ({@code null} if the passed-in
* Collection was {@code null})
* Copy the given {@code Collection} into a {@code Class} array.
* <p>The {@code Collection} must contain {@code Class} elements only.
* @param collection the {@code Collection} to copy
* @return the {@code Class} array
* @since 3.1
* @see StringUtils#toStringArray
*/
public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
if (collection == null) {
@@ -1109,8 +1110,7 @@ public abstract class ClassUtils {
* @return all interfaces that the given object implements as an array
*/
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
return ifcs.toArray(new Class<?>[ifcs.size()]);
return toClassArray(getAllInterfacesForClassAsSet(clazz, classLoader));
}
/**
@@ -1150,12 +1150,13 @@ public abstract class ClassUtils {
return Collections.<Class<?>>singleton(clazz);
}
Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
while (clazz != null) {
Class<?>[] ifcs = clazz.getInterfaces();
Class<?> current = clazz;
while (current != null) {
Class<?>[] ifcs = current.getInterfaces();
for (Class<?> ifc : ifcs) {
interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
}
clazz = clazz.getSuperclass();
current = current.getSuperclass();
}
return interfaces;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -824,13 +824,9 @@ public abstract class StringUtils {
return array1;
}
List<String> result = new ArrayList<String>();
Set<String> result = new LinkedHashSet<String>();
result.addAll(Arrays.asList(array1));
for (String str : array2) {
if (!result.contains(str)) {
result.add(str);
}
}
result.addAll(Arrays.asList(array2));
return toStringArray(result);
}
@@ -858,7 +854,6 @@ public abstract class StringUtils {
if (collection == null) {
return null;
}
return collection.toArray(new String[collection.size()]);
}
@@ -872,9 +867,7 @@ public abstract class StringUtils {
if (enumeration == null) {
return null;
}
List<String> list = Collections.list(enumeration);
return list.toArray(new String[list.size()]);
return toStringArray(Collections.list(enumeration));
}
/**
@@ -939,10 +932,9 @@ public abstract class StringUtils {
/**
* Take an array of strings and split each element based on the given delimiter.
* A {@code Properties} instance is then generated, with the left of the
* delimiter providing the key, and the right of the delimiter providing the value.
* <p>Will trim both the key and value before adding them to the
* {@code Properties} instance.
* A {@code Properties} instance is then generated, with the left of the delimiter
* providing the key, and the right of the delimiter providing the value.
* <p>Will trim both the key and value before adding them to the {@code Properties}.
* @param array the array to process
* @param delimiter to split each element using (typically the equals symbol)
* @return a {@code Properties} instance representing the array contents,