Migrate toward java.util.function
- Package-private changes only - Maintains binary and source compatibility
This commit is contained in:
parent
54cc2a9c77
commit
30e627659a
|
@ -560,7 +560,7 @@ public class CollectionUtils {
|
||||||
if (inputIterator != null && transformer != null) {
|
if (inputIterator != null && transformer != null) {
|
||||||
while (inputIterator.hasNext()) {
|
while (inputIterator.hasNext()) {
|
||||||
final I item = inputIterator.next();
|
final I item = inputIterator.next();
|
||||||
final O value = transformer.transform(item);
|
final O value = transformer.apply(item);
|
||||||
outputCollection.add(value);
|
outputCollection.add(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2068,7 +2068,7 @@ public class CollectionUtils {
|
||||||
if (collection instanceof List<?>) {
|
if (collection instanceof List<?>) {
|
||||||
final List<C> list = (List<C>) collection;
|
final List<C> list = (List<C>) collection;
|
||||||
for (final ListIterator<C> it = list.listIterator(); it.hasNext();) {
|
for (final ListIterator<C> it = list.listIterator(); it.hasNext();) {
|
||||||
it.set(transformer.transform(it.next()));
|
it.set(transformer.apply(it.next()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Collection<C> resultCollection = collect(collection, transformer);
|
final Collection<C> resultCollection = collect(collection, transformer);
|
||||||
|
|
|
@ -1312,7 +1312,7 @@ public class IteratorUtils {
|
||||||
if (iterator != null) {
|
if (iterator != null) {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final E element = iterator.next();
|
final E element = iterator.next();
|
||||||
stringBuilder.append(transformer.transform(element));
|
stringBuilder.append(transformer.apply(element));
|
||||||
stringBuilder.append(delimiter);
|
stringBuilder.append(delimiter);
|
||||||
}
|
}
|
||||||
if (stringBuilder.length() > prefix.length()) {
|
if (stringBuilder.length() > prefix.length()) {
|
||||||
|
|
|
@ -1497,7 +1497,7 @@ public class MapUtils {
|
||||||
public static <K, V, E> void populateMap(final Map<K, V> map, final Iterable<? extends E> elements,
|
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) {
|
final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) {
|
||||||
for (final E temp : elements) {
|
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,
|
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) {
|
final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) {
|
||||||
for (final E temp : elements) {
|
for (final E temp : elements) {
|
||||||
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
|
map.put(keyTransformer.apply(temp), valueTransformer.apply(temp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
|
||||||
bag.clear();
|
bag.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
|
||||||
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
|
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
|
||||||
bag.clear();
|
bag.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -145,7 +145,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
|
||||||
* enforces a uniqueness constraint
|
* enforces a uniqueness constraint
|
||||||
*/
|
*/
|
||||||
private void addToIndex(final C object) {
|
private void addToIndex(final C object) {
|
||||||
final K key = keyTransformer.transform(object);
|
final K key = keyTransformer.apply(object);
|
||||||
if (uniqueIndex && index.containsKey(key)) {
|
if (uniqueIndex && index.containsKey(key)) {
|
||||||
throw new IllegalArgumentException("Duplicate key in uniquely indexed collection.");
|
throw new IllegalArgumentException("Duplicate key in uniquely indexed collection.");
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(final Object object) {
|
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
|
* @param object the object to remove
|
||||||
*/
|
*/
|
||||||
private void removeFromIndex(final C object) {
|
private void removeFromIndex(final C object) {
|
||||||
index.remove(keyTransformer.transform(object));
|
index.remove(keyTransformer.apply(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
|
||||||
final E[] values = (E[]) collection.toArray(); // NOPMD - false positive for generics
|
final E[] values = (E[]) collection.toArray(); // NOPMD - false positive for generics
|
||||||
collection.clear();
|
collection.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
@ -146,7 +146,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
|
||||||
* @return a transformed object
|
* @return a transformed object
|
||||||
*/
|
*/
|
||||||
protected E transform(final E object) {
|
protected E transform(final E object) {
|
||||||
return transformer.transform(object);
|
return transformer.apply(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,8 @@ public class TransformingComparator<I, O> implements Comparator<I>, Serializable
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compare(final I obj1, final I obj2) {
|
public int compare(final I obj1, final I obj2) {
|
||||||
final O value1 = this.transformer.transform(obj1);
|
final O value1 = this.transformer.apply(obj1);
|
||||||
final O value2 = this.transformer.transform(obj2);
|
final O value2 = this.transformer.apply(obj2);
|
||||||
return this.decorated.compare(value1, value2);
|
return this.decorated.compare(value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public T transform(T object) {
|
public T transform(T object) {
|
||||||
for (final Transformer<? super T, ? extends T> iTransformer : iTransformers) {
|
for (final Transformer<? super T, ? extends T> iTransformer : iTransformers) {
|
||||||
object = iTransformer.transform(object);
|
object = iTransformer.apply(object);
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,8 +134,8 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public O transform(final I input) {
|
||||||
if (iPredicate.test(input)) {
|
if (iPredicate.test(input)) {
|
||||||
return iTrueTransformer.transform(input);
|
return iTrueTransformer.apply(input);
|
||||||
}
|
}
|
||||||
return iFalseTransformer.transform(input);
|
return iFalseTransformer.apply(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,10 +188,10 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
public O transform(final I input) {
|
public O transform(final I input) {
|
||||||
for (int i = 0; i < iPredicates.length; i++) {
|
for (int i = 0; i < iPredicates.length; i++) {
|
||||||
if (iPredicates[i].test(input)) {
|
if (iPredicates[i].test(input)) {
|
||||||
return iTransformers[i].transform(input);
|
return iTransformers[i].apply(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return iDefault.transform(input);
|
return iDefault.apply(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public final class TransformedPredicate<T> extends AbstractPredicate<T> implemen
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final T object) {
|
public boolean test(final T object) {
|
||||||
final T result = iTransformer.transform(object);
|
final T result = iTransformer.apply(object);
|
||||||
return iPredicate.test(result);
|
return iPredicate.test(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class TransformerClosure<T> implements Closure<T>, Serializable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(final T input) {
|
public void execute(final T input) {
|
||||||
iTransformer.transform(input);
|
iTransformer.apply(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -68,7 +68,7 @@ public final class TransformerPredicate<T> extends AbstractPredicate<T> implemen
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final T object) {
|
public boolean test(final T object) {
|
||||||
final Boolean result = iTransformer.transform(object);
|
final Boolean result = iTransformer.apply(object);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new FunctorException(
|
throw new FunctorException(
|
||||||
"Transformer must return an instanceof Boolean, it was a null object");
|
"Transformer must return an instanceof Boolean, it was a null object");
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class ObjectGraphIterator<E> implements Iterator<E> {
|
||||||
while (currentIterator.hasNext() && !hasNext) {
|
while (currentIterator.hasNext() && !hasNext) {
|
||||||
E next = currentIterator.next();
|
E next = currentIterator.next();
|
||||||
if (transformer != null) {
|
if (transformer != null) {
|
||||||
next = transformer.transform(next);
|
next = transformer.apply(next);
|
||||||
}
|
}
|
||||||
findNext(next);
|
findNext(next);
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ public class ObjectGraphIterator<E> implements Iterator<E> {
|
||||||
if (transformer == null) {
|
if (transformer == null) {
|
||||||
findNext(root);
|
findNext(root);
|
||||||
} else {
|
} else {
|
||||||
findNext(transformer.transform(root));
|
findNext(transformer.apply(root));
|
||||||
}
|
}
|
||||||
root = null;
|
root = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,6 @@ public class TransformIterator<I, O> implements Iterator<O> {
|
||||||
* @return the transformed object
|
* @return the transformed object
|
||||||
*/
|
*/
|
||||||
protected O transform(final I source) {
|
protected O transform(final I source) {
|
||||||
return transformer.transform(source);
|
return transformer.apply(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class LazyList<E> extends AbstractSerializableListDecorator<E> {
|
||||||
return factory.get();
|
return factory.get();
|
||||||
}
|
}
|
||||||
if (transformer != null) {
|
if (transformer != null) {
|
||||||
return transformer.transform(index);
|
return transformer.apply(index);
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Factory and Transformer are both null!");
|
throw new IllegalStateException("Factory and Transformer are both null!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class TransformedList<E> extends TransformedCollection<E> implements List
|
||||||
final E[] values = (E[]) list.toArray(); // NOPMD - false positive for generics
|
final E[] values = (E[]) list.toArray(); // NOPMD - false positive for generics
|
||||||
list.clear();
|
list.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class DefaultedMap<K, V> extends AbstractMapDecorator<K, V> implements Se
|
||||||
final V v;
|
final V v;
|
||||||
return (v = map.get(key)) != null || map.containsKey(key)
|
return (v = map.get(key)) != null || map.containsKey(key)
|
||||||
? v
|
? v
|
||||||
: value.transform((K) key);
|
: value.apply((K) key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Seriali
|
||||||
if (!map.containsKey(key)) {
|
if (!map.containsKey(key)) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final K castKey = (K) key;
|
final K castKey = (K) key;
|
||||||
final V value = factory.transform(castKey);
|
final V value = factory.apply(castKey);
|
||||||
map.put(castKey, value);
|
map.put(castKey, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,7 +315,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
||||||
* @return the new collection
|
* @return the new collection
|
||||||
*/
|
*/
|
||||||
protected Collection<V> createCollection(final int size) {
|
protected Collection<V> createCollection(final int size) {
|
||||||
return collectionFactory.create();
|
return collectionFactory.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class TransformedMap<K, V>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected V checkSetValue(final V value) {
|
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) {
|
if (keyTransformer == null) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
return keyTransformer.transform(object);
|
return keyTransformer.apply(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,7 +228,7 @@ public class TransformedMap<K, V>
|
||||||
if (valueTransformer == null) {
|
if (valueTransformer == null) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
return valueTransformer.transform(object);
|
return valueTransformer.apply(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class TransformedMultiValuedMap<K, V> extends AbstractMultiValuedMapDecor
|
||||||
if (keyTransformer == null) {
|
if (keyTransformer == null) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
return keyTransformer.transform(object);
|
return keyTransformer.apply(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,7 +182,7 @@ public class TransformedMultiValuedMap<K, V> extends AbstractMultiValuedMapDecor
|
||||||
if (valueTransformer == null) {
|
if (valueTransformer == null) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
return valueTransformer.transform(object);
|
return valueTransformer.apply(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class TransformedQueue<E> extends TransformedCollection<E> implements Que
|
||||||
final E[] values = (E[]) queue.toArray(); // NOPMD - false positive for generics
|
final E[] values = (E[]) queue.toArray(); // NOPMD - false positive for generics
|
||||||
queue.clear();
|
queue.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class TransformedNavigableSet<E> extends TransformedSortedSet<E> implemen
|
||||||
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
||||||
set.clear();
|
set.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -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
|
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
||||||
set.clear();
|
set.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class TransformedSortedSet<E> extends TransformedSet<E> implements Sorted
|
||||||
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
||||||
set.clear();
|
set.clear();
|
||||||
for (final E value : values) {
|
for (final E value : values) {
|
||||||
decorated.decorated().add(transformer.transform(value));
|
decorated.decorated().add(transformer.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decorated;
|
return decorated;
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class TransformedSplitMap<J, K, U, V> extends AbstractIterableGetMapDecor
|
||||||
* @return the transformed value
|
* @return the transformed value
|
||||||
*/
|
*/
|
||||||
protected V checkSetValue(final U value) {
|
protected V checkSetValue(final U value) {
|
||||||
return valueTransformer.transform(value);
|
return valueTransformer.apply(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,7 +165,7 @@ public class TransformedSplitMap<J, K, U, V> extends AbstractIterableGetMapDecor
|
||||||
* @return the transformed object
|
* @return the transformed object
|
||||||
*/
|
*/
|
||||||
protected K transformKey(final J 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
|
* @return the transformed object
|
||||||
*/
|
*/
|
||||||
protected V transformValue(final U object) {
|
protected V transformValue(final U object) {
|
||||||
return valueTransformer.transform(object);
|
return valueTransformer.apply(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue