Use Stream

This commit is contained in:
Gary Gregory 2022-08-21 15:22:21 -04:00
parent f8df864f4c
commit 6de0fc1ae5
4 changed files with 8 additions and 18 deletions

View File

@ -263,7 +263,7 @@ public class BooleanUtils {
public static boolean oneHot(final boolean... array) { public static boolean oneHot(final boolean... array) {
ObjectUtils.requireNonEmpty(array, "array"); ObjectUtils.requireNonEmpty(array, "array");
boolean result = false; boolean result = false;
for (boolean element: array) { for (final boolean element: array) {
if (element) { if (element) {
if (result) { if (result) {
return false; return false;

View File

@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream;
/** /**
* <p>A set of characters.</p> * <p>A set of characters.</p>
@ -172,9 +173,7 @@ public class CharSet implements Serializable {
* @throws NullPointerException if set is {@code null} * @throws NullPointerException if set is {@code null}
*/ */
protected CharSet(final String... set) { protected CharSet(final String... set) {
for (final String s : set) { Stream.of(set).forEach(this::add);
add(s);
}
} }
/** /**

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.lang3; package org.apache.commons.lang3;
import org.apache.commons.lang3.stream.Streams;
/** /**
* <p>Operations on {@link CharSet} instances.</p> * <p>Operations on {@link CharSet} instances.</p>
* *
@ -101,14 +103,7 @@ public class CharSetUtils {
* @return whether or not the String is empty * @return whether or not the String is empty
*/ */
private static boolean deepEmpty(final String[] strings) { private static boolean deepEmpty(final String[] strings) {
if (strings != null) { return Streams.of(strings).allMatch(StringUtils::isEmpty);
for (final String s : strings) {
if (StringUtils.isNotEmpty(s)) {
return false;
}
}
}
return true;
} }
/** /**

View File

@ -22,6 +22,7 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -578,12 +579,7 @@ public class DurationFormatUtils {
* @return boolean {@code true} if contained * @return boolean {@code true} if contained
*/ */
static boolean containsTokenWithValue(final Token[] tokens, final Object value) { static boolean containsTokenWithValue(final Token[] tokens, final Object value) {
for (final Token token : tokens) { return Stream.of(tokens).anyMatch(token -> token.getValue() == value);
if (token.getValue() == value) {
return true;
}
}
return false;
} }
private final Object value; private final Object value;