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) {
ObjectUtils.requireNonEmpty(array, "array");
boolean result = false;
for (boolean element: array) {
for (final boolean element: array) {
if (element) {
if (result) {
return false;

View File

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

View File

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

View File

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