Migrate toward java.util.function

- Package-private changes only
- Maintains binary and source compatibility
This commit is contained in:
Gary Gregory 2024-07-11 13:50:10 -04:00
parent 54cc2a9c77
commit 30e627659a
28 changed files with 42 additions and 42 deletions

View File

@ -560,7 +560,7 @@ public class CollectionUtils {
if (inputIterator != null && transformer != null) {
while (inputIterator.hasNext()) {
final I item = inputIterator.next();
final O value = transformer.transform(item);
final O value = transformer.apply(item);
outputCollection.add(value);
}
}
@ -2068,7 +2068,7 @@ public class CollectionUtils {
if (collection instanceof List<?>) {
final List<C> list = (List<C>) collection;
for (final ListIterator<C> it = list.listIterator(); it.hasNext();) {
it.set(transformer.transform(it.next()));
it.set(transformer.apply(it.next()));
}
} else {
final Collection<C> resultCollection = collect(collection, transformer);

View File

@ -1312,7 +1312,7 @@ public class IteratorUtils {
if (iterator != null) {
while (iterator.hasNext()) {
final E element = iterator.next();
stringBuilder.append(transformer.transform(element));
stringBuilder.append(transformer.apply(element));
stringBuilder.append(delimiter);
}
if (stringBuilder.length() > prefix.length()) {

View File

@ -1497,7 +1497,7 @@ public class MapUtils {
public static <K, V, E> void populateMap(final Map<K, V> map, final Iterable<? extends E> elements,
final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) {
for (final E temp : elements) {
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
map.put(keyTransformer.apply(temp), valueTransformer.apply(temp));
}
}
@ -1532,7 +1532,7 @@ public class MapUtils {
public static <K, V, E> void populateMap(final MultiMap<K, V> map, final Iterable<? extends E> elements,
final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) {
for (final E temp : elements) {
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
map.put(keyTransformer.apply(temp), valueTransformer.apply(temp));
}
}

View File

@ -65,7 +65,7 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
bag.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -65,7 +65,7 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
bag.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -145,7 +145,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
* enforces a uniqueness constraint
*/
private void addToIndex(final C object) {
final K key = keyTransformer.transform(object);
final K key = keyTransformer.apply(object);
if (uniqueIndex && index.containsKey(key)) {
throw new IllegalArgumentException("Duplicate key in uniquely indexed collection.");
}
@ -166,7 +166,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
@SuppressWarnings("unchecked")
@Override
public boolean contains(final Object object) {
return index.containsKey(keyTransformer.transform((C) object));
return index.containsKey(keyTransformer.apply((C) object));
}
/**
@ -236,7 +236,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
* @param object the object to remove
*/
private void removeFromIndex(final C object) {
index.remove(keyTransformer.transform(object));
index.remove(keyTransformer.apply(object));
}
/**

View File

@ -68,7 +68,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
final E[] values = (E[]) collection.toArray(); // NOPMD - false positive for generics
collection.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;
@ -146,7 +146,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
* @return a transformed object
*/
protected E transform(final E object) {
return transformer.transform(object);
return transformer.apply(object);
}
}

View File

@ -81,8 +81,8 @@ public class TransformingComparator<I, O> implements Comparator<I>, Serializable
*/
@Override
public int compare(final I obj1, final I obj2) {
final O value1 = this.transformer.transform(obj1);
final O value2 = this.transformer.transform(obj2);
final O value1 = this.transformer.apply(obj1);
final O value2 = this.transformer.apply(obj2);
return this.decorated.compare(value1, value2);
}

View File

@ -120,7 +120,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
@Override
public T transform(T object) {
for (final Transformer<? super T, ? extends T> iTransformer : iTransformers) {
object = iTransformer.transform(object);
object = iTransformer.apply(object);
}
return object;
}

View File

@ -134,8 +134,8 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
@Override
public O transform(final I input) {
if (iPredicate.test(input)) {
return iTrueTransformer.transform(input);
return iTrueTransformer.apply(input);
}
return iFalseTransformer.transform(input);
return iFalseTransformer.apply(input);
}
}

View File

@ -188,10 +188,10 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
public O transform(final I input) {
for (int i = 0; i < iPredicates.length; i++) {
if (iPredicates[i].test(input)) {
return iTransformers[i].transform(input);
return iTransformers[i].apply(input);
}
}
return iDefault.transform(input);
return iDefault.apply(input);
}
}

View File

@ -77,7 +77,7 @@ public final class TransformedPredicate<T> extends AbstractPredicate<T> implemen
*/
@Override
public boolean test(final T object) {
final T result = iTransformer.transform(object);
final T result = iTransformer.apply(object);
return iPredicate.test(result);
}

View File

@ -69,7 +69,7 @@ public class TransformerClosure<T> implements Closure<T>, Serializable {
*/
@Override
public void execute(final T input) {
iTransformer.transform(input);
iTransformer.apply(input);
}
/**

View File

@ -68,7 +68,7 @@ public final class TransformerPredicate<T> extends AbstractPredicate<T> implemen
*/
@Override
public boolean test(final T object) {
final Boolean result = iTransformer.transform(object);
final Boolean result = iTransformer.apply(object);
if (result == null) {
throw new FunctorException(
"Transformer must return an instanceof Boolean, it was a null object");

View File

@ -160,7 +160,7 @@ public class ObjectGraphIterator<E> implements Iterator<E> {
while (currentIterator.hasNext() && !hasNext) {
E next = currentIterator.next();
if (transformer != null) {
next = transformer.transform(next);
next = transformer.apply(next);
}
findNext(next);
}
@ -238,7 +238,7 @@ public class ObjectGraphIterator<E> implements Iterator<E> {
if (transformer == null) {
findNext(root);
} else {
findNext(transformer.transform(root));
findNext(transformer.apply(root));
}
root = null;
}

View File

@ -133,6 +133,6 @@ public class TransformIterator<I, O> implements Iterator<O> {
* @return the transformed object
*/
protected O transform(final I source) {
return transformer.transform(source);
return transformer.apply(source);
}
}

View File

@ -134,7 +134,7 @@ public class LazyList<E> extends AbstractSerializableListDecorator<E> {
return factory.get();
}
if (transformer != null) {
return transformer.transform(index);
return transformer.apply(index);
}
throw new IllegalStateException("Factory and Transformer are both null!");
}

View File

@ -93,7 +93,7 @@ public class TransformedList<E> extends TransformedCollection<E> implements List
final E[] values = (E[]) list.toArray(); // NOPMD - false positive for generics
list.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -173,7 +173,7 @@ public class DefaultedMap<K, V> extends AbstractMapDecorator<K, V> implements Se
final V v;
return (v = map.get(key)) != null || map.containsKey(key)
? v
: value.transform((K) key);
: value.apply((K) key);
}
/**

View File

@ -135,7 +135,7 @@ public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Seriali
if (!map.containsKey(key)) {
@SuppressWarnings("unchecked")
final K castKey = (K) key;
final V value = factory.transform(castKey);
final V value = factory.apply(castKey);
map.put(castKey, value);
return value;
}

View File

@ -315,7 +315,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
* @return the new collection
*/
protected Collection<V> createCollection(final int size) {
return collectionFactory.create();
return collectionFactory.get();
}
/**

View File

@ -139,7 +139,7 @@ public class TransformedMap<K, V>
*/
@Override
protected V checkSetValue(final V value) {
return valueTransformer.transform(value);
return valueTransformer.apply(value);
}
/**
@ -192,7 +192,7 @@ public class TransformedMap<K, V>
if (keyTransformer == null) {
return object;
}
return keyTransformer.transform(object);
return keyTransformer.apply(object);
}
/**
@ -228,7 +228,7 @@ public class TransformedMap<K, V>
if (valueTransformer == null) {
return object;
}
return valueTransformer.transform(object);
return valueTransformer.apply(object);
}
/**

View File

@ -167,7 +167,7 @@ public class TransformedMultiValuedMap<K, V> extends AbstractMultiValuedMapDecor
if (keyTransformer == null) {
return object;
}
return keyTransformer.transform(object);
return keyTransformer.apply(object);
}
/**
@ -182,7 +182,7 @@ public class TransformedMultiValuedMap<K, V> extends AbstractMultiValuedMapDecor
if (valueTransformer == null) {
return object;
}
return valueTransformer.transform(object);
return valueTransformer.apply(object);
}
}

View File

@ -62,7 +62,7 @@ public class TransformedQueue<E> extends TransformedCollection<E> implements Que
final E[] values = (E[]) queue.toArray(); // NOPMD - false positive for generics
queue.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -61,7 +61,7 @@ public class TransformedNavigableSet<E> extends TransformedSortedSet<E> implemen
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
set.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -63,7 +63,7 @@ public class TransformedSet<E> extends TransformedCollection<E> implements Set<E
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
set.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -65,7 +65,7 @@ public class TransformedSortedSet<E> extends TransformedSet<E> implements Sorted
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
set.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
decorated.decorated().add(transformer.apply(value));
}
}
return decorated;

View File

@ -124,7 +124,7 @@ public class TransformedSplitMap<J, K, U, V> extends AbstractIterableGetMapDecor
* @return the transformed value
*/
protected V checkSetValue(final U value) {
return valueTransformer.transform(value);
return valueTransformer.apply(value);
}
@Override
@ -165,7 +165,7 @@ public class TransformedSplitMap<J, K, U, V> extends AbstractIterableGetMapDecor
* @return the transformed object
*/
protected K transformKey(final J object) {
return keyTransformer.transform(object);
return keyTransformer.apply(object);
}
/**
@ -198,7 +198,7 @@ public class TransformedSplitMap<J, K, U, V> extends AbstractIterableGetMapDecor
* @return the transformed object
*/
protected V transformValue(final U object) {
return valueTransformer.transform(object);
return valueTransformer.apply(object);
}
/**