Use forEach()
This commit is contained in:
parent
46b15a2ecb
commit
2c16052f94
|
@ -231,14 +231,9 @@ public class CharSet implements Serializable {
|
||||||
* @return {@code true} if the set contains the characters
|
* @return {@code true} if the set contains the characters
|
||||||
*/
|
*/
|
||||||
public boolean contains(final char ch) {
|
public boolean contains(final char ch) {
|
||||||
synchronized(set) {
|
synchronized (set) {
|
||||||
for (final CharRange range : set) {
|
return set.stream().anyMatch(range -> range.contains(ch));
|
||||||
if (range.contains(ch)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basics
|
// Basics
|
||||||
|
|
|
@ -127,13 +127,11 @@ public class ClassUtils {
|
||||||
private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap = new HashMap<>();
|
private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (final Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperMap.entrySet()) {
|
primitiveWrapperMap.forEach((primitiveClass, wrapperClass) -> {
|
||||||
final Class<?> primitiveClass = entry.getKey();
|
|
||||||
final Class<?> wrapperClass = entry.getValue();
|
|
||||||
if (!primitiveClass.equals(wrapperClass)) {
|
if (!primitiveClass.equals(wrapperClass)) {
|
||||||
wrapperPrimitiveMap.put(wrapperClass, primitiveClass);
|
wrapperPrimitiveMap.put(wrapperClass, primitiveClass);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,21 +146,17 @@ public class ClassUtils {
|
||||||
|
|
||||||
/** Feed abbreviation maps. */
|
/** Feed abbreviation maps. */
|
||||||
static {
|
static {
|
||||||
final Map<String, String> m = new HashMap<>();
|
final Map<String, String> map = new HashMap<>();
|
||||||
m.put("int", "I");
|
map.put("int", "I");
|
||||||
m.put("boolean", "Z");
|
map.put("boolean", "Z");
|
||||||
m.put("float", "F");
|
map.put("float", "F");
|
||||||
m.put("long", "J");
|
map.put("long", "J");
|
||||||
m.put("short", "S");
|
map.put("short", "S");
|
||||||
m.put("byte", "B");
|
map.put("byte", "B");
|
||||||
m.put("double", "D");
|
map.put("double", "D");
|
||||||
m.put("char", "C");
|
map.put("char", "C");
|
||||||
final Map<String, String> r = new HashMap<>();
|
abbreviationMap = Collections.unmodifiableMap(map);
|
||||||
for (final Map.Entry<String, String> e : m.entrySet()) {
|
reverseAbbreviationMap = Collections.unmodifiableMap(map.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)));
|
||||||
r.put(e.getValue(), e.getKey());
|
|
||||||
}
|
|
||||||
abbreviationMap = Collections.unmodifiableMap(m);
|
|
||||||
reverseAbbreviationMap = Collections.unmodifiableMap(r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,13 +205,13 @@ public class ClassUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<Class<?>> classes = new ArrayList<>(classNames.size());
|
final List<Class<?>> classes = new ArrayList<>(classNames.size());
|
||||||
for (final String className : classNames) {
|
classNames.forEach(className -> {
|
||||||
try {
|
try {
|
||||||
classes.add(Class.forName(className));
|
classes.add(Class.forName(className));
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
classes.add(null);
|
classes.add(null);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,10 +175,7 @@ public class EnumUtils {
|
||||||
asEnum(enumClass);
|
asEnum(enumClass);
|
||||||
Objects.requireNonNull(values, "values");
|
Objects.requireNonNull(values, "values");
|
||||||
final EnumSet<E> condensed = EnumSet.noneOf(enumClass);
|
final EnumSet<E> condensed = EnumSet.noneOf(enumClass);
|
||||||
for (final E constant : values) {
|
values.forEach(constant -> condensed.add(Validate.notNull(constant, NULL_ELEMENTS_NOT_PERMITTED)));
|
||||||
Validate.notNull(constant, NULL_ELEMENTS_NOT_PERMITTED);
|
|
||||||
condensed.add(constant);
|
|
||||||
}
|
|
||||||
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
|
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
|
||||||
for (final E value : condensed) {
|
for (final E value : condensed) {
|
||||||
result[value.ordinal() / Long.SIZE] |= 1L << (value.ordinal() % Long.SIZE);
|
result[value.ordinal() / Long.SIZE] |= 1L << (value.ordinal() % Long.SIZE);
|
||||||
|
|
|
@ -365,9 +365,7 @@ public class ThreadUtils {
|
||||||
|
|
||||||
final Collection<Thread> result = new ArrayList<>();
|
final Collection<Thread> result = new ArrayList<>();
|
||||||
final NamePredicate threadNamePredicate = new NamePredicate(threadName);
|
final NamePredicate threadNamePredicate = new NamePredicate(threadName);
|
||||||
for (final ThreadGroup group : threadGroups) {
|
threadGroups.forEach(group -> result.addAll(findThreads(group, false, threadNamePredicate)));
|
||||||
result.addAll(findThreads(group, false, threadNamePredicate));
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableCollection(result);
|
return Collections.unmodifiableCollection(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.ClassUtils;
|
import org.apache.commons.lang3.ClassUtils;
|
||||||
|
@ -247,14 +248,7 @@ public class FieldUtils {
|
||||||
*/
|
*/
|
||||||
public static List<Field> getFieldsListWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls) {
|
public static List<Field> getFieldsListWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls) {
|
||||||
Validate.notNull(annotationCls, "annotationCls");
|
Validate.notNull(annotationCls, "annotationCls");
|
||||||
final List<Field> allFields = getAllFieldsList(cls);
|
return getAllFieldsList(cls).stream().filter(field -> field.getAnnotation(annotationCls) != null).collect(Collectors.toList());
|
||||||
final List<Field> annotatedFields = new ArrayList<>();
|
|
||||||
for (final Field field : allFields) {
|
|
||||||
if (field.getAnnotation(annotationCls) != null) {
|
|
||||||
annotatedFields.add(field);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return annotatedFields;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -924,10 +924,10 @@ public class MethodUtils {
|
||||||
final List<Class<?>> classes = searchSupers ? getAllSuperclassesAndInterfaces(cls) : new ArrayList<>();
|
final List<Class<?>> classes = searchSupers ? getAllSuperclassesAndInterfaces(cls) : new ArrayList<>();
|
||||||
classes.add(0, cls);
|
classes.add(0, cls);
|
||||||
final List<Method> annotatedMethods = new ArrayList<>();
|
final List<Method> annotatedMethods = new ArrayList<>();
|
||||||
for (final Class<?> acls : classes) {
|
classes.forEach(acls -> {
|
||||||
final Method[] methods = ignoreAccess ? acls.getDeclaredMethods() : acls.getMethods();
|
final Method[] methods = ignoreAccess ? acls.getDeclaredMethods() : acls.getMethods();
|
||||||
Stream.of(methods).filter(method -> method.isAnnotationPresent(annotationCls)).forEachOrdered(annotatedMethods::add);
|
Stream.of(methods).filter(method -> method.isAnnotationPresent(annotationCls)).forEachOrdered(annotatedMethods::add);
|
||||||
}
|
});
|
||||||
return annotatedMethods;
|
return annotatedMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -523,11 +523,6 @@ public class ExtendedMessageFormat extends MessageFormat {
|
||||||
if (coll == null || coll.isEmpty()) {
|
if (coll == null || coll.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final Object name : coll) {
|
return coll.stream().anyMatch(Objects::nonNull);
|
||||||
if (name != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1222,9 +1222,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
||||||
*/
|
*/
|
||||||
public StrBuilder appendAll(final Iterable<?> iterable) {
|
public StrBuilder appendAll(final Iterable<?> iterable) {
|
||||||
if (iterable != null) {
|
if (iterable != null) {
|
||||||
for (final Object o : iterable) {
|
iterable.forEach(this::append);
|
||||||
append(o);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1240,9 +1238,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
||||||
*/
|
*/
|
||||||
public StrBuilder appendAll(final Iterator<?> it) {
|
public StrBuilder appendAll(final Iterator<?> it) {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
while (it.hasNext()) {
|
it.forEachRemaining(this::append);
|
||||||
append(it.next());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,20 +486,18 @@ public class FastDateParser implements DateParser, Serializable {
|
||||||
* @return The map of string display names to field values
|
* @return The map of string display names to field values
|
||||||
*/
|
*/
|
||||||
private static Map<String, Integer> appendDisplayNames(final Calendar calendar, Locale locale, final int field,
|
private static Map<String, Integer> appendDisplayNames(final Calendar calendar, Locale locale, final int field,
|
||||||
final StringBuilder regex) {
|
final StringBuilder regex) {
|
||||||
final Map<String, Integer> values = new HashMap<>();
|
final Map<String, Integer> values = new HashMap<>();
|
||||||
locale = LocaleUtils.toLocale(locale);
|
final Locale actualLocale = LocaleUtils.toLocale(locale);
|
||||||
final Map<String, Integer> displayNames = calendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
|
final Map<String, Integer> displayNames = calendar.getDisplayNames(field, Calendar.ALL_STYLES, actualLocale);
|
||||||
final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
|
final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
|
||||||
for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
|
displayNames.forEach((k, v) -> {
|
||||||
final String key = displayName.getKey().toLowerCase(locale);
|
final String keyLc = k.toLowerCase(actualLocale);
|
||||||
if (sorted.add(key)) {
|
if (sorted.add(keyLc)) {
|
||||||
values.put(key, displayName.getValue());
|
values.put(keyLc, v);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
for (final String symbol : sorted) {
|
sorted.forEach(symbol -> simpleQuote(regex, symbol).append('|'));
|
||||||
simpleQuote(regex, symbol).append('|');
|
|
||||||
}
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -953,9 +951,7 @@ public class FastDateParser implements DateParser, Serializable {
|
||||||
}
|
}
|
||||||
// order the regex alternatives with longer strings first, greedy
|
// order the regex alternatives with longer strings first, greedy
|
||||||
// match will ensure the longest string will be consumed
|
// match will ensure the longest string will be consumed
|
||||||
for (final String zoneName : sorted) {
|
sorted.forEach(zoneName -> simpleQuote(sb.append('|'), zoneName));
|
||||||
simpleQuote(sb.append('|'), zoneName);
|
|
||||||
}
|
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
createPattern(sb);
|
createPattern(sb);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue