Where possible:

- Add final modifier to private fields
- Add final modifier to method parameters
- Add final modifier to local variables

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1429905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2013-01-07 17:15:14 +00:00
parent 4f43347950
commit 9aea104d8a
423 changed files with 6718 additions and 6685 deletions

View File

@ -58,7 +58,7 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @throws IllegalArgumentException if the specified initial size
* is negative
*/
public ArrayStack(int initialSize) {
public ArrayStack(final int initialSize) {
super(initialSize);
}
@ -81,7 +81,7 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @throws EmptyStackException if the stack is empty
*/
public E peek() throws EmptyStackException {
int n = size();
final int n = size();
if (n <= 0) {
throw new EmptyStackException();
} else {
@ -98,8 +98,8 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @throws EmptyStackException if there are not enough items on the
* stack to satisfy this request
*/
public E peek(int n) throws EmptyStackException {
int m = (size() - n) - 1;
public E peek(final int n) throws EmptyStackException {
final int m = (size() - n) - 1;
if (m < 0) {
throw new EmptyStackException();
} else {
@ -114,7 +114,7 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @throws EmptyStackException if the stack is empty
*/
public E pop() throws EmptyStackException {
int n = size();
final int n = size();
if (n <= 0) {
throw new EmptyStackException();
} else {
@ -129,7 +129,7 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @param item the item to be added
* @return the item just pushed
*/
public E push(E item) {
public E push(final E item) {
add(item);
return item;
}
@ -145,11 +145,11 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @param object the object to be searched for
* @return the 1-based depth into the stack of the object, or -1 if not found
*/
public int search(Object object) {
public int search(final Object object) {
int i = size() - 1; // Current index
int n = 1; // Current distance
while (i >= 0) {
Object current = get(i);
final Object current = get(i);
if ((object == null && current == null) ||
(object != null && object.equals(current))) {
return n;
@ -167,7 +167,7 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @throws BufferUnderflowException if the stack is empty
*/
public E get() {
int size = size();
final int size = size();
if (size == 0) {
throw new BufferUnderflowException();
}
@ -181,7 +181,7 @@ public class ArrayStack<E> extends ArrayList<E> implements Buffer<E> {
* @throws BufferUnderflowException if the stack is empty
*/
public E remove() {
int size = size();
final int size = size();
if (size == 0) {
throw new BufferUnderflowException();
}

View File

@ -80,7 +80,7 @@ public class BagUtils {
* @return a synchronized bag backed by that bag
* @throws IllegalArgumentException if the Bag is null
*/
public static <E> Bag<E> synchronizedBag(Bag<E> bag) {
public static <E> Bag<E> synchronizedBag(final Bag<E> bag) {
return SynchronizedBag.synchronizedBag(bag);
}
@ -93,7 +93,7 @@ public class BagUtils {
* @return an unmodifiable view of that bag
* @throws IllegalArgumentException if the Bag is null
*/
public static <E> Bag<E> unmodifiableBag(Bag<E> bag) {
public static <E> Bag<E> unmodifiableBag(final Bag<E> bag) {
return UnmodifiableBag.unmodifiableBag(bag);
}
@ -112,7 +112,7 @@ public class BagUtils {
* @return a predicated bag backed by the given bag
* @throws IllegalArgumentException if the Bag or Predicate is null
*/
public static <E> Bag<E> predicatedBag(Bag<E> bag, Predicate<? super E> predicate) {
public static <E> Bag<E> predicatedBag(final Bag<E> bag, final Predicate<? super E> predicate) {
return PredicatedBag.predicatedBag(bag, predicate);
}
@ -132,7 +132,7 @@ public class BagUtils {
* @return a transformed bag backed by the given bag
* @throws IllegalArgumentException if the Bag or Transformer is null
*/
public static <E> Bag<E> transformingBag(Bag<E> bag, Transformer<? super E, ? extends E> transformer) {
public static <E> Bag<E> transformingBag(final Bag<E> bag, final Transformer<? super E, ? extends E> transformer) {
return TransformedBag.transformingBag(bag, transformer);
}
@ -163,7 +163,7 @@ public class BagUtils {
* @return a synchronized bag backed by that bag
* @throws IllegalArgumentException if the SortedBag is null
*/
public static <E> SortedBag<E> synchronizedSortedBag(SortedBag<E> bag) {
public static <E> SortedBag<E> synchronizedSortedBag(final SortedBag<E> bag) {
return SynchronizedSortedBag.synchronizedSortedBag(bag);
}
@ -177,7 +177,7 @@ public class BagUtils {
* @return an unmodifiable view of that bag
* @throws IllegalArgumentException if the SortedBag is null
*/
public static <E> SortedBag<E> unmodifiableSortedBag(SortedBag<E> bag) {
public static <E> SortedBag<E> unmodifiableSortedBag(final SortedBag<E> bag) {
return UnmodifiableSortedBag.unmodifiableSortedBag(bag);
}
@ -197,8 +197,8 @@ public class BagUtils {
* @return a predicated bag backed by the given bag
* @throws IllegalArgumentException if the SortedBag or Predicate is null
*/
public static <E> SortedBag<E> predicatedSortedBag(SortedBag<E> bag,
Predicate<? super E> predicate) {
public static <E> SortedBag<E> predicatedSortedBag(final SortedBag<E> bag,
final Predicate<? super E> predicate) {
return PredicatedSortedBag.predicatedSortedBag(bag, predicate);
}
@ -219,8 +219,8 @@ public class BagUtils {
* @return a transformed bag backed by the given bag
* @throws IllegalArgumentException if the Bag or Transformer is null
*/
public static <E> SortedBag<E> transformingSortedBag(SortedBag<E> bag,
Transformer<? super E, ? extends E> transformer) {
public static <E> SortedBag<E> transformingSortedBag(final SortedBag<E> bag,
final Transformer<? super E, ? extends E> transformer) {
return TransformedSortedBag.transformingSortedBag(bag, transformer);
}

View File

@ -40,7 +40,7 @@ public class BufferOverflowException extends RuntimeException {
*
* @param message the detail message for this exception
*/
public BufferOverflowException(String message) {
public BufferOverflowException(final String message) {
this(message, null);
}
@ -50,7 +50,7 @@ public class BufferOverflowException extends RuntimeException {
* @param message the detail message for this exception
* @param exception the root cause of the exception
*/
public BufferOverflowException(String message, Throwable exception) {
public BufferOverflowException(final String message, final Throwable exception) {
super(message, exception);
}

View File

@ -43,7 +43,7 @@ public class BufferUnderflowException extends NoSuchElementException {
*
* @param message the detail message for this exception
*/
public BufferUnderflowException(String message) {
public BufferUnderflowException(final String message) {
super(message);
}
@ -53,7 +53,7 @@ public class BufferUnderflowException extends NoSuchElementException {
* @param message the detail message for this exception
* @param exception the root cause of the exception
*/
public BufferUnderflowException(String message, Throwable exception) {
public BufferUnderflowException(final String message, final Throwable exception) {
super(message);
initCause(exception);
}

View File

@ -64,7 +64,7 @@ public class BufferUtils {
* @return a synchronized buffer backed by that buffer
* @throws IllegalArgumentException if the Buffer is null
*/
public static <E> Buffer<E> synchronizedBuffer(Buffer<E> buffer) {
public static <E> Buffer<E> synchronizedBuffer(final Buffer<E> buffer) {
return SynchronizedBuffer.synchronizedBuffer(buffer);
}
@ -81,7 +81,7 @@ public class BufferUtils {
* @return a blocking buffer backed by that buffer
* @throws IllegalArgumentException if the Buffer is null
*/
public static <E> Buffer<E> blockingBuffer(Buffer<E> buffer) {
public static <E> Buffer<E> blockingBuffer(final Buffer<E> buffer) {
return BlockingBuffer.blockingBuffer(buffer);
}
@ -100,7 +100,7 @@ public class BufferUtils {
* @throws IllegalArgumentException if the Buffer is null
* @since 3.2
*/
public static <E> Buffer<E> blockingBuffer(Buffer<E> buffer, long timeoutMillis) {
public static <E> Buffer<E> blockingBuffer(final Buffer<E> buffer, final long timeoutMillis) {
return BlockingBuffer.blockingBuffer(buffer, timeoutMillis);
}
@ -118,7 +118,7 @@ public class BufferUtils {
* @throws IllegalArgumentException if the given buffer is null
* @since 3.2
*/
public static <E> Buffer<E> boundedBuffer(Buffer<E> buffer, int maximumSize) {
public static <E> Buffer<E> boundedBuffer(final Buffer<E> buffer, final int maximumSize) {
return BoundedBuffer.boundedBuffer(buffer, maximumSize);
}
@ -137,7 +137,7 @@ public class BufferUtils {
* @throws IllegalArgumentException if the given buffer is null
* @since 3.2
*/
public static <E> Buffer<E> boundedBuffer(Buffer<E> buffer, int maximumSize, long timeoutMillis) {
public static <E> Buffer<E> boundedBuffer(final Buffer<E> buffer, final int maximumSize, final long timeoutMillis) {
return BoundedBuffer.boundedBuffer(buffer, maximumSize, timeoutMillis);
}
@ -149,7 +149,7 @@ public class BufferUtils {
* @return an unmodifiable buffer backed by that buffer
* @throws IllegalArgumentException if the Buffer is null
*/
public static <E> Buffer<E> unmodifiableBuffer(Buffer<E> buffer) {
public static <E> Buffer<E> unmodifiableBuffer(final Buffer<E> buffer) {
return UnmodifiableBuffer.unmodifiableBuffer(buffer);
}
@ -167,7 +167,7 @@ public class BufferUtils {
* @return a predicated buffer
* @throws IllegalArgumentException if the Buffer or Predicate is null
*/
public static <E> Buffer<E> predicatedBuffer(Buffer<E> buffer, Predicate<? super E> predicate) {
public static <E> Buffer<E> predicatedBuffer(final Buffer<E> buffer, final Predicate<? super E> predicate) {
return PredicatedBuffer.predicatedBuffer(buffer, predicate);
}
@ -187,7 +187,7 @@ public class BufferUtils {
* @return a transformed buffer backed by the given buffer
* @throws IllegalArgumentException if the Buffer or Transformer is null
*/
public static <E> Buffer<E> transformingBuffer(Buffer<E> buffer, Transformer<? super E, ? extends E> transformer) {
public static <E> Buffer<E> transformingBuffer(final Buffer<E> buffer, final Transformer<? super E, ? extends E> transformer) {
return TransformedBuffer.transformingBuffer(buffer, transformer);
}

View File

@ -93,7 +93,7 @@ public class ClosureUtils {
* @param transformer the transformer to run each time in the closure, null means nop
* @return the closure
*/
public static <E> Closure<E> asClosure(Transformer<? super E, ?> transformer) {
public static <E> Closure<E> asClosure(final Transformer<? super E, ?> transformer) {
return TransformerClosure.transformerClosure(transformer);
}
@ -108,7 +108,7 @@ public class ClosureUtils {
* @param closure the closure to call repeatedly
* @return the <code>for</code> closure
*/
public static <E> Closure<E> forClosure(int count, Closure<? super E> closure) {
public static <E> Closure<E> forClosure(final int count, final Closure<? super E> closure) {
return ForClosure.forClosure(count, closure);
}
@ -123,7 +123,7 @@ public class ClosureUtils {
* @return the <code>while</code> closure
* @throws IllegalArgumentException if either argument is null
*/
public static <E> Closure<E> whileClosure(Predicate<? super E> predicate, Closure<? super E> closure) {
public static <E> Closure<E> whileClosure(final Predicate<? super E> predicate, final Closure<? super E> closure) {
return WhileClosure.<E>whileClosure(predicate, closure, false);
}
@ -138,7 +138,7 @@ public class ClosureUtils {
* @return the <code>do-while</code> closure
* @throws IllegalArgumentException if either argument is null
*/
public static <E> Closure<E> doWhileClosure(Closure<? super E> closure, Predicate<? super E> predicate) {
public static <E> Closure<E> doWhileClosure(final Closure<? super E> closure, final Predicate<? super E> predicate) {
return WhileClosure.<E>whileClosure(predicate, closure, true);
}
@ -153,7 +153,7 @@ public class ClosureUtils {
* @return the <code>invoker</code> closure
* @throws IllegalArgumentException if the method name is null
*/
public static <E> Closure<E> invokerClosure(String methodName) {
public static <E> Closure<E> invokerClosure(final String methodName) {
// reuse transformer as it has caching - this is lazy really, should have inner class here
return asClosure(InvokerTransformer.<E, Object>invokerTransformer(methodName));
}
@ -172,7 +172,7 @@ public class ClosureUtils {
* @throws IllegalArgumentException if the method name is null
* @throws IllegalArgumentException if the paramTypes and args don't match
*/
public static <E> Closure<E> invokerClosure(String methodName, Class<?>[] paramTypes, Object[] args) {
public static <E> Closure<E> invokerClosure(final String methodName, final Class<?>[] paramTypes, final Object[] args) {
// reuse transformer as it has caching - this is lazy really, should have inner class here
return asClosure(InvokerTransformer.<E, Object>invokerTransformer(methodName, paramTypes, args));
}
@ -188,7 +188,7 @@ public class ClosureUtils {
* @return the <code>chained</code> closure
* @throws IllegalArgumentException if either closure is null
*/
public static <E> Closure<E> chainedClosure(Closure<? super E> closure1, Closure<? super E> closure2) {
public static <E> Closure<E> chainedClosure(final Closure<? super E> closure1, final Closure<? super E> closure2) {
return ChainedClosure.<E>chainedClosure(closure1, closure2);
}
@ -203,7 +203,7 @@ public class ClosureUtils {
* @throws IllegalArgumentException if the closures array is null
* @throws IllegalArgumentException if any closure in the array is null
*/
public static <E> Closure<E> chainedClosure(Closure<? super E>... closures) {
public static <E> Closure<E> chainedClosure(final Closure<? super E>... closures) {
return ChainedClosure.chainedClosure(closures);
}
@ -220,7 +220,7 @@ public class ClosureUtils {
* @throws IllegalArgumentException if the closures collection is empty
* @throws IllegalArgumentException if any closure in the collection is null
*/
public static <E> Closure<E> chainedClosure(Collection<Closure<E>> closures) {
public static <E> Closure<E> chainedClosure(final Collection<Closure<E>> closures) {
return ChainedClosure.chainedClosure(closures);
}
@ -237,7 +237,7 @@ public class ClosureUtils {
* @throws IllegalArgumentException if the closure is null
* @since 3.2
*/
public static <E> Closure<E> ifClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure) {
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure) {
return IfClosure.<E>ifClosure(predicate, trueClosure);
}
@ -254,9 +254,9 @@ public class ClosureUtils {
* @throws IllegalArgumentException if the predicate is null
* @throws IllegalArgumentException if either closure is null
*/
public static <E> Closure<E> ifClosure(Predicate<? super E> predicate,
Closure<? super E> trueClosure,
Closure<? super E> falseClosure) {
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate,
final Closure<? super E> trueClosure,
final Closure<? super E> falseClosure) {
return IfClosure.<E>ifClosure(predicate, trueClosure, falseClosure);
}
@ -277,7 +277,7 @@ public class ClosureUtils {
* @throws IllegalArgumentException if any element in the arrays is null
* @throws IllegalArgumentException if the arrays are different sizes
*/
public static <E> Closure<E> switchClosure(Predicate<? super E>[] predicates, Closure<? super E>[] closures) {
public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures) {
return SwitchClosure.<E>switchClosure(predicates, closures, null);
}
@ -300,9 +300,9 @@ public class ClosureUtils {
* @throws IllegalArgumentException if any element in the arrays is null
* @throws IllegalArgumentException if the arrays are different sizes
*/
public static <E> Closure<E> switchClosure(Predicate<? super E>[] predicates,
Closure<? super E>[] closures,
Closure<? super E> defaultClosure) {
public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates,
final Closure<? super E>[] closures,
final Closure<? super E> defaultClosure) {
return SwitchClosure.<E>switchClosure(predicates, closures, defaultClosure);
}
@ -326,7 +326,7 @@ public class ClosureUtils {
* @throws IllegalArgumentException if any closure in the map is null
* @throws ClassCastException if the map elements are of the wrong type
*/
public static <E> Closure<E> switchClosure(Map<Predicate<E>, Closure<E>> predicatesAndClosures) {
public static <E> Closure<E> switchClosure(final Map<Predicate<E>, Closure<E>> predicatesAndClosures) {
return SwitchClosure.switchClosure(predicatesAndClosures);
}
@ -348,18 +348,18 @@ public class ClosureUtils {
* @throws IllegalArgumentException if any closure in the map is null
*/
@SuppressWarnings("unchecked")
public static <E> Closure<E> switchMapClosure(Map<? extends E, Closure<E>> objectsAndClosures) {
public static <E> Closure<E> switchMapClosure(final Map<? extends E, Closure<E>> objectsAndClosures) {
Closure<? super E>[] trs = null;
Predicate<E>[] preds = null;
if (objectsAndClosures == null) {
throw new IllegalArgumentException("The object and closure map must not be null");
}
Closure<? super E> def = objectsAndClosures.remove(null);
int size = objectsAndClosures.size();
final Closure<? super E> def = objectsAndClosures.remove(null);
final int size = objectsAndClosures.size();
trs = new Closure[size];
preds = new Predicate[size];
int i = 0;
for (Map.Entry<? extends E, Closure<E>> entry : objectsAndClosures.entrySet()) {
for (final Map.Entry<? extends E, Closure<E>> entry : objectsAndClosures.entrySet()) {
preds[i] = EqualPredicate.<E>equalPredicate(entry.getKey());
trs[i] = entry.getValue();
i++;

View File

@ -50,29 +50,29 @@ public class CollectionUtils {
private static class CardinalityHelper<O> {
final Map<O, Integer> cardinalityA, cardinalityB;
public CardinalityHelper(Iterable<? extends O> a, Iterable<? extends O> b) {
public CardinalityHelper(final Iterable<? extends O> a, final Iterable<? extends O> b) {
cardinalityA = CollectionUtils.<O>getCardinalityMap(a);
cardinalityB = CollectionUtils.<O>getCardinalityMap(b);
}
public final int max(Object obj) {
public final int max(final Object obj) {
return Math.max(freqA(obj), freqB(obj));
}
public final int min(Object obj) {
public final int min(final Object obj) {
return Math.min(freqA(obj), freqB(obj));
}
public int freqA(Object obj) {
public int freqA(final Object obj) {
return getFreq(obj, cardinalityA);
}
public int freqB(Object obj) {
public int freqB(final Object obj) {
return getFreq(obj, cardinalityB);
}
private final int getFreq(final Object obj, final Map<?, Integer> freqMap) {
Integer count = freqMap.get(obj);
final Integer count = freqMap.get(obj);
if (count != null) {
return count.intValue();
}
@ -84,7 +84,7 @@ public class CollectionUtils {
private final Set<O> elements;
private final List<O> newList;
public SetOperationCardinalityHelper(Iterable<? extends O> a, Iterable<? extends O> b) {
public SetOperationCardinalityHelper(final Iterable<? extends O> a, final Iterable<? extends O> b) {
super(a, b);
elements = new HashSet<O>();
addAll(elements, a);
@ -96,7 +96,7 @@ public class CollectionUtils {
return elements.iterator();
}
public void setCardinality(O obj, int count) {
public void setCardinality(final O obj, final int count) {
for (int i = 0; i < count; i++) {
newList.add(obj);
}
@ -146,7 +146,7 @@ public class CollectionUtils {
* @return an empty collection if the argument is <code>null</code>
*/
@SuppressWarnings("unchecked")
public static <T> Collection<T> emptyIfNull(Collection<T> collection) {
public static <T> Collection<T> emptyIfNull(final Collection<T> collection) {
return collection == null ? EMPTY_COLLECTION : collection;
}
@ -166,8 +166,8 @@ public class CollectionUtils {
* @see Collection#addAll
*/
public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) {
SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b);
for (O obj : helper) {
final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b);
for (final O obj : helper) {
helper.setCardinality(obj, helper.max(obj));
}
return helper.list();
@ -190,8 +190,8 @@ public class CollectionUtils {
* @see #containsAny
*/
public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) {
SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b);
for (O obj : helper) {
final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b);
for (final O obj : helper) {
helper.setCardinality(obj, helper.min(obj));
}
return helper.list();
@ -218,8 +218,8 @@ public class CollectionUtils {
* @return the symmetric difference of the two collections
*/
public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) {
SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b);
for (O obj : helper) {
final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b);
for (final O obj : helper) {
helper.setCardinality(obj, helper.max(obj) - helper.min(obj));
}
return helper.list();
@ -239,7 +239,7 @@ public class CollectionUtils {
* @see Collection#removeAll
*/
public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) {
Predicate<O> p = TruePredicate.truePredicate();
final Predicate<O> p = TruePredicate.truePredicate();
return subtract(a, b, p);
}
@ -269,12 +269,12 @@ public class CollectionUtils {
final Predicate<O> p) {
final ArrayList<O> list = new ArrayList<O>();
final HashBag<O> bag = new HashBag<O>();
for (O element : b) {
for (final O element : b) {
if (p.evaluate(element)) {
bag.add(element);
}
}
for (O element : a) {
for (final O element : a) {
if (!bag.remove(element, 1)) {
list.add(element);
}
@ -296,13 +296,13 @@ public class CollectionUtils {
*/
public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) {
if (coll1.size() < coll2.size()) {
for (Object aColl1 : coll1) {
for (final Object aColl1 : coll1) {
if (coll2.contains(aColl1)) {
return true;
}
}
} else {
for (Object aColl2 : coll2) {
for (final Object aColl2 : coll2) {
if (coll1.contains(aColl2)) {
return true;
}
@ -328,9 +328,9 @@ public class CollectionUtils {
* @return the populated cardinality map
*/
public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) {
Map<O, Integer> count = new HashMap<O, Integer>();
for (O obj : coll) {
Integer c = count.get(obj);
final Map<O, Integer> count = new HashMap<O, Integer>();
for (final O obj : coll) {
final Integer c = count.get(obj);
if (c == null) {
count.put(obj, Integer.valueOf(1));
} else {
@ -353,8 +353,8 @@ public class CollectionUtils {
* @see Collection#containsAll
*/
public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) {
CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b);
for (Object obj : a) {
final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b);
for (final Object obj : a) {
if (helper.freqA(obj) > helper.freqB(obj)) {
return false;
}
@ -407,7 +407,7 @@ public class CollectionUtils {
if(helper.cardinalityA.size() != helper.cardinalityB.size()) {
return false;
}
for( Object obj : helper.cardinalityA.keySet()) {
for( final Object obj : helper.cardinalityA.keySet()) {
if(helper.freqA(obj) != helper.freqB(obj)) {
return false;
}
@ -423,7 +423,7 @@ public class CollectionUtils {
* @param <O> the type of object that the {@link Iterable} may contain.
* @return the the number of occurrences of obj in coll
*/
public static <O> int cardinality(O obj, final Iterable<? super O> coll) {
public static <O> int cardinality(final O obj, final Iterable<? super O> coll) {
if (coll instanceof Set<?>) {
return ((Set<? super O>) coll).contains(obj) ? 1 : 0;
}
@ -432,13 +432,13 @@ public class CollectionUtils {
}
int count = 0;
if (obj == null) {
for (Object element : coll) {
for (final Object element : coll) {
if (element == null) {
count++;
}
}
} else {
for (Object element : coll) {
for (final Object element : coll) {
if (obj.equals(element)) {
count++;
}
@ -457,9 +457,9 @@ public class CollectionUtils {
* @param predicate the predicate to use, may be null
* @return the first element of the collection which matches the predicate or null if none could be found
*/
public static <T> T find(Collection<T> collection, Predicate<? super T> predicate) {
public static <T> T find(final Collection<T> collection, final Predicate<? super T> predicate) {
if (collection != null && predicate != null) {
for (T item : collection) {
for (final T item : collection) {
if (predicate.evaluate(item)) {
return item;
}
@ -479,9 +479,9 @@ public class CollectionUtils {
* the closure to perform, may be null
* @return closure
*/
public static <T, C extends Closure<? super T>> C forAllDo(Collection<T> collection, C closure) {
public static <T, C extends Closure<? super T>> C forAllDo(final Collection<T> collection, final C closure) {
if (collection != null && closure != null) {
for (T element : collection) {
for (final T element : collection) {
closure.execute(element);
}
}
@ -500,7 +500,7 @@ public class CollectionUtils {
* @return closure
* @since 4.0
*/
public static <T, C extends Closure<? super T>> C forAllDo(Iterator<T> iterator, C closure) {
public static <T, C extends Closure<? super T>> C forAllDo(final Iterator<T> iterator, final C closure) {
if (iterator != null && closure != null) {
while (iterator.hasNext()) {
closure.execute(iterator.next());
@ -521,10 +521,10 @@ public class CollectionUtils {
* the predicate to use as a filter, may be null
* @return true if the collection is modified by this call, false otherwise.
*/
public static <T> boolean filter(Iterable<T> collection, Predicate<? super T> predicate) {
public static <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) {
boolean result = false;
if (collection != null && predicate != null) {
for (Iterator<T> it = collection.iterator(); it.hasNext();) {
for (final Iterator<T> it = collection.iterator(); it.hasNext();) {
if (!predicate.evaluate(it.next())) {
it.remove();
result = true;
@ -552,16 +552,16 @@ public class CollectionUtils {
* @param transformer
* the transformer to perform, may be null
*/
public static <C> void transform(Collection<C> collection,
Transformer<? super C, ? extends C> transformer) {
public static <C> void transform(final Collection<C> collection,
final Transformer<? super C, ? extends C> transformer) {
if (collection != null && transformer != null) {
if (collection instanceof List<?>) {
List<C> list = (List<C>) collection;
for (ListIterator<C> it = list.listIterator(); it.hasNext();) {
final List<C> list = (List<C>) collection;
for (final ListIterator<C> it = list.listIterator(); it.hasNext();) {
it.set(transformer.transform(it.next()));
}
} else {
Collection<C> resultCollection = collect(collection, transformer);
final Collection<C> resultCollection = collect(collection, transformer);
collection.clear();
collection.addAll(resultCollection);
}
@ -580,10 +580,10 @@ public class CollectionUtils {
* the predicate to use, may be null
* @return the number of matches for the predicate in the collection
*/
public static <C> int countMatches(Iterable<C> input, Predicate<? super C> predicate) {
public static <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) {
int count = 0;
if (input != null && predicate != null) {
for (C o : input) {
for (final C o : input) {
if (predicate.evaluate(o)) {
count++;
}
@ -605,9 +605,9 @@ public class CollectionUtils {
* @return true if at least one element of the collection matches the
* predicate
*/
public static <C> boolean exists(Iterable<C> input, Predicate<? super C> predicate) {
public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) {
if (input != null && predicate != null) {
for (C o : input) {
for (final C o : input) {
if (predicate.evaluate(o)) {
return true;
}
@ -630,8 +630,8 @@ public class CollectionUtils {
* @throws NullPointerException
* if the input collection is null
*/
public static <O> Collection<O> select(Collection<? extends O> inputCollection,
Predicate<? super O> predicate) {
public static <O> Collection<O> select(final Collection<? extends O> inputCollection,
final Predicate<? super O> predicate) {
return select(inputCollection, predicate, new ArrayList<O>(inputCollection.size()));
}
@ -651,10 +651,10 @@ public class CollectionUtils {
* and predicate or not null
* @return the outputCollection
*/
public static <O, R extends Collection<? super O>> R select(Collection<? extends O> inputCollection,
Predicate<? super O> predicate, R outputCollection) {
public static <O, R extends Collection<? super O>> R select(final Collection<? extends O> inputCollection,
final Predicate<? super O> predicate, final R outputCollection) {
if (inputCollection != null && predicate != null) {
for (O item : inputCollection) {
for (final O item : inputCollection) {
if (predicate.evaluate(item)) {
outputCollection.add(item);
}
@ -678,8 +678,8 @@ public class CollectionUtils {
* @throws NullPointerException
* if the input collection is null
*/
public static <O> Collection<O> selectRejected(Collection<? extends O> inputCollection,
Predicate<? super O> predicate) {
public static <O> Collection<O> selectRejected(final Collection<? extends O> inputCollection,
final Predicate<? super O> predicate) {
return selectRejected(inputCollection, predicate, new ArrayList<O>(inputCollection.size()));
}
@ -700,9 +700,9 @@ public class CollectionUtils {
* @return outputCollection
*/
public static <O, R extends Collection<? super O>> R selectRejected(
Collection<? extends O> inputCollection, Predicate<? super O> predicate, R outputCollection) {
final Collection<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection) {
if (inputCollection != null && predicate != null) {
for (O item : inputCollection) {
for (final O item : inputCollection) {
if (!predicate.evaluate(item)) {
outputCollection.add(item);
}
@ -727,9 +727,9 @@ public class CollectionUtils {
* @throws NullPointerException
* if the input collection is null
*/
public static <I, O> Collection<O> collect(Iterable<I> inputCollection,
Transformer<? super I, ? extends O> transformer) {
ArrayList<O> answer = new ArrayList<O>();
public static <I, O> Collection<O> collect(final Iterable<I> inputCollection,
final Transformer<? super I, ? extends O> transformer) {
final ArrayList<O> answer = new ArrayList<O>();
collect(inputCollection, transformer, answer);
return answer;
}
@ -749,9 +749,9 @@ public class CollectionUtils {
* @param <O> the type of object in the output collection
* @return the transformed result (new list)
*/
public static <I, O> Collection<O> collect(Iterator<I> inputIterator,
Transformer<? super I, ? extends O> transformer) {
ArrayList<O> answer = new ArrayList<O>();
public static <I, O> Collection<O> collect(final Iterator<I> inputIterator,
final Transformer<? super I, ? extends O> transformer) {
final ArrayList<O> answer = new ArrayList<O>();
collect(inputIterator, transformer, answer);
return answer;
}
@ -774,7 +774,7 @@ public class CollectionUtils {
* @throws NullPointerException if the output collection is null and both, inputCollection and
* transformer are not null
*/
public static <I, O, R extends Collection<? super O>> R collect(Iterable<? extends I> inputCollection,
public static <I, O, R extends Collection<? super O>> R collect(final Iterable<? extends I> inputCollection,
final Transformer<? super I, ? extends O> transformer, final R outputCollection) {
if (inputCollection != null) {
return collect(inputCollection.iterator(), transformer, outputCollection);
@ -801,12 +801,12 @@ public class CollectionUtils {
* transformer are not null
*/
//TODO - deprecate and replace with IteratorIterable
public static <I, O, R extends Collection<? super O>> R collect(Iterator<? extends I> inputIterator,
public static <I, O, R extends Collection<? super O>> R collect(final Iterator<? extends I> inputIterator,
final Transformer<? super I, ? extends O> transformer, final R outputCollection) {
if (inputIterator != null && transformer != null) {
while (inputIterator.hasNext()) {
I item = inputIterator.next();
O value = transformer.transform(item);
final I item = inputIterator.next();
final O value = transformer.transform(item);
outputCollection.add(value);
}
}
@ -823,7 +823,7 @@ public class CollectionUtils {
* @throws NullPointerException if the collection is null
* @since 3.2
*/
public static <T> boolean addIgnoreNull(Collection<T> collection, T object) {
public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) {
if (collection == null) {
throw new NullPointerException("The collection must not be null");
}
@ -843,7 +843,7 @@ public class CollectionUtils {
* @throws NullPointerException
* if the collection or iterator is null
*/
public static <C> boolean addAll(Collection<C> collection, Iterable<? extends C> iterable) {
public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) {
if (iterable instanceof Collection<?>) {
return collection.addAll((Collection<? extends C>) iterable);
}
@ -861,7 +861,7 @@ public class CollectionUtils {
* @throws NullPointerException
* if the collection or iterator is null
*/
public static <C> boolean addAll(Collection<C> collection, Iterator<? extends C> iterator) {
public static <C> boolean addAll(final Collection<C> collection, final Iterator<? extends C> iterator) {
boolean changed = false;
while (iterator.hasNext()) {
changed |= collection.add(iterator.next());
@ -876,7 +876,7 @@ public class CollectionUtils {
* @param enumeration the enumeration of elements to add, must not be null
* @throws NullPointerException if the collection or enumeration is null
*/
public static <C> boolean addAll(Collection<C> collection, Enumeration<? extends C> enumeration) {
public static <C> boolean addAll(final Collection<C> collection, final Enumeration<? extends C> enumeration) {
boolean changed = false;
while (enumeration.hasMoreElements()) {
changed |= collection.add(enumeration.nextElement());
@ -894,9 +894,9 @@ public class CollectionUtils {
* @throws NullPointerException
* if the collection or array is null
*/
public static <C> boolean addAll(Collection<C> collection, C[] elements) {
public static <C> boolean addAll(final Collection<C> collection, final C[] elements) {
boolean changed = false;
for (C element : elements) {
for (final C element : elements) {
changed |= collection.add(element);
}
return changed;
@ -916,7 +916,7 @@ public class CollectionUtils {
* @throws IndexOutOfBoundsException if the index is invalid
* @throws IllegalArgumentException if the object type is invalid
*/
public static <T> T get(Iterator<T> iterator, int index) {
public static <T> T get(final Iterator<T> iterator, final int index) {
int i = index;
checkIndexBounds(i);
while (iterator.hasNext()) {
@ -934,7 +934,7 @@ public class CollectionUtils {
* @param index the index to check.
* @throws IndexOutOfBoundsException if the index is negative.
*/
private static void checkIndexBounds(int index) {
private static void checkIndexBounds(final int index) {
if (index < 0) {
throw new IndexOutOfBoundsException("Index cannot be negative: " + index);
}
@ -952,7 +952,7 @@ public class CollectionUtils {
* @return the object at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
*/
public static <T> T get(Iterable<T> iterable, int index) {
public static <T> T get(final Iterable<T> iterable, final int index) {
checkIndexBounds(index);
if (iterable instanceof List<?>) {
return ((List<T>) iterable).get(index);
@ -990,19 +990,19 @@ public class CollectionUtils {
* @throws IndexOutOfBoundsException if the index is invalid
* @throws IllegalArgumentException if the object type is invalid
*/
public static Object get(Object object, int index) {
public static Object get(final Object object, final int index) {
int i = index;
if (i < 0) {
throw new IndexOutOfBoundsException("Index cannot be negative: " + i);
}
if (object instanceof Map<?,?>) {
Map<?, ?> map = (Map<?, ?>) object;
Iterator<?> iterator = map.entrySet().iterator();
final Map<?, ?> map = (Map<?, ?>) object;
final Iterator<?> iterator = map.entrySet().iterator();
return get(iterator, i);
} else if (object instanceof Object[]) {
return ((Object[]) object)[i];
} else if (object instanceof Iterator<?>) {
Iterator<?> it = (Iterator<?>) object;
final Iterator<?> it = (Iterator<?>) object;
while (it.hasNext()) {
i--;
if (i == -1) {
@ -1012,10 +1012,10 @@ public class CollectionUtils {
}
throw new IndexOutOfBoundsException("Entry does not exist: " + i);
} else if (object instanceof Collection<?>) {
Iterator<?> iterator = ((Collection<?>) object).iterator();
final Iterator<?> iterator = ((Collection<?>) object).iterator();
return get(iterator, i);
} else if (object instanceof Enumeration<?>) {
Enumeration<?> it = (Enumeration<?>) object;
final Enumeration<?> it = (Enumeration<?>) object;
while (it.hasMoreElements()) {
i--;
if (i == -1) {
@ -1030,7 +1030,7 @@ public class CollectionUtils {
} else {
try {
return Array.get(object, i);
} catch (IllegalArgumentException ex) {
} catch (final IllegalArgumentException ex) {
throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
}
}
@ -1045,7 +1045,7 @@ public class CollectionUtils {
* @return the object at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
*/
public static <K,V> Map.Entry<K, V> get(Map<K,V> map, int index) {
public static <K,V> Map.Entry<K, V> get(final Map<K,V> map, final int index) {
checkIndexBounds(index);
return get(map.entrySet(), index);
}
@ -1067,7 +1067,7 @@ public class CollectionUtils {
* @throws IllegalArgumentException thrown if object is not recognised
* @since 3.1
*/
public static int size(Object object) {
public static int size(final Object object) {
if (object == null) {
return 0;
}
@ -1079,13 +1079,13 @@ public class CollectionUtils {
} else if (object instanceof Object[]) {
total = ((Object[]) object).length;
} else if (object instanceof Iterator<?>) {
Iterator<?> it = (Iterator<?>) object;
final Iterator<?> it = (Iterator<?>) object;
while (it.hasNext()) {
total++;
it.next();
}
} else if (object instanceof Enumeration<?>) {
Enumeration<?> it = (Enumeration<?>) object;
final Enumeration<?> it = (Enumeration<?>) object;
while (it.hasMoreElements()) {
total++;
it.nextElement();
@ -1093,7 +1093,7 @@ public class CollectionUtils {
} else {
try {
total = Array.getLength(object);
} catch (IllegalArgumentException ex) {
} catch (final IllegalArgumentException ex) {
throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
}
}
@ -1120,7 +1120,7 @@ public class CollectionUtils {
* @throws IllegalArgumentException thrown if object is not recognised
* @since 3.2
*/
public static boolean sizeIsEmpty(Object object) {
public static boolean sizeIsEmpty(final Object object) {
if (object == null) {
return true;
} else if (object instanceof Collection<?>) {
@ -1136,7 +1136,7 @@ public class CollectionUtils {
} else {
try {
return Array.getLength(object) == 0;
} catch (IllegalArgumentException ex) {
} catch (final IllegalArgumentException ex) {
throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
}
}
@ -1152,7 +1152,7 @@ public class CollectionUtils {
* @return true if empty or null
* @since 3.2
*/
public static boolean isEmpty(Collection<?> coll) {
public static boolean isEmpty(final Collection<?> coll) {
return coll == null || coll.isEmpty();
}
@ -1165,7 +1165,7 @@ public class CollectionUtils {
* @return true if non-null and non-empty
* @since 3.2
*/
public static boolean isNotEmpty(Collection<?> coll) {
public static boolean isNotEmpty(final Collection<?> coll) {
return !isEmpty(coll);
}
@ -1175,7 +1175,7 @@ public class CollectionUtils {
*
* @param array the array to reverse
*/
public static void reverseArray(Object[] array) {
public static void reverseArray(final Object[] array) {
int i = 0;
int j = array.length - 1;
Object tmp;
@ -1205,7 +1205,7 @@ public class CollectionUtils {
* @throws NullPointerException if the collection is null
*/
@SuppressWarnings("unchecked")
public static boolean isFull(Collection<?> coll) {
public static boolean isFull(final Collection<?> coll) {
if (coll == null) {
throw new NullPointerException("The collection must not be null");
}
@ -1213,9 +1213,9 @@ public class CollectionUtils {
return ((BoundedCollection<?>) coll).isFull();
}
try {
BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection((Collection<Object>) coll);
final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection((Collection<Object>) coll);
return bcoll.isFull();
} catch (IllegalArgumentException ex) {
} catch (final IllegalArgumentException ex) {
return false;
}
}
@ -1236,7 +1236,7 @@ public class CollectionUtils {
* @throws NullPointerException if the collection is null
*/
@SuppressWarnings("unchecked")
public static int maxSize(Collection<?> coll) {
public static int maxSize(final Collection<?> coll) {
if (coll == null) {
throw new NullPointerException("The collection must not be null");
}
@ -1244,9 +1244,9 @@ public class CollectionUtils {
return ((BoundedCollection<?>) coll).maxSize();
}
try {
BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection((Collection<Object>) coll);
final BoundedCollection<?> bcoll = UnmodifiableBoundedCollection.unmodifiableBoundedCollection((Collection<Object>) coll);
return bcoll.maxSize();
} catch (IllegalArgumentException ex) {
} catch (final IllegalArgumentException ex) {
return -1;
}
}
@ -1267,7 +1267,7 @@ public class CollectionUtils {
* @throws NullPointerException if either parameter is null
* @since 3.2
*/
public static <C> Collection<C> retainAll(Collection<C> collection, Collection<?> retain) {
public static <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) {
return ListUtils.retainAll(collection, retain);
}
@ -1287,7 +1287,7 @@ public class CollectionUtils {
* @throws NullPointerException if either parameter is null
* @since 3.3 (method existed in 3.2 but was completely broken)
*/
public static <E> Collection<E> removeAll(Collection<E> collection, Collection<?> remove) {
public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) {
return ListUtils.removeAll(collection, remove);
}
@ -1314,7 +1314,7 @@ public class CollectionUtils {
* @return a synchronized collection backed by the given collection
* @throws IllegalArgumentException if the collection is null
*/
public static <C> Collection<C> synchronizedCollection(Collection<C> collection) {
public static <C> Collection<C> synchronizedCollection(final Collection<C> collection) {
return SynchronizedCollection.synchronizedCollection(collection);
}
@ -1327,7 +1327,7 @@ public class CollectionUtils {
* @return an unmodifiable collection backed by the given collection
* @throws IllegalArgumentException if the collection is null
*/
public static <C> Collection<C> unmodifiableCollection(Collection<C> collection) {
public static <C> Collection<C> unmodifiableCollection(final Collection<C> collection) {
return UnmodifiableCollection.unmodifiableCollection(collection);
}
@ -1345,7 +1345,7 @@ public class CollectionUtils {
* @return a predicated collection backed by the given collection
* @throws IllegalArgumentException if the Collection is null
*/
public static <C> Collection<C> predicatedCollection(Collection<C> collection, Predicate<? super C> predicate) {
public static <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) {
return PredicatedCollection.predicatedCollection(collection, predicate);
}
@ -1364,7 +1364,7 @@ public class CollectionUtils {
* @return a transformed collection backed by the given collection
* @throws IllegalArgumentException if the Collection or Transformer is null
*/
public static <E> Collection<E> transformingCollection(Collection<E> collection, Transformer<? super E, ? extends E> transformer) {
public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) {
return TransformedCollection.transformingCollection(collection, transformer);
}
@ -1375,7 +1375,7 @@ public class CollectionUtils {
* @return sole member of collection
* @throws IllegalArgumentException if collection is null/empty or contains more than one element
*/
public static <E> E extractSingleton(Collection<E> collection) {
public static <E> E extractSingleton(final Collection<E> collection) {
if (collection == null || collection.size() != 1) {
throw new IllegalArgumentException("Can extract singleton only when collection size == 1");
}

View File

@ -76,8 +76,8 @@ public class ComparatorUtils {
* @see ComparatorChain
*/
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(Comparator<E> comparator1,
Comparator<E> comparator2) {
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(final Comparator<E> comparator1,
final Comparator<E> comparator2) {
return chainedComparator(new Comparator[] {comparator1, comparator2});
}
@ -90,9 +90,9 @@ public class ComparatorUtils {
* @throws NullPointerException if comparators array is null or contains a null
* @see ComparatorChain
*/
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(Comparator<E>[] comparators) {
ComparatorChain<E> chain = new ComparatorChain<E>();
for (Comparator<E> comparator : comparators) {
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(final Comparator<E>[] comparators) {
final ComparatorChain<E> chain = new ComparatorChain<E>();
for (final Comparator<E> comparator : comparators) {
if (comparator == null) {
throw new NullPointerException("Comparator cannot be null");
}
@ -113,7 +113,7 @@ public class ComparatorUtils {
* @see ComparatorChain
*/
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(Collection<Comparator<E>> comparators) {
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators) {
return chainedComparator(
(Comparator<E>[]) comparators.toArray(new Comparator[comparators.size()])
);
@ -126,7 +126,7 @@ public class ComparatorUtils {
* @return a comparator that reverses the order of the input comparator
* @see ReverseComparator
*/
public static <E> Comparator<E> reversedComparator(Comparator<E> comparator) {
public static <E> Comparator<E> reversedComparator(final Comparator<E> comparator) {
return new ReverseComparator<E>(comparator);
}
@ -142,7 +142,7 @@ public class ComparatorUtils {
* <code>false</code> {@link Boolean}s.
* @return a comparator that sorts booleans
*/
public static Comparator<Boolean> booleanComparator(boolean trueFirst) {
public static Comparator<Boolean> booleanComparator(final boolean trueFirst) {
return BooleanComparator.booleanComparator(trueFirst);
}
@ -197,7 +197,7 @@ public class ComparatorUtils {
* @see TransformingComparator
*/
@SuppressWarnings("unchecked")
public static <E> Comparator<E> transformedComparator(Comparator<E> comparator, Transformer<? super E, ? extends E> transformer) {
public static <E> Comparator<E> transformedComparator(Comparator<E> comparator, final Transformer<? super E, ? extends E> transformer) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
@ -215,11 +215,11 @@ public class ComparatorUtils {
* @return the smaller of the two objects
*/
@SuppressWarnings("unchecked")
public static <E> E min(E o1, E o2, Comparator<E> comparator) {
public static <E> E min(final E o1, final E o2, Comparator<E> comparator) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
int c = comparator.compare(o1, o2);
final int c = comparator.compare(o1, o2);
return c < 0 ? o1 : o2;
}
@ -234,11 +234,11 @@ public class ComparatorUtils {
* @return the larger of the two objects
*/
@SuppressWarnings("unchecked")
public static <E> E max(E o1, E o2, Comparator<E> comparator) {
public static <E> E max(final E o1, final E o2, Comparator<E> comparator) {
if (comparator == null) {
comparator = NATURAL_COMPARATOR;
}
int c = comparator.compare(o1, o2);
final int c = comparator.compare(o1, o2);
return c > 0 ? o1 : o2;
}

View File

@ -49,7 +49,7 @@ public class EnumerationUtils {
* @return a list containing all elements of the given enumeration
* @throws NullPointerException if the enumeration parameter is <code>null</code>.
*/
public static <E> List<E> toList(Enumeration<E> enumeration) {
public static <E> List<E> toList(final Enumeration<E> enumeration) {
return IteratorUtils.toList(new EnumerationIterator<E>(enumeration));
}
@ -60,8 +60,8 @@ public class EnumerationUtils {
* @param stringTokenizer the tokenizer to convert to a {@link List(String)}
* @return List<String>
*/
public static List<String> toList(StringTokenizer stringTokenizer) {
List<String> result = new ArrayList<String>(stringTokenizer.countTokens());
public static List<String> toList(final StringTokenizer stringTokenizer) {
final List<String> result = new ArrayList<String>(stringTokenizer.countTokens());
while (stringTokenizer.hasMoreTokens()) {
result.add(stringTokenizer.nextToken());
}

View File

@ -188,7 +188,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param base string to interpolate
* @return returns the key name with the ${key} substituted
*/
protected String interpolate(String base) {
protected String interpolate(final String base) {
// COPIED from [configuration] 2003-12-29
return interpolateHelper(base, null);
}
@ -207,7 +207,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*
* @return the string with the interpolation taken care of
*/
protected String interpolateHelper(String base, List<String> priorVariables) {
protected String interpolateHelper(final String base, List<String> priorVariables) {
// COPIED from [configuration] 2003-12-29
if (base == null) {
return null;
@ -224,7 +224,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
int end = -1;
int prec = 0 - END_TOKEN.length();
String variable = null;
StringBuilder result = new StringBuilder();
final StringBuilder result = new StringBuilder();
// FIXME: we should probably allow the escaping of the start token
while ((begin = base.indexOf(START_TOKEN, prec + END_TOKEN.length())) > -1
@ -234,13 +234,13 @@ public class ExtendedProperties extends Hashtable<String, Object> {
// if we've got a loop, create a useful exception message and throw
if (priorVariables.contains(variable)) {
String initialBase = priorVariables.remove(0).toString();
final String initialBase = priorVariables.remove(0).toString();
priorVariables.add(variable);
StringBuilder priorVariableSb = new StringBuilder();
final StringBuilder priorVariableSb = new StringBuilder();
// create a nice trace of interpolated variables like so:
// var1->var2->var3
for (Iterator<?> it = priorVariables.iterator(); it.hasNext();) {
for (final Iterator<?> it = priorVariables.iterator(); it.hasNext();) {
priorVariableSb.append(it.next());
if (it.hasNext()) {
priorVariableSb.append("->");
@ -256,7 +256,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
}
//QUESTION: getProperty or getPropertyDirect
Object value = getProperty(variable);
final Object value = getProperty(variable);
if (value != null) {
result.append(interpolateHelper(value.toString(), priorVariables));
@ -281,10 +281,10 @@ public class ExtendedProperties extends Hashtable<String, Object> {
/**
* Inserts a backslash before every comma and backslash.
*/
private static String escape(String s) {
StringBuilder buf = new StringBuilder(s);
private static String escape(final String s) {
final StringBuilder buf = new StringBuilder(s);
for (int i = 0; i < buf.length(); i++) {
char c = buf.charAt(i);
final char c = buf.charAt(i);
if (c == ',' || c == '\\') {
buf.insert(i, '\\');
i++;
@ -296,11 +296,11 @@ public class ExtendedProperties extends Hashtable<String, Object> {
/**
* Removes a backslash from every pair of backslashes.
*/
private static String unescape(String s) {
StringBuilder buf = new StringBuilder(s);
private static String unescape(final String s) {
final StringBuilder buf = new StringBuilder(s);
for (int i = 0; i < buf.length() - 1; i++) {
char c1 = buf.charAt(i);
char c2 = buf.charAt(i + 1);
final char c1 = buf.charAt(i);
final char c2 = buf.charAt(i + 1);
if (c1 == '\\' && c2 == '\\') {
buf.deleteCharAt(i);
}
@ -312,7 +312,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* Counts the number of successive times 'ch' appears in the
* 'line' before the position indicated by the 'index'.
*/
private static int countPreceding(String line, int index, char ch) {
private static int countPreceding(final String line, final int index, final char ch) {
int i;
for (i = index - 1; i >= 0; i--) {
if (line.charAt(i) != ch) {
@ -325,7 +325,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
/**
* Checks if the line ends with odd number of backslashes
*/
private static boolean endsWithSlash(String line) {
private static boolean endsWithSlash(final String line) {
if (!line.endsWith("\\")) {
return false;
}
@ -344,7 +344,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*
* @param reader A Reader.
*/
public PropertiesReader(Reader reader) {
public PropertiesReader(final Reader reader) {
super(reader);
}
@ -355,7 +355,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws IOException if there is difficulty reading the source.
*/
public String readProperty() throws IOException {
StringBuilder buffer = new StringBuilder();
final StringBuilder buffer = new StringBuilder();
String line = readLine();
while (line != null) {
line = line.trim();
@ -390,7 +390,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*
* @param string A String.
*/
public PropertiesTokenizer(String string) {
public PropertiesTokenizer(final String string) {
super(string, DELIMITER);
}
@ -411,10 +411,10 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*/
@Override
public String nextToken() {
StringBuilder buffer = new StringBuilder();
final StringBuilder buffer = new StringBuilder();
while (hasMoreTokens()) {
String token = super.nextToken();
final String token = super.nextToken();
if (endsWithSlash(token)) {
buffer.append(token.substring(0, token.length() - 1));
buffer.append(DELIMITER);
@ -441,7 +441,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param file the filename to load
* @throws IOException if a file error occurs
*/
public ExtendedProperties(String file) throws IOException {
public ExtendedProperties(final String file) throws IOException {
this(file, null);
}
@ -452,7 +452,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param defaultFile a second filename to load default values from
* @throws IOException if a file error occurs
*/
public ExtendedProperties(String file, String defaultFile) throws IOException {
public ExtendedProperties(final String file, final String defaultFile) throws IOException {
this.file = file;
basePath = new File(file).getAbsolutePath();
@ -467,7 +467,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
if (in != null) {
in.close();
}
} catch (IOException ex) {}
} catch (final IOException ex) {}
}
if (defaultFile != null) {
@ -499,7 +499,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*
* @param inc the property name which includes another property, empty converted to null
*/
public void setInclude(String inc) {
public void setInclude(final String inc) {
includePropertyName = inc;
}
@ -509,7 +509,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param input the InputStream to load from
* @throws IOException if an IO error occurs
*/
public void load(InputStream input) throws IOException {
public void load(final InputStream input) throws IOException {
load(input, null);
}
@ -521,13 +521,13 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param enc the encoding to use
* @throws IOException if an IO error occurs
*/
public synchronized void load(InputStream input, String enc) throws IOException {
public synchronized void load(final InputStream input, final String enc) throws IOException {
PropertiesReader reader = null;
if (enc != null) {
try {
reader = new PropertiesReader(new InputStreamReader(input, enc));
} catch (UnsupportedEncodingException ex) {
} catch (final UnsupportedEncodingException ex) {
// Another try coming up....
}
}
@ -536,7 +536,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
try {
reader = new PropertiesReader(new InputStreamReader(input, "8859_1"));
} catch (UnsupportedEncodingException ex) {
} catch (final UnsupportedEncodingException ex) {
// ISO8859-1 support is required on java platforms but....
// If it's not supported, use the system default encoding
reader = new PropertiesReader(new InputStreamReader(input));
@ -544,16 +544,16 @@ public class ExtendedProperties extends Hashtable<String, Object> {
}
try {
String includeProperty = getInclude();
final String includeProperty = getInclude();
while (true) {
String line = reader.readProperty();
final String line = reader.readProperty();
if (line == null) {
return; // EOF
}
int equalSign = line.indexOf('=');
final int equalSign = line.indexOf('=');
if (equalSign > 0) {
String key = line.substring(0, equalSign).trim();
final String key = line.substring(0, equalSign).trim();
String value = line.substring(equalSign + 1).trim();
/* COLLECTIONS-238 allows empty properties to exist by commenting this out
@ -603,7 +603,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @return value as object. Will return user value if exists,
* if not then default value if exists, otherwise null
*/
public Object getProperty(String key) {
public Object getProperty(final String key) {
// first, try to get from the 'user value' store
Object obj = super.get(key);
@ -637,14 +637,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param key the key to add
* @param value the value to add
*/
public void addProperty(String key, Object value) {
public void addProperty(final String key, final Object value) {
if (value instanceof String) {
String str = (String) value;
final String str = (String) value;
if (str.indexOf(PropertiesTokenizer.DELIMITER) > 0) {
// token contains commas, so must be split apart then added
PropertiesTokenizer tokenizer = new PropertiesTokenizer(str);
final PropertiesTokenizer tokenizer = new PropertiesTokenizer(str);
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
final String token = tokenizer.nextToken();
addPropertyInternal(key, unescape(token));
}
} else {
@ -666,7 +666,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param key the key to store at
* @param value the decoded object to store
*/
private void addPropertyDirect(String key, Object value) {
private void addPropertyDirect(final String key, final Object value) {
// safety check
if (!containsKey(key)) {
keysAsListed.add(key);
@ -685,12 +685,12 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param key the key to store at
* @param value the decoded object to store
*/
private void addPropertyInternal(String key, Object value) {
Object current = this.get(key);
private void addPropertyInternal(final String key, final Object value) {
final Object current = this.get(key);
if (current instanceof String) {
// one object already in map - convert it to a vector
List<Object> values = new Vector<Object>(2);
final List<Object> values = new Vector<Object>(2);
values.add(current);
values.add(value);
super.put(key, values);
@ -698,6 +698,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
} else if (current instanceof List) {
// already a list - just add the new token
@SuppressWarnings("unchecked") // OK to cast to Object
final
List<Object> list = (List<Object>) current;
list.add(value);
@ -718,7 +719,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param key the key to set
* @param value the value to set
*/
public void setProperty(String key, Object value) {
public void setProperty(final String key, final Object value) {
clearProperty(key);
addProperty(key, value);
}
@ -732,22 +733,22 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param header a textual comment to act as a file header
* @throws IOException if an IO error occurs
*/
public synchronized void save(OutputStream output, String header) throws IOException {
public synchronized void save(final OutputStream output, final String header) throws IOException {
if (output == null) {
return;
}
PrintWriter theWrtr = new PrintWriter(output);
final PrintWriter theWrtr = new PrintWriter(output);
if (header != null) {
theWrtr.println(header);
}
Enumeration<String> theKeys = keys();
final Enumeration<String> theKeys = keys();
while (theKeys.hasMoreElements()) {
String key = theKeys.nextElement();
Object value = get(key);
final String key = theKeys.nextElement();
final Object value = get(key);
if (value != null) {
if (value instanceof String) {
StringBuilder currentOutput = new StringBuilder();
final StringBuilder currentOutput = new StringBuilder();
currentOutput.append(key);
currentOutput.append("=");
currentOutput.append(escape((String) value));
@ -755,9 +756,10 @@ public class ExtendedProperties extends Hashtable<String, Object> {
} else if (value instanceof List) {
@SuppressWarnings("unchecked") // we only add Strings to the Lists
final
List<String> values = (List<String>) value;
for (String currentElement : values) {
StringBuilder currentOutput = new StringBuilder();
for (final String currentElement : values) {
final StringBuilder currentOutput = new StringBuilder();
currentOutput.append(key);
currentOutput.append("=");
currentOutput.append(escape(currentElement));
@ -777,9 +779,9 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*
* @param props the properties to combine
*/
public void combine(ExtendedProperties props) {
for (Iterator<String> it = props.getKeys(); it.hasNext();) {
String key = it.next();
public void combine(final ExtendedProperties props) {
for (final Iterator<String> it = props.getKeys(); it.hasNext();) {
final String key = it.next();
clearProperty(key);
addPropertyDirect(key, props.get(key));
}
@ -790,7 +792,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
*
* @param key the property key to remove along with corresponding value
*/
public void clearProperty(String key) {
public void clearProperty(final String key) {
if (containsKey(key)) {
// we also need to rebuild the keysAsListed or else
// things get *very* confusing
@ -821,12 +823,12 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param prefix the prefix to match
* @return an Iterator of keys that match the prefix
*/
public Iterator<String> getKeys(String prefix) {
Iterator<String> keys = getKeys();
ArrayList<String> matchingKeys = new ArrayList<String>();
public Iterator<String> getKeys(final String prefix) {
final Iterator<String> keys = getKeys();
final ArrayList<String> matchingKeys = new ArrayList<String>();
while (keys.hasNext()) {
String key = keys.next();
final String key = keys.next();
if (key.startsWith(prefix)) {
matchingKeys.add(key);
}
@ -843,13 +845,13 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @return a new independent ExtendedProperties
* or {@code null} if no keys matched
*/
public ExtendedProperties subset(String prefix) {
ExtendedProperties c = new ExtendedProperties();
Iterator<String> keys = getKeys();
public ExtendedProperties subset(final String prefix) {
final ExtendedProperties c = new ExtendedProperties();
final Iterator<String> keys = getKeys();
boolean validSubset = false;
while (keys.hasNext()) {
String key = keys.next();
final String key = keys.next();
if (key.startsWith(prefix)) {
if (!validSubset) {
@ -889,11 +891,11 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* Display the configuration for debugging purposes to System.out.
*/
public void display() {
Iterator<String> i = getKeys();
final Iterator<String> i = getKeys();
while (i.hasNext()) {
String key = i.next();
Object value = get(key);
final String key = i.next();
final Object value = get(key);
System.out.println(key + " => " + value);
}
}
@ -906,7 +908,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a String.
*/
public String getString(String key) {
public String getString(final String key) {
return getString(key, null);
}
@ -920,8 +922,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a String.
*/
public String getString(String key, String defaultValue) {
Object value = get(key);
public String getString(final String key, final String defaultValue) {
final Object value = get(key);
if (value instanceof String) {
return interpolate((String) value);
@ -934,6 +936,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
}
} else if (value instanceof List) {
@SuppressWarnings("unchecked") // Only expecting Strings here
final
List<String> entry = (List<String>) value;
return interpolate(entry.get(0)); // requires a String
} else {
@ -952,7 +955,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws IllegalArgumentException if one of the tokens is
* malformed (does not contain an equals sign).
*/
public Properties getProperties(String key) {
public Properties getProperties(final String key) {
return getProperties(key, new Properties());
}
@ -967,19 +970,19 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws IllegalArgumentException if one of the tokens is
* malformed (does not contain an equals sign).
*/
public Properties getProperties(String key, Properties defaults) {
public Properties getProperties(final String key, final Properties defaults) {
/*
* Grab an array of the tokens for this key.
*/
String[] tokens = getStringArray(key);
final String[] tokens = getStringArray(key);
// Each token is of the form 'key=value'.
Properties props = new Properties(defaults);
for (String token : tokens) {
int equalSign = token.indexOf('=');
final Properties props = new Properties(defaults);
for (final String token : tokens) {
final int equalSign = token.indexOf('=');
if (equalSign > 0) {
String pkey = token.substring(0, equalSign).trim();
String pvalue = token.substring(equalSign + 1).trim();
final String pkey = token.substring(0, equalSign).trim();
final String pvalue = token.substring(equalSign + 1).trim();
props.setProperty(pkey, pvalue);
} else {
throw new IllegalArgumentException('\'' + token + "' does not contain " + "an equals sign");
@ -997,8 +1000,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a String/List.
*/
public String[] getStringArray(String key) {
Object value = get(key);
public String[] getStringArray(final String key) {
final Object value = get(key);
List<String> values;
if (value instanceof String) {
@ -1007,6 +1010,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
} else if (value instanceof List) {
@SuppressWarnings("unchecked") // We only add Strings to the Lists
final
List<String> list = (List<String>) value;
values = list;
@ -1020,7 +1024,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
throw new ClassCastException('\'' + key + "' doesn't map to a String/List object");
}
String[] tokens = new String[values.size()];
final String[] tokens = new String[values.size()];
for (int i = 0; i < tokens.length; i++) {
tokens[i] = values.get(i);
}
@ -1037,7 +1041,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Vector.
*/
public Vector<String> getVector(String key) {
public Vector<String> getVector(final String key) {
return getVector(key, null);
}
@ -1053,16 +1057,17 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Vector.
*/
public Vector<String> getVector(String key, Vector<String> defaultValue) {
Object value = get(key);
public Vector<String> getVector(final String key, final Vector<String> defaultValue) {
final Object value = get(key);
if (value instanceof List) {
@SuppressWarnings("unchecked") // our lists only contain Strings
final
List<String> list = (List<String>) value;
return new Vector<String>(list);
} else if (value instanceof String) {
Vector<String> values = new Vector<String>(1);
final Vector<String> values = new Vector<String>(1);
values.add((String) value);
super.put(key, values);
return values;
@ -1090,7 +1095,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* object that is not a List.
* @since 3.2
*/
public List<String> getList(String key) {
public List<String> getList(final String key) {
return getList(key, null);
}
@ -1107,16 +1112,17 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* object that is not a List.
* @since 3.2
*/
public List<String> getList(String key, List<String> defaultValue) {
Object value = get(key);
public List<String> getList(final String key, final List<String> defaultValue) {
final Object value = get(key);
if (value instanceof List) {
@SuppressWarnings("unchecked") // our lists only contain strings
final
List<String> list = (List<String>) value;
return new ArrayList<String>(list);
} else if (value instanceof String) {
List<String> values = new ArrayList<String>(1);
final List<String> values = new ArrayList<String>(1);
values.add((String) value);
super.put(key, values);
return values;
@ -1142,8 +1148,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Boolean.
*/
public boolean getBoolean(String key) {
Boolean b = getBoolean(key, null);
public boolean getBoolean(final String key) {
final Boolean b = getBoolean(key, null);
if (b != null) {
return b.booleanValue();
} else {
@ -1160,7 +1166,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Boolean.
*/
public boolean getBoolean(String key, boolean defaultValue) {
public boolean getBoolean(final String key, final boolean defaultValue) {
return getBoolean(key, Boolean.valueOf(defaultValue)).booleanValue();
}
@ -1174,16 +1180,16 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Boolean.
*/
public Boolean getBoolean(String key, Boolean defaultValue) {
public Boolean getBoolean(final String key, final Boolean defaultValue) {
Object value = get(key);
final Object value = get(key);
if (value instanceof Boolean) {
return (Boolean) value;
} else if (value instanceof String) {
String s = testBoolean((String) value);
Boolean b = Boolean.valueOf(s);
final String s = testBoolean((String) value);
final Boolean b = Boolean.valueOf(s);
super.put(key, b);
return b;
@ -1210,8 +1216,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @return <code>true</code> or <code>false</code> if the supplied
* text maps to a boolean value, or <code>null</code> otherwise.
*/
public String testBoolean(String value) {
String s = value.toLowerCase(Locale.ENGLISH);
public String testBoolean(final String value) {
final String s = value.toLowerCase(Locale.ENGLISH);
if (s.equals("true") || s.equals("on") || s.equals("yes")) {
return "true";
@ -1234,8 +1240,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public byte getByte(String key) {
Byte b = getByte(key, null);
public byte getByte(final String key) {
final Byte b = getByte(key, null);
if (b != null) {
return b.byteValue();
} else {
@ -1254,7 +1260,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public byte getByte(String key, byte defaultValue) {
public byte getByte(final String key, final byte defaultValue) {
return getByte(key, Byte.valueOf(defaultValue)).byteValue();
}
@ -1270,14 +1276,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Byte getByte(String key, Byte defaultValue) {
Object value = get(key);
public Byte getByte(final String key, final Byte defaultValue) {
final Object value = get(key);
if (value instanceof Byte) {
return (Byte) value;
} else if (value instanceof String) {
Byte b = new Byte((String) value);
final Byte b = new Byte((String) value);
super.put(key, b);
return b;
@ -1304,8 +1310,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public short getShort(String key) {
Short s = getShort(key, null);
public short getShort(final String key) {
final Short s = getShort(key, null);
if (s != null) {
return s.shortValue();
} else {
@ -1324,7 +1330,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public short getShort(String key, short defaultValue) {
public short getShort(final String key, final short defaultValue) {
return getShort(key, Short.valueOf(defaultValue)).shortValue();
}
@ -1340,14 +1346,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Short getShort(String key, Short defaultValue) {
Object value = get(key);
public Short getShort(final String key, final Short defaultValue) {
final Object value = get(key);
if (value instanceof Short) {
return (Short) value;
} else if (value instanceof String) {
Short s = new Short((String) value);
final Short s = new Short((String) value);
super.put(key, s);
return s;
@ -1369,7 +1375,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param name The resource name.
* @return The value of the resource as an integer.
*/
public int getInt(String name) {
public int getInt(final String name) {
return getInteger(name);
}
@ -1381,7 +1387,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param def The default value of the resource.
* @return The value of the resource as an integer.
*/
public int getInt(String name, int def) {
public int getInt(final String name, final int def) {
return getInteger(name, def);
}
@ -1397,8 +1403,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public int getInteger(String key) {
Integer i = getInteger(key, null);
public int getInteger(final String key) {
final Integer i = getInteger(key, null);
if (i != null) {
return i.intValue();
} else {
@ -1417,8 +1423,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public int getInteger(String key, int defaultValue) {
Integer i = getInteger(key, null);
public int getInteger(final String key, final int defaultValue) {
final Integer i = getInteger(key, null);
if (i == null) {
return defaultValue;
@ -1438,14 +1444,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Integer getInteger(String key, Integer defaultValue) {
Object value = get(key);
public Integer getInteger(final String key, final Integer defaultValue) {
final Object value = get(key);
if (value instanceof Integer) {
return (Integer) value;
} else if (value instanceof String) {
Integer i = new Integer((String) value);
final Integer i = new Integer((String) value);
super.put(key, i);
return i;
@ -1472,8 +1478,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public long getLong(String key) {
Long l = getLong(key, null);
public long getLong(final String key) {
final Long l = getLong(key, null);
if (l != null) {
return l.longValue();
} else {
@ -1492,7 +1498,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public long getLong(String key, long defaultValue) {
public long getLong(final String key, final long defaultValue) {
return getLong(key, new Long(defaultValue)).longValue();
}
@ -1508,14 +1514,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Long getLong(String key, Long defaultValue) {
Object value = get(key);
public Long getLong(final String key, final Long defaultValue) {
final Object value = get(key);
if (value instanceof Long) {
return (Long) value;
} else if (value instanceof String) {
Long l = new Long((String) value);
final Long l = new Long((String) value);
super.put(key, l);
return l;
@ -1542,8 +1548,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public float getFloat(String key) {
Float f = getFloat(key, null);
public float getFloat(final String key) {
final Float f = getFloat(key, null);
if (f != null) {
return f.floatValue();
} else {
@ -1562,7 +1568,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public float getFloat(String key, float defaultValue) {
public float getFloat(final String key, final float defaultValue) {
return getFloat(key, new Float(defaultValue)).floatValue();
}
@ -1578,14 +1584,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Float getFloat(String key, Float defaultValue) {
Object value = get(key);
public Float getFloat(final String key, final Float defaultValue) {
final Object value = get(key);
if (value instanceof Float) {
return (Float) value;
} else if (value instanceof String) {
Float f = new Float((String) value);
final Float f = new Float((String) value);
super.put(key, f);
return f;
@ -1612,8 +1618,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public double getDouble(String key) {
Double d = getDouble(key, null);
public double getDouble(final String key) {
final Double d = getDouble(key, null);
if (d != null) {
return d.doubleValue();
} else {
@ -1632,7 +1638,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public double getDouble(String key, double defaultValue) {
public double getDouble(final String key, final double defaultValue) {
return getDouble(key, new Double(defaultValue)).doubleValue();
}
@ -1648,14 +1654,14 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Double getDouble(String key, Double defaultValue) {
Object value = get(key);
public Double getDouble(final String key, final Double defaultValue) {
final Object value = get(key);
if (value instanceof Double) {
return (Double) value;
} else if (value instanceof String) {
Double d = new Double((String) value);
final Double d = new Double((String) value);
super.put(key, d);
return d;
@ -1683,10 +1689,11 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param props the properties object to convert
* @return new ExtendedProperties created from props
*/
public static ExtendedProperties convertProperties(Properties props) {
ExtendedProperties c = new ExtendedProperties();
public static ExtendedProperties convertProperties(final Properties props) {
final ExtendedProperties c = new ExtendedProperties();
@SuppressWarnings("unchecked") // Properties are supposed to have string keys ...
final
Enumeration<String> e = (Enumeration<String>) props.propertyNames();
// Unfortunately PMD 4.3 cannot handle the original code where the @Suppress
// was in the for loop:
@ -1694,8 +1701,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
// Enumeration<String> e = (Enumeration<String>) props.propertyNames(); e.hasMoreElements();) {
// String s = e.nextElement(); // ... if props does not, this line would fail anyway ...
while (e.hasMoreElements()) {
String s = e.nextElement(); // ... if props does not, this line would fail anyway ...
String value = props.getProperty(s);
final String s = e.nextElement(); // ... if props does not, this line would fail anyway ...
final String value = props.getProperty(s);
if(value != null) {
c.setProperty(s, value);
}
@ -1713,8 +1720,8 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @return old value of the property
*/
@Override
public Object put(String key, Object value) {
Object ret = getProperty(key);
public Object put(final String key, final Object value) {
final Object ret = getProperty(key);
addProperty(key, value);
return ret;
}
@ -1727,16 +1734,17 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @param map full of key/value pair data
*/
@Override
public void putAll(Map<? extends String, ? extends Object> map) {
public void putAll(final Map<? extends String, ? extends Object> map) {
if (map instanceof ExtendedProperties) {
for (Iterator<String> it = ((ExtendedProperties) map).getKeys(); it.hasNext(); ) {
String key = it.next();
for (final Iterator<String> it = ((ExtendedProperties) map).getKeys(); it.hasNext(); ) {
final String key = it.next();
put(key, map.get(key));
}
} else {
@SuppressWarnings("unchecked") // OK to downcast here
final
Map<String, Object> mapso = (Map<String,Object>) map;
for (java.util.Map.Entry<String, Object> entry : mapso.entrySet()) {
for (final java.util.Map.Entry<String, Object> entry : mapso.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
@ -1751,9 +1759,9 @@ public class ExtendedProperties extends Hashtable<String, Object> {
* @return old value of the property
*/
@Override
public Object remove(Object key) {
String strKey = String.valueOf(key);
Object ret = getProperty(strKey);
public Object remove(final Object key) {
final String strKey = String.valueOf(key);
final Object ret = getProperty(strKey);
clearProperty(strKey);
return ret;
}

View File

@ -82,7 +82,7 @@ public class FactoryUtils {
* @param constantToReturn the constant object to return each time in the factory
* @return the <code>constant</code> factory.
*/
public static <T> Factory<T> constantFactory(T constantToReturn) {
public static <T> Factory<T> constantFactory(final T constantToReturn) {
return ConstantFactory.constantFactory(constantToReturn);
}
@ -104,7 +104,7 @@ public class FactoryUtils {
* the {@code prototype} is {@code null}
* @throws IllegalArgumentException if the prototype cannot be cloned
*/
public static <T> Factory<T> prototypeFactory(T prototype) {
public static <T> Factory<T> prototypeFactory(final T prototype) {
return PrototypeFactory.<T>prototypeFactory(prototype);
}
@ -119,7 +119,7 @@ public class FactoryUtils {
* @return the <code>reflection</code> factory
* @throws IllegalArgumentException if the classToInstantiate is null
*/
public static <T> Factory<T> instantiateFactory(Class<T> classToInstantiate) {
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) {
return InstantiateFactory.instantiateFactory(classToInstantiate, null, null);
}
@ -138,7 +138,7 @@ public class FactoryUtils {
* @throws IllegalArgumentException if the paramTypes and args don't match
* @throws IllegalArgumentException if the constructor doesn't exist
*/
public static <T> Factory<T> instantiateFactory(Class<T> classToInstantiate, Class<?>[] paramTypes, Object[] args) {
public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate, final Class<?>[] paramTypes, final Object[] args) {
return InstantiateFactory.instantiateFactory(classToInstantiate, paramTypes, args);
}

View File

@ -42,7 +42,7 @@ public class FunctorException extends RuntimeException {
*
* @param msg the error message.
*/
public FunctorException(String msg) {
public FunctorException(final String msg) {
super(msg);
}
@ -53,7 +53,7 @@ public class FunctorException extends RuntimeException {
* @param rootCause the exception or error that caused this exception
* to be thrown.
*/
public FunctorException(Throwable rootCause) {
public FunctorException(final Throwable rootCause) {
super(rootCause);
}
@ -65,7 +65,7 @@ public class FunctorException extends RuntimeException {
* @param rootCause the exception or error that caused this exception
* to be thrown.
*/
public FunctorException(String msg, Throwable rootCause) {
public FunctorException(final String msg, final Throwable rootCause) {
super(msg, rootCause);
}

View File

@ -193,7 +193,7 @@ public class IteratorUtils {
* @param object the single object over which to iterate
* @return a singleton iterator over the object
*/
public static <E> ResettableIterator<E> singletonIterator(E object) {
public static <E> ResettableIterator<E> singletonIterator(final E object) {
return new SingletonIterator<E>(object);
}
@ -206,7 +206,7 @@ public class IteratorUtils {
* @param object the single object over which to iterate
* @return a singleton list iterator over the object
*/
public static <E> ListIterator<E> singletonListIterator(E object) {
public static <E> ListIterator<E> singletonListIterator(final E object) {
return new SingletonListIterator<E>(object);
}
@ -222,7 +222,7 @@ public class IteratorUtils {
* @return an iterator over the array
* @throws NullPointerException if array is null
*/
public static <E> ResettableIterator<E> arrayIterator(E[] array) {
public static <E> ResettableIterator<E> arrayIterator(final E[] array) {
return new ObjectArrayIterator<E>(array);
}
@ -237,7 +237,7 @@ public class IteratorUtils {
* @throws IllegalArgumentException if the array is not an array
* @throws NullPointerException if array is null
*/
public static <E> ResettableIterator<E> arrayIterator(Object array) {
public static <E> ResettableIterator<E> arrayIterator(final Object array) {
return new ArrayIterator<E>(array);
}
@ -254,7 +254,7 @@ public class IteratorUtils {
* than the length of the array
* @throws NullPointerException if array is null
*/
public static <E> ResettableIterator<E> arrayIterator(E[] array, int start) {
public static <E> ResettableIterator<E> arrayIterator(final E[] array, final int start) {
return new ObjectArrayIterator<E>(array, start);
}
@ -272,7 +272,7 @@ public class IteratorUtils {
* than the length of the array
* @throws NullPointerException if array is null
*/
public static <E> ResettableIterator<E> arrayIterator(Object array, int start) {
public static <E> ResettableIterator<E> arrayIterator(final Object array, final int start) {
return new ArrayIterator<E>(array, start);
}
@ -290,7 +290,7 @@ public class IteratorUtils {
* @throws IllegalArgumentException if end is before start
* @throws NullPointerException if array is null
*/
public static <E> ResettableIterator<E> arrayIterator(E[] array, int start, int end) {
public static <E> ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end) {
return new ObjectArrayIterator<E>(array, start, end);
}
@ -309,7 +309,7 @@ public class IteratorUtils {
* @throws IllegalArgumentException if end is before start
* @throws NullPointerException if array is null
*/
public static <E> ResettableIterator<E> arrayIterator(Object array, int start, int end) {
public static <E> ResettableIterator<E> arrayIterator(final Object array, final int start, final int end) {
return new ArrayIterator<E>(array, start, end);
}
@ -321,7 +321,7 @@ public class IteratorUtils {
* @return a list iterator over the array
* @throws NullPointerException if array is null
*/
public static <E> ResettableListIterator<E> arrayListIterator(E[] array) {
public static <E> ResettableListIterator<E> arrayListIterator(final E[] array) {
return new ObjectArrayListIterator<E>(array);
}
@ -336,7 +336,7 @@ public class IteratorUtils {
* @throws IllegalArgumentException if the array is not an array
* @throws NullPointerException if array is null
*/
public static <E> ResettableListIterator<E> arrayListIterator(Object array) {
public static <E> ResettableListIterator<E> arrayListIterator(final Object array) {
return new ArrayListIterator<E>(array);
}
@ -349,7 +349,7 @@ public class IteratorUtils {
* @throws IndexOutOfBoundsException if start is less than zero
* @throws NullPointerException if array is null
*/
public static <E> ResettableListIterator<E> arrayListIterator(E[] array, int start) {
public static <E> ResettableListIterator<E> arrayListIterator(final E[] array, final int start) {
return new ObjectArrayListIterator<E>(array, start);
}
@ -366,7 +366,7 @@ public class IteratorUtils {
* @throws IndexOutOfBoundsException if start is less than zero
* @throws NullPointerException if array is null
*/
public static <E> ResettableListIterator<E> arrayListIterator(Object array, int start) {
public static <E> ResettableListIterator<E> arrayListIterator(final Object array, final int start) {
return new ArrayListIterator<E>(array, start);
}
@ -381,7 +381,7 @@ public class IteratorUtils {
* @throws IllegalArgumentException if end is before start
* @throws NullPointerException if array is null
*/
public static <E> ResettableListIterator<E> arrayListIterator(E[] array, int start, int end) {
public static <E> ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end) {
return new ObjectArrayListIterator<E>(array, start, end);
}
@ -400,7 +400,7 @@ public class IteratorUtils {
* @throws IllegalArgumentException if end is before start
* @throws NullPointerException if array is null
*/
public static <E> ResettableListIterator<E> arrayListIterator(Object array, int start, int end) {
public static <E> ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end) {
return new ArrayListIterator<E>(array, start, end);
}
@ -414,7 +414,7 @@ public class IteratorUtils {
* @param iterator the iterator to make immutable
* @return an immutable version of the iterator
*/
public static <E> Iterator<E> unmodifiableIterator(Iterator<E> iterator) {
public static <E> Iterator<E> unmodifiableIterator(final Iterator<E> iterator) {
return UnmodifiableIterator.unmodifiableIterator(iterator);
}
@ -427,7 +427,7 @@ public class IteratorUtils {
* @param listIterator the iterator to make immutable
* @return an immutable version of the iterator
*/
public static <E> ListIterator<E> unmodifiableListIterator(ListIterator<E> listIterator) {
public static <E> ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator) {
return UnmodifiableListIterator.umodifiableListIterator(listIterator);
}
@ -439,7 +439,7 @@ public class IteratorUtils {
* @param mapIterator the iterator to make immutable
* @return an immutable version of the iterator
*/
public static <K, V> MapIterator<K, V> unmodifiableMapIterator(MapIterator<K, V> mapIterator) {
public static <K, V> MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator) {
return UnmodifiableMapIterator.unmodifiableMapIterator(mapIterator);
}
@ -454,7 +454,7 @@ public class IteratorUtils {
* @return a combination iterator over the iterators
* @throws NullPointerException if either iterator is null
*/
public static <E> Iterator<E> chainedIterator(Iterator<? extends E> iterator1, Iterator<? extends E> iterator2) {
public static <E> Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) {
return new IteratorChain<E>(iterator1, iterator2);
}
@ -466,7 +466,7 @@ public class IteratorUtils {
* @return a combination iterator over the iterators
* @throws NullPointerException if iterators array is null or contains a null
*/
public static <E> Iterator<E> chainedIterator(Iterator<? extends E>[] iterators) {
public static <E> Iterator<E> chainedIterator(final Iterator<? extends E>[] iterators) {
return new IteratorChain<E>(iterators);
}
@ -479,7 +479,7 @@ public class IteratorUtils {
* @throws NullPointerException if iterators collection is null or contains a null
* @throws ClassCastException if the iterators collection contains the wrong object type
*/
public static <E> Iterator<E> chainedIterator(Collection<Iterator<? extends E>> iterators) {
public static <E> Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators) {
return new IteratorChain<E>(iterators);
}
@ -501,7 +501,7 @@ public class IteratorUtils {
* @return a combination iterator over the iterators
* @throws NullPointerException if either iterator is null
*/
public static <E> Iterator<E> collatedIterator(Comparator<? super E> comparator, Iterator<? extends E> iterator1, Iterator<? extends E> iterator2) {
public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) {
return new CollatingIterator<E>(comparator, iterator1, iterator2);
}
@ -520,7 +520,7 @@ public class IteratorUtils {
* @return a combination iterator over the iterators
* @throws NullPointerException if iterators array is null or contains a null
*/
public static <E> Iterator<E> collatedIterator(Comparator<? super E> comparator, Iterator<? extends E>[] iterators) {
public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E>[] iterators) {
return new CollatingIterator<E>(comparator, iterators);
}
@ -540,8 +540,8 @@ public class IteratorUtils {
* @throws NullPointerException if iterators collection is null or contains a null
* @throws ClassCastException if the iterators collection contains the wrong object type
*/
public static <E> Iterator<E> collatedIterator(Comparator<? super E> comparator,
Collection<Iterator<? extends E>> iterators) {
public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator,
final Collection<Iterator<? extends E>> iterators) {
return new CollatingIterator<E>(comparator, iterators);
}
@ -600,7 +600,7 @@ public class IteratorUtils {
* @return a new object graph iterator
* @since 3.1
*/
public static <E> Iterator<E> objectGraphIterator(E root, Transformer<? super E, ? extends E> transformer) {
public static <E> Iterator<E> objectGraphIterator(final E root, final Transformer<? super E, ? extends E> transformer) {
return new ObjectGraphIterator<E>(root, transformer);
}
@ -617,7 +617,7 @@ public class IteratorUtils {
* @return a new transforming iterator
* @throws NullPointerException if either parameter is null
*/
public static <I, O> Iterator<O> transformedIterator(Iterator<? extends I> iterator, Transformer<? super I, ? extends O> transform) {
public static <I, O> Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
@ -640,7 +640,7 @@ public class IteratorUtils {
* @return a new filtered iterator
* @throws NullPointerException if either parameter is null
*/
public static <E> Iterator<E> filteredIterator(Iterator<? extends E> iterator, Predicate<? super E> predicate) {
public static <E> Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
@ -661,7 +661,7 @@ public class IteratorUtils {
* @return a new filtered iterator
* @throws NullPointerException if either parameter is null
*/
public static <E> ListIterator<E> filteredListIterator(ListIterator<? extends E> listIterator, Predicate<? super E> predicate) {
public static <E> ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator, final Predicate<? super E> predicate) {
if (listIterator == null) {
throw new NullPointerException("ListIterator must not be null");
}
@ -684,7 +684,7 @@ public class IteratorUtils {
* @return a new looping iterator
* @throws NullPointerException if the collection is null
*/
public static <E> ResettableIterator<E> loopingIterator(Collection<? extends E> coll) {
public static <E> ResettableIterator<E> loopingIterator(final Collection<? extends E> coll) {
if (coll == null) {
throw new NullPointerException("Collection must not be null");
}
@ -702,7 +702,7 @@ public class IteratorUtils {
* @throws NullPointerException if the list is null
* @since 3.2
*/
public static <E> ResettableListIterator<E> loopingListIterator(List<E> list) {
public static <E> ResettableListIterator<E> loopingListIterator(final List<E> list) {
if (list == null) {
throw new NullPointerException("List must not be null");
}
@ -717,7 +717,7 @@ public class IteratorUtils {
* @param enumeration the enumeration to use
* @return a new iterator
*/
public static <E> Iterator<E> asIterator(Enumeration<? extends E> enumeration) {
public static <E> Iterator<E> asIterator(final Enumeration<? extends E> enumeration) {
if (enumeration == null) {
throw new NullPointerException("Enumeration must not be null");
}
@ -732,7 +732,7 @@ public class IteratorUtils {
* @param removeCollection the collection to remove elements from
* @return a new iterator
*/
public static <E> Iterator<E> asIterator(Enumeration<? extends E> enumeration, Collection<? super E> removeCollection) {
public static <E> Iterator<E> asIterator(final Enumeration<? extends E> enumeration, final Collection<? super E> removeCollection) {
if (enumeration == null) {
throw new NullPointerException("Enumeration must not be null");
}
@ -749,7 +749,7 @@ public class IteratorUtils {
* @return a new enumeration
* @throws NullPointerException if iterator is null
*/
public static <E> Enumeration<E> asEnumeration(Iterator<? extends E> iterator) {
public static <E> Enumeration<E> asEnumeration(final Iterator<? extends E> iterator) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
@ -764,7 +764,7 @@ public class IteratorUtils {
* @return a new, single use iterable
* @throws NullPointerException if iterator is null
*/
public static <E> Iterable<E> asIterable(Iterator<? extends E> iterator) {
public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
@ -779,7 +779,7 @@ public class IteratorUtils {
* @return a new, multiple use iterable
* @throws NullPointerException if iterator is null
*/
public static <E> Iterable<E> asMultipleUseIterable(Iterator<? extends E> iterator) {
public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
@ -796,7 +796,7 @@ public class IteratorUtils {
* @return a new iterator
* @throws NullPointerException if iterator parameter is null
*/
public static <E> ListIterator<E> toListIterator(Iterator<? extends E> iterator) {
public static <E> ListIterator<E> toListIterator(final Iterator<? extends E> iterator) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
@ -813,11 +813,11 @@ public class IteratorUtils {
* @return an array of the iterator contents
* @throws NullPointerException if iterator parameter is null
*/
public static Object[] toArray(Iterator<?> iterator) {
public static Object[] toArray(final Iterator<?> iterator) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
List<?> list = toList(iterator, 100);
final List<?> list = toList(iterator, 100);
return list.toArray();
}
@ -835,14 +835,14 @@ public class IteratorUtils {
* @throws ClassCastException if the arrayClass is invalid
*/
@SuppressWarnings("unchecked")
public static <E> E[] toArray(Iterator<? extends E> iterator, Class<E> arrayClass) {
public static <E> E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
if (arrayClass == null) {
throw new NullPointerException("Array class must not be null");
}
List<E> list = toList(iterator, 100);
final List<E> list = toList(iterator, 100);
return list.toArray((E[]) Array.newInstance(arrayClass, list.size()));
}
@ -856,7 +856,7 @@ public class IteratorUtils {
* @return a list of the iterator contents
* @throws NullPointerException if iterator parameter is null
*/
public static <E> List<E> toList(Iterator<? extends E> iterator) {
public static <E> List<E> toList(final Iterator<? extends E> iterator) {
return toList(iterator, 10);
}
@ -872,14 +872,14 @@ public class IteratorUtils {
* @throws NullPointerException if iterator parameter is null
* @throws IllegalArgumentException if the size is less than 1
*/
public static <E> List<E> toList(Iterator<? extends E> iterator, int estimatedSize) {
public static <E> List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize) {
if (iterator == null) {
throw new NullPointerException("Iterator must not be null");
}
if (estimatedSize < 1) {
throw new IllegalArgumentException("Estimated size must be greater than 0");
}
List<E> list = new ArrayList<E>(estimatedSize);
final List<E> list = new ArrayList<E>(estimatedSize);
while (iterator.hasNext()) {
list.add(iterator.next());
}
@ -905,7 +905,7 @@ public class IteratorUtils {
* @param obj the object to convert to an iterator
* @return a suitable iterator, never null
*/
public static Iterator<?> getIterator(Object obj) {
public static Iterator<?> getIterator(final Object obj) {
if (obj == null) {
return emptyIterator();
}
@ -930,20 +930,20 @@ public class IteratorUtils {
return new ArrayIterator<Object>(obj);
}
try {
Method method = obj.getClass().getMethod("iterator", (Class[]) null);
final Method method = obj.getClass().getMethod("iterator", (Class[]) null);
if (Iterator.class.isAssignableFrom(method.getReturnType())) {
Iterator<?> it = (Iterator<?>) method.invoke(obj, (Object[]) null);
final Iterator<?> it = (Iterator<?>) method.invoke(obj, (Object[]) null);
if (it != null) {
return it;
}
}
} catch (RuntimeException e) {
} catch (final RuntimeException e) {
// ignore
} catch (NoSuchMethodException e) {
} catch (final NoSuchMethodException e) {
// ignore
} catch (IllegalAccessException e) {
} catch (final IllegalAccessException e) {
// ignore
} catch (InvocationTargetException e) {
} catch (final InvocationTargetException e) {
// ignore
}
return singletonIterator(obj);

View File

@ -63,7 +63,7 @@ public class ListUtils {
* @param list the list, possibly <code>null</code>
* @return an empty list if the argument is <code>null</code>
*/
public static <T> List<T> emptyIfNull(List<T> list) {
public static <T> List<T> emptyIfNull(final List<T> list) {
return list == null ? Collections.<T>emptyList() : list;
}
@ -87,9 +87,9 @@ public class ListUtils {
larger = list1;
}
HashSet<E> hashSet = new HashSet<E>(smaller);
final HashSet<E> hashSet = new HashSet<E>(smaller);
for (E e : larger) {
for (final E e : larger) {
if (hashSet.contains(e)) {
result.add(e);
hashSet.remove(e);
@ -174,8 +174,8 @@ public class ListUtils {
* @since 4.0
* @see CollectionUtils#select(Collection, Predicate)
*/
public static <E> List<E> select(Collection<? extends E> inputCollection,
Predicate<? super E> predicate) {
public static <E> List<E> select(final Collection<? extends E> inputCollection,
final Predicate<? super E> predicate) {
return CollectionUtils.select(inputCollection, predicate, new ArrayList<E>(inputCollection.size()));
}
@ -198,8 +198,8 @@ public class ListUtils {
* @since 4.0
* @see CollectionUtils#selectRejected(Collection, Predicate)
*/
public static <E> List<E> selectRejected(Collection<? extends E> inputCollection,
Predicate<? super E> predicate) {
public static <E> List<E> selectRejected(final Collection<? extends E> inputCollection,
final Predicate<? super E> predicate) {
return CollectionUtils.selectRejected(inputCollection, predicate, new ArrayList<E>(inputCollection.size()));
}
@ -240,8 +240,8 @@ public class ListUtils {
return false;
}
Iterator<?> it1 = list1.iterator();
Iterator<?> it2 = list2.iterator();
final Iterator<?> it1 = list1.iterator();
final Iterator<?> it2 = list2.iterator();
Object obj1 = null;
Object obj2 = null;
@ -274,10 +274,10 @@ public class ListUtils {
return 0;
}
int hashCode = 1;
Iterator<?> it = list.iterator();
final Iterator<?> it = list.iterator();
while (it.hasNext()) {
Object obj = it.next();
final Object obj = it.next();
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}
return hashCode;
@ -306,10 +306,10 @@ public class ListUtils {
* @throws NullPointerException if either parameter is null
* @since 3.2
*/
public static <E> List<E> retainAll(Collection<E> collection, Collection<?> retain) {
List<E> list = new ArrayList<E>(Math.min(collection.size(), retain.size()));
public static <E> List<E> retainAll(final Collection<E> collection, final Collection<?> retain) {
final List<E> list = new ArrayList<E>(Math.min(collection.size(), retain.size()));
for (E obj : collection) {
for (final E obj : collection) {
if (retain.contains(obj)) {
list.add(obj);
}
@ -340,9 +340,9 @@ public class ListUtils {
* @throws NullPointerException if either parameter is null
* @since 3.2
*/
public static <E> List<E> removeAll(Collection<E> collection, Collection<?> remove) {
List<E> list = new ArrayList<E>();
for (E obj : collection) {
public static <E> List<E> removeAll(final Collection<E> collection, final Collection<?> remove) {
final List<E> list = new ArrayList<E>();
for (final E obj : collection) {
if (!remove.contains(obj)) {
list.add(obj);
}
@ -374,7 +374,7 @@ public class ListUtils {
* @return a synchronized list backed by the given list
* @throws IllegalArgumentException if the list is null
*/
public static <E> List<E> synchronizedList(List<E> list) {
public static <E> List<E> synchronizedList(final List<E> list) {
return SynchronizedList.synchronizedList(list);
}
@ -388,7 +388,7 @@ public class ListUtils {
* @return an unmodifiable list backed by the given list
* @throws IllegalArgumentException if the list is null
*/
public static <E> List<E> unmodifiableList(List<E> list) {
public static <E> List<E> unmodifiableList(final List<E> list) {
return UnmodifiableList.unmodifiableList(list);
}
@ -406,7 +406,7 @@ public class ListUtils {
* @return a predicated list backed by the given list
* @throws IllegalArgumentException if the List or Predicate is null
*/
public static <E> List<E> predicatedList(List<E> list, Predicate<E> predicate) {
public static <E> List<E> predicatedList(final List<E> list, final Predicate<E> predicate) {
return PredicatedList.predicatedList(list, predicate);
}
@ -430,7 +430,7 @@ public class ListUtils {
* @return a transformed list backed by the given list
* @throws IllegalArgumentException if the List or Transformer is null
*/
public static <E> List<E> transformedList(List<E> list, Transformer<? super E, ? extends E> transformer) {
public static <E> List<E> transformedList(final List<E> list, final Transformer<? super E, ? extends E> transformer) {
return TransformedList.transformingList(list, transformer);
}
@ -464,7 +464,7 @@ public class ListUtils {
* @return a lazy list backed by the given list
* @throws IllegalArgumentException if the List or Factory is null
*/
public static <E> List<E> lazyList(List<E> list, Factory<? extends E> factory) {
public static <E> List<E> lazyList(final List<E> list, final Factory<? extends E> factory) {
return LazyList.lazyList(list, factory);
}
@ -479,7 +479,7 @@ public class ListUtils {
* @return a fixed-size list backed by that list
* @throws IllegalArgumentException if the List is null
*/
public static <E> List<E> fixedSizeList(List<E> list) {
public static <E> List<E> fixedSizeList(final List<E> list) {
return FixedSizeList.fixedSizeList(list);
}
@ -494,10 +494,10 @@ public class ListUtils {
* @param predicate the predicate to use, may be null
* @return the first index of an Object in the List which matches the predicate or -1 if none could be found
*/
public static <E> int indexOf(List<E> list, Predicate<E> predicate) {
public static <E> int indexOf(final List<E> list, final Predicate<E> predicate) {
if (list != null && predicate != null) {
for (int i = 0; i < list.size(); i++) {
E item = list.get(i);
final E item = list.get(i);
if (predicate.evaluate(item)) {
return i;
}
@ -526,7 +526,7 @@ public class ListUtils {
* @return a list of consecutive sublists
* @throws IllegalArgumentException if list is {@code null} or size is not strictly positive
*/
public static <T> List<List<T>> partition(List<T> list, int size) {
public static <T> List<List<T>> partition(final List<T> list, final int size) {
if (list == null) {
throw new IllegalArgumentException("List must not be null");
}
@ -543,14 +543,14 @@ public class ListUtils {
private final List<T> list;
private final int size;
private Partition(List<T> list, int size) {
private Partition(final List<T> list, final int size) {
this.list = list;
this.size = size;
}
@Override
public List<T> get(int index) {
int listSize = size();
public List<T> get(final int index) {
final int listSize = size();
if (listSize < 0) {
throw new IllegalArgumentException("negative size: " + listSize);
}
@ -561,8 +561,8 @@ public class ListUtils {
throw new IndexOutOfBoundsException("Index " + index + " must be less than size " +
listSize);
}
int start = index * size;
int end = Math.min(start + size, list.size());
final int start = index * size;
final int end = Math.min(start + size, list.size());
return list.subList(start, end);
}

View File

@ -127,7 +127,7 @@ public class MapUtils {
*/
public static <K> String getString(final Map<? super K, ?> map, final K key) {
if (map != null) {
Object answer = map.get(key);
final Object answer = map.get(key);
if (answer != null) {
return answer.toString();
}
@ -151,7 +151,7 @@ public class MapUtils {
*/
public static <K> Boolean getBoolean(final Map<? super K, ?> map, final K key) {
if (map != null) {
Object answer = map.get(key);
final Object answer = map.get(key);
if (answer != null) {
if (answer instanceof Boolean) {
return (Boolean) answer;
@ -160,7 +160,7 @@ public class MapUtils {
return Boolean.valueOf((String) answer);
}
if (answer instanceof Number) {
Number n = (Number) answer;
final Number n = (Number) answer;
return n.intValue() != 0 ? Boolean.TRUE : Boolean.FALSE;
}
}
@ -183,16 +183,16 @@ public class MapUtils {
*/
public static <K> Number getNumber(final Map<? super K, ?> map, final K key) {
if (map != null) {
Object answer = map.get(key);
final Object answer = map.get(key);
if (answer != null) {
if (answer instanceof Number) {
return (Number) answer;
}
if (answer instanceof String) {
try {
String text = (String) answer;
final String text = (String) answer;
return NumberFormat.getInstance().parse(text);
} catch (ParseException e) {
} catch (final ParseException e) {
// failure means null is returned
}
}
@ -211,7 +211,7 @@ public class MapUtils {
* @return the value in the Map as a Byte, <code>null</code> if null map input
*/
public static <K> Byte getByte(final Map<? super K, ?> map, final K key) {
Number answer = getNumber(map, key);
final Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
@ -231,7 +231,7 @@ public class MapUtils {
* @return the value in the Map as a Short, <code>null</code> if null map input
*/
public static <K> Short getShort(final Map<? super K, ?> map, final K key) {
Number answer = getNumber(map, key);
final Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
@ -251,7 +251,7 @@ public class MapUtils {
* @return the value in the Map as a Integer, <code>null</code> if null map input
*/
public static <K> Integer getInteger(final Map<? super K, ?> map, final K key) {
Number answer = getNumber(map, key);
final Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
@ -271,7 +271,7 @@ public class MapUtils {
* @return the value in the Map as a Long, <code>null</code> if null map input
*/
public static <K> Long getLong(final Map<? super K, ?> map, final K key) {
Number answer = getNumber(map, key);
final Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
@ -291,7 +291,7 @@ public class MapUtils {
* @return the value in the Map as a Float, <code>null</code> if null map input
*/
public static <K> Float getFloat(final Map<? super K, ?> map, final K key) {
Number answer = getNumber(map, key);
final Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
@ -311,7 +311,7 @@ public class MapUtils {
* @return the value in the Map as a Double, <code>null</code> if null map input
*/
public static <K> Double getDouble(final Map<? super K, ?> map, final K key) {
Number answer = getNumber(map, key);
final Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
@ -333,7 +333,7 @@ public class MapUtils {
*/
public static <K> Map<?, ?> getMap(final Map<? super K, ?> map, final K key) {
if (map != null) {
Object answer = map.get(key);
final Object answer = map.get(key);
if (answer != null && answer instanceof Map) {
return (Map<?, ?>) answer;
}
@ -353,9 +353,9 @@ public class MapUtils {
* @return the value in the map, or defaultValue if the original value
* is null or the map is null
*/
public static <K, V> V getObject(Map<K, V> map, K key, V defaultValue) {
public static <K, V> V getObject(final Map<K, V> map, final K key, final V defaultValue) {
if (map != null) {
V answer = map.get(key);
final V answer = map.get(key);
if (answer != null) {
return answer;
}
@ -375,7 +375,7 @@ public class MapUtils {
* original value is null, the map is null or the string conversion
* fails
*/
public static <K> String getString(Map<? super K, ?> map, K key, String defaultValue) {
public static <K> String getString(final Map<? super K, ?> map, final K key, final String defaultValue) {
String answer = getString(map, key);
if (answer == null) {
answer = defaultValue;
@ -395,7 +395,7 @@ public class MapUtils {
* original value is null, the map is null or the boolean conversion
* fails
*/
public static <K> Boolean getBoolean(Map<? super K, ?> map, K key, Boolean defaultValue) {
public static <K> Boolean getBoolean(final Map<? super K, ?> map, final K key, final Boolean defaultValue) {
Boolean answer = getBoolean(map, key);
if (answer == null) {
answer = defaultValue;
@ -415,7 +415,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Number getNumber(Map<? super K, ?> map, K key, Number defaultValue) {
public static <K> Number getNumber(final Map<? super K, ?> map, final K key, final Number defaultValue) {
Number answer = getNumber(map, key);
if (answer == null) {
answer = defaultValue;
@ -435,7 +435,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Byte getByte(Map<? super K, ?> map, K key, Byte defaultValue) {
public static <K> Byte getByte(final Map<? super K, ?> map, final K key, final Byte defaultValue) {
Byte answer = getByte(map, key);
if (answer == null) {
answer = defaultValue;
@ -455,7 +455,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Short getShort(Map<? super K, ?> map, K key, Short defaultValue) {
public static <K> Short getShort(final Map<? super K, ?> map, final K key, final Short defaultValue) {
Short answer = getShort(map, key);
if (answer == null) {
answer = defaultValue;
@ -475,7 +475,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Integer getInteger(Map<? super K, ?> map, K key, Integer defaultValue) {
public static <K> Integer getInteger(final Map<? super K, ?> map, final K key, final Integer defaultValue) {
Integer answer = getInteger(map, key);
if (answer == null) {
answer = defaultValue;
@ -495,7 +495,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Long getLong(Map<? super K, ?> map, K key, Long defaultValue) {
public static <K> Long getLong(final Map<? super K, ?> map, final K key, final Long defaultValue) {
Long answer = getLong(map, key);
if (answer == null) {
answer = defaultValue;
@ -515,7 +515,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Float getFloat(Map<? super K, ?> map, K key, Float defaultValue) {
public static <K> Float getFloat(final Map<? super K, ?> map, final K key, final Float defaultValue) {
Float answer = getFloat(map, key);
if (answer == null) {
answer = defaultValue;
@ -535,7 +535,7 @@ public class MapUtils {
* original value is null, the map is null or the number conversion
* fails
*/
public static <K> Double getDouble(Map<? super K, ?> map, K key, Double defaultValue) {
public static <K> Double getDouble(final Map<? super K, ?> map, final K key, final Double defaultValue) {
Double answer = getDouble(map, key);
if (answer == null) {
answer = defaultValue;
@ -555,7 +555,7 @@ public class MapUtils {
* original value is null, the map is null or the map conversion
* fails
*/
public static <K> Map<?, ?> getMap(Map<? super K, ?> map, K key, Map<?, ?> defaultValue) {
public static <K> Map<?, ?> getMap(final Map<? super K, ?> map, final K key, final Map<?, ?> defaultValue) {
Map<?, ?> answer = getMap(map, key);
if (answer == null) {
answer = defaultValue;
@ -593,7 +593,7 @@ public class MapUtils {
* @return the value in the Map as a byte, <code>0</code> if null map input
*/
public static <K> byte getByteValue(final Map<? super K, ?> map, final K key) {
Byte byteObject = getByte(map, key);
final Byte byteObject = getByte(map, key);
if (byteObject == null) {
return 0;
}
@ -610,7 +610,7 @@ public class MapUtils {
* @return the value in the Map as a short, <code>0</code> if null map input
*/
public static <K> short getShortValue(final Map<? super K, ?> map, final K key) {
Short shortObject = getShort(map, key);
final Short shortObject = getShort(map, key);
if (shortObject == null) {
return 0;
}
@ -627,7 +627,7 @@ public class MapUtils {
* @return the value in the Map as an int, <code>0</code> if null map input
*/
public static <K> int getIntValue(final Map<? super K, ?> map, final K key) {
Integer integerObject = getInteger(map, key);
final Integer integerObject = getInteger(map, key);
if (integerObject == null) {
return 0;
}
@ -644,7 +644,7 @@ public class MapUtils {
* @return the value in the Map as a long, <code>0L</code> if null map input
*/
public static <K> long getLongValue(final Map<? super K, ?> map, final K key) {
Long longObject = getLong(map, key);
final Long longObject = getLong(map, key);
if (longObject == null) {
return 0L;
}
@ -661,7 +661,7 @@ public class MapUtils {
* @return the value in the Map as a float, <code>0.0F</code> if null map input
*/
public static <K> float getFloatValue(final Map<? super K, ?> map, final K key) {
Float floatObject = getFloat(map, key);
final Float floatObject = getFloat(map, key);
if (floatObject == null) {
return 0f;
}
@ -678,7 +678,7 @@ public class MapUtils {
* @return the value in the Map as a double, <code>0.0</code> if null map input
*/
public static <K> double getDoubleValue(final Map<? super K, ?> map, final K key) {
Double doubleObject = getDouble(map, key);
final Double doubleObject = getDouble(map, key);
if (doubleObject == null) {
return 0d;
}
@ -704,8 +704,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as a Boolean, <code>defaultValue</code> if null map input
*/
public static <K> boolean getBooleanValue(final Map<? super K, ?> map, final K key, boolean defaultValue) {
Boolean booleanObject = getBoolean(map, key);
public static <K> boolean getBooleanValue(final Map<? super K, ?> map, final K key, final boolean defaultValue) {
final Boolean booleanObject = getBoolean(map, key);
if (booleanObject == null) {
return defaultValue;
}
@ -724,8 +724,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as a byte, <code>defaultValue</code> if null map input
*/
public static <K> byte getByteValue(final Map<? super K, ?> map, final K key, byte defaultValue) {
Byte byteObject = getByte(map, key);
public static <K> byte getByteValue(final Map<? super K, ?> map, final K key, final byte defaultValue) {
final Byte byteObject = getByte(map, key);
if (byteObject == null) {
return defaultValue;
}
@ -744,8 +744,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as a short, <code>defaultValue</code> if null map input
*/
public static <K> short getShortValue(final Map<? super K, ?> map, final K key, short defaultValue) {
Short shortObject = getShort(map, key);
public static <K> short getShortValue(final Map<? super K, ?> map, final K key, final short defaultValue) {
final Short shortObject = getShort(map, key);
if (shortObject == null) {
return defaultValue;
}
@ -764,8 +764,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as an int, <code>defaultValue</code> if null map input
*/
public static <K> int getIntValue(final Map<? super K, ?> map, final K key, int defaultValue) {
Integer integerObject = getInteger(map, key);
public static <K> int getIntValue(final Map<? super K, ?> map, final K key, final int defaultValue) {
final Integer integerObject = getInteger(map, key);
if (integerObject == null) {
return defaultValue;
}
@ -784,8 +784,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as a long, <code>defaultValue</code> if null map input
*/
public static <K> long getLongValue(final Map<? super K, ?> map, final K key, long defaultValue) {
Long longObject = getLong(map, key);
public static <K> long getLongValue(final Map<? super K, ?> map, final K key, final long defaultValue) {
final Long longObject = getLong(map, key);
if (longObject == null) {
return defaultValue;
}
@ -804,8 +804,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as a float, <code>defaultValue</code> if null map input
*/
public static <K> float getFloatValue(final Map<? super K, ?> map, final K key, float defaultValue) {
Float floatObject = getFloat(map, key);
public static <K> float getFloatValue(final Map<? super K, ?> map, final K key, final float defaultValue) {
final Float floatObject = getFloat(map, key);
if (floatObject == null) {
return defaultValue;
}
@ -824,8 +824,8 @@ public class MapUtils {
* conversion fails
* @return the value in the Map as a double, <code>defaultValue</code> if null map input
*/
public static <K> double getDoubleValue(final Map<? super K, ?> map, final K key, double defaultValue) {
Double doubleObject = getDouble(map, key);
public static <K> double getDoubleValue(final Map<? super K, ?> map, final K key, final double defaultValue) {
final Double doubleObject = getDouble(map, key);
if (doubleObject == null) {
return defaultValue;
}
@ -842,12 +842,12 @@ public class MapUtils {
* @return the properties object
*/
public static <K, V> Properties toProperties(final Map<K, V> map) {
Properties answer = new Properties();
final Properties answer = new Properties();
if (map != null) {
for (Entry<K, V> entry2 : map.entrySet()) {
Map.Entry<?, ?> entry = entry2;
Object key = entry.getKey();
Object value = entry.getValue();
for (final Entry<K, V> entry2 : map.entrySet()) {
final Map.Entry<?, ?> entry = entry2;
final Object key = entry.getKey();
final Object value = entry.getValue();
answer.put(key, value);
}
}
@ -862,12 +862,12 @@ public class MapUtils {
* @throws NullPointerException if the bundle is null
*/
public static Map<String, Object> toMap(final ResourceBundle resourceBundle) {
Enumeration<String> enumeration = resourceBundle.getKeys();
Map<String, Object> map = new HashMap<String, Object>();
final Enumeration<String> enumeration = resourceBundle.getKeys();
final Map<String, Object> map = new HashMap<String, Object>();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
Object value = resourceBundle.getObject(key);
final String key = enumeration.nextElement();
final Object value = resourceBundle.getObject(key);
map.put(key, value);
}
@ -980,9 +980,9 @@ public class MapUtils {
lineage.push(map);
for (Map.Entry<?, ?> entry : map.entrySet()) {
Object childKey = entry.getKey();
Object childValue = entry.getValue();
for (final Map.Entry<?, ?> entry : map.entrySet()) {
final Object childKey = entry.getKey();
final Object childValue = entry.getValue();
if (childValue instanceof Map && !lineage.contains(childValue)) {
verbosePrintInternal(
out,
@ -1048,9 +1048,9 @@ public class MapUtils {
* @return a new HashMap containing the inverted data
* @throws NullPointerException if the map is null
*/
public static <K, V> Map<V, K> invertMap(Map<K, V> map) {
Map<V, K> out = new HashMap<V, K>(map.size());
for (Entry<K, V> entry : map.entrySet()) {
public static <K, V> Map<V, K> invertMap(final Map<K, V> map) {
final Map<V, K> out = new HashMap<V, K>(map.size());
for (final Entry<K, V> entry : map.entrySet()) {
out.put(entry.getValue(), entry.getKey());
}
return out;
@ -1076,7 +1076,7 @@ public class MapUtils {
* @param value the value, null converted to ""
* @throws NullPointerException if the map is null
*/
public static <K> void safeAddToMap(Map<? super K, Object> map, K key, Object value) throws NullPointerException {
public static <K> void safeAddToMap(final Map<? super K, Object> map, final K key, final Object value) throws NullPointerException {
map.put(key, value == null ? "" : value);
}
@ -1129,25 +1129,25 @@ public class MapUtils {
* @since 3.2
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> putAll(Map<K, V> map, Object[] array) {
public static <K, V> Map<K, V> putAll(final Map<K, V> map, final Object[] array) {
map.size(); // force NPE
if (array == null || array.length == 0) {
return map;
}
Object obj = array[0];
final Object obj = array[0];
if (obj instanceof Map.Entry) {
for (Object element : array) {
Map.Entry<K, V> entry = (Map.Entry<K, V>) element;
for (final Object element : array) {
final Map.Entry<K, V> entry = (Map.Entry<K, V>) element;
map.put(entry.getKey(), entry.getValue());
}
} else if (obj instanceof KeyValue) {
for (Object element : array) {
KeyValue<K, V> keyval = (KeyValue<K, V>) element;
for (final Object element : array) {
final KeyValue<K, V> keyval = (KeyValue<K, V>) element;
map.put(keyval.getKey(), keyval.getValue());
}
} else if (obj instanceof Object[]) {
for (int i = 0; i < array.length; i++) {
Object[] sub = (Object[]) array[i];
final Object[] sub = (Object[]) array[i];
if (sub == null || sub.length < 2) {
throw new IllegalArgumentException("Invalid array element: " + i);
}
@ -1172,7 +1172,7 @@ public class MapUtils {
* @param map the map, possibly <code>null</code>
* @return an empty map if the argument is <code>null</code>
*/
public static <K,V> Map<K,V> emptyIfNull(Map<K,V> map) {
public static <K,V> Map<K,V> emptyIfNull(final Map<K,V> map) {
return map == null ? Collections.<K,V>emptyMap() : map;
}
@ -1185,7 +1185,7 @@ public class MapUtils {
* @return true if empty or null
* @since 3.2
*/
public static boolean isEmpty(Map<?,?> map) {
public static boolean isEmpty(final Map<?,?> map) {
return map == null || map.isEmpty();
}
@ -1198,7 +1198,7 @@ public class MapUtils {
* @return true if non-null and non-empty
* @since 3.2
*/
public static boolean isNotEmpty(Map<?,?> map) {
public static boolean isNotEmpty(final Map<?,?> map) {
return !MapUtils.isEmpty(map);
}
@ -1226,7 +1226,7 @@ public class MapUtils {
* @param map the map to synchronize, must not be null
* @return a synchronized map backed by the given map
*/
public static <K, V> Map<K, V> synchronizedMap(Map<K, V> map) {
public static <K, V> Map<K, V> synchronizedMap(final Map<K, V> map) {
return Collections.synchronizedMap(map);
}
@ -1239,7 +1239,7 @@ public class MapUtils {
* @return an unmodifiable map backed by the given map
* @throws IllegalArgumentException if the map is null
*/
public static <K, V> Map<K, V> unmodifiableMap(Map<K, V> map) {
public static <K, V> Map<K, V> unmodifiableMap(final Map<K, V> map) {
return UnmodifiableMap.unmodifiableMap(map);
}
@ -1258,7 +1258,7 @@ public class MapUtils {
* @return a predicated map backed by the given map
* @throws IllegalArgumentException if the Map is null
*/
public static <K, V> IterableMap<K, V> predicatedMap(Map<K, V> map, Predicate<? super K> keyPred, Predicate<? super V> valuePred) {
public static <K, V> IterableMap<K, V> predicatedMap(final Map<K, V> map, final Predicate<? super K> keyPred, final Predicate<? super V> valuePred) {
return PredicatedMap.predicatedMap(map, keyPred, valuePred);
}
@ -1283,9 +1283,9 @@ public class MapUtils {
* @return a transformed map backed by the given map
* @throws IllegalArgumentException if the Map is null
*/
public static <K, V> IterableMap<K, V> transformedMap(Map<K, V> map,
Transformer<? super K, ? extends K> keyTransformer,
Transformer<? super V, ? extends V> valueTransformer) {
public static <K, V> IterableMap<K, V> transformedMap(final Map<K, V> map,
final Transformer<? super K, ? extends K> keyTransformer,
final Transformer<? super V, ? extends V> valueTransformer) {
return TransformedMap.transformingMap(map, keyTransformer, valueTransformer);
}
@ -1299,7 +1299,7 @@ public class MapUtils {
* @return a fixed-size map backed by that map
* @throws IllegalArgumentException if the Map is null
*/
public static <K, V> IterableMap<K, V> fixedSizeMap(Map<K, V> map) {
public static <K, V> IterableMap<K, V> fixedSizeMap(final Map<K, V> map) {
return FixedSizeMap.fixedSizeMap(map);
}
@ -1331,7 +1331,7 @@ public class MapUtils {
* @return a lazy map backed by the given map
* @throws IllegalArgumentException if the Map or Factory is null
*/
public static <K, V> IterableMap<K, V> lazyMap(Map<K, V> map, Factory<? extends V> factory) {
public static <K, V> IterableMap<K, V> lazyMap(final Map<K, V> map, final Factory<? extends V> factory) {
return LazyMap.lazyMap(map, factory);
}
@ -1370,7 +1370,7 @@ public class MapUtils {
* @return a lazy map backed by the given map
* @throws IllegalArgumentException if the Map or Transformer is null
*/
public static <K, V> IterableMap<K, V> lazyMap(Map<K, V> map, Transformer<? super K, ? extends V> transformerFactory) {
public static <K, V> IterableMap<K, V> lazyMap(final Map<K, V> map, final Transformer<? super K, ? extends V> transformerFactory) {
return LazyMap.lazyMap(map, transformerFactory);
}
@ -1385,7 +1385,7 @@ public class MapUtils {
* @return an ordered map backed by the given map
* @throws IllegalArgumentException if the Map is null
*/
public static <K, V> OrderedMap<K, V> orderedMap(Map<K, V> map) {
public static <K, V> OrderedMap<K, V> orderedMap(final Map<K, V> map) {
return ListOrderedMap.listOrderedMap(map);
}
@ -1398,7 +1398,7 @@ public class MapUtils {
* @see MultiValueMap
* @since 3.2
*/
public static <K, V> MultiValueMap<K, V> multiValueMap(Map<K, ? super Collection<V>> map) {
public static <K, V> MultiValueMap<K, V> multiValueMap(final Map<K, ? super Collection<V>> map) {
return MultiValueMap.<K, V>multiValueMap(map);
}
@ -1413,7 +1413,7 @@ public class MapUtils {
* @see MultiValueMap
* @since 3.2
*/
public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(Map<K, C> map, Class<C> collectionClass) {
public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(final Map<K, C> map, final Class<C> collectionClass) {
return MultiValueMap.multiValueMap(map, collectionClass);
}
@ -1428,7 +1428,7 @@ public class MapUtils {
* @see MultiValueMap
* @since 3.2
*/
public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(Map<K, C> map, Factory<C> collectionFactory) {
public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(final Map<K, C> map, final Factory<C> collectionFactory) {
return MultiValueMap.multiValueMap(map, collectionFactory);
}
@ -1457,7 +1457,7 @@ public class MapUtils {
* @return a synchronized map backed by the given map
* @throws IllegalArgumentException if the map is null
*/
public static <K, V> SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> map) {
public static <K, V> SortedMap<K, V> synchronizedSortedMap(final SortedMap<K, V> map) {
return Collections.synchronizedSortedMap(map);
}
@ -1470,7 +1470,7 @@ public class MapUtils {
* @return an unmodifiable map backed by the given map
* @throws IllegalArgumentException if the map is null
*/
public static <K, V> SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, V> map) {
public static <K, V> SortedMap<K, V> unmodifiableSortedMap(final SortedMap<K, V> map) {
return UnmodifiableSortedMap.unmodifiableSortedMap(map);
}
@ -1489,8 +1489,8 @@ public class MapUtils {
* @return a predicated map backed by the given map
* @throws IllegalArgumentException if the SortedMap is null
*/
public static <K, V> SortedMap<K, V> predicatedSortedMap(SortedMap<K, V> map,
Predicate<? super K> keyPred, Predicate<? super V> valuePred) {
public static <K, V> SortedMap<K, V> predicatedSortedMap(final SortedMap<K, V> map,
final Predicate<? super K> keyPred, final Predicate<? super V> valuePred) {
return PredicatedSortedMap.predicatedSortedMap(map, keyPred, valuePred);
}
@ -1515,9 +1515,9 @@ public class MapUtils {
* @return a transformed map backed by the given map
* @throws IllegalArgumentException if the SortedMap is null
*/
public static <K, V> SortedMap<K, V> transformedSortedMap(SortedMap<K, V> map,
Transformer<? super K, ? extends K> keyTransformer,
Transformer<? super V, ? extends V> valueTransformer) {
public static <K, V> SortedMap<K, V> transformedSortedMap(final SortedMap<K, V> map,
final Transformer<? super K, ? extends K> keyTransformer,
final Transformer<? super V, ? extends V> valueTransformer) {
return TransformedSortedMap.transformingSortedMap(map, keyTransformer, valueTransformer);
}
@ -1531,7 +1531,7 @@ public class MapUtils {
* @return a fixed-size map backed by that map
* @throws IllegalArgumentException if the SortedMap is null
*/
public static <K, V> SortedMap<K, V> fixedSizeSortedMap(SortedMap<K, V> map) {
public static <K, V> SortedMap<K, V> fixedSizeSortedMap(final SortedMap<K, V> map) {
return FixedSizeSortedMap.fixedSizeSortedMap(map);
}
@ -1564,8 +1564,8 @@ public class MapUtils {
* @return a lazy map backed by the given map
* @throws IllegalArgumentException if the SortedMap or Factory is null
*/
public static <K, V> SortedMap<K, V> lazySortedMap(SortedMap<K, V> map,
Factory<? extends V> factory) {
public static <K, V> SortedMap<K, V> lazySortedMap(final SortedMap<K, V> map,
final Factory<? extends V> factory) {
return LazySortedMap.lazySortedMap(map, factory);
}
@ -1604,8 +1604,8 @@ public class MapUtils {
* @return a lazy map backed by the given map
* @throws IllegalArgumentException if the Map or Transformer is null
*/
public static <K, V> SortedMap<K, V> lazySortedMap(SortedMap<K, V> map,
Transformer<? super K, ? extends V> transformerFactory) {
public static <K, V> SortedMap<K, V> lazySortedMap(final SortedMap<K, V> map,
final Transformer<? super K, ? extends V> transformerFactory) {
return LazySortedMap.lazySortedMap(map, transformerFactory);
}
@ -1619,7 +1619,7 @@ public class MapUtils {
* @param keyTransformer the <code>Transformer</code> used to transform the collection value into a key value
* @throws NullPointerException if the map, collection or transformer are null
*/
public static <K, V> void populateMap(Map<K, V> map, Collection<? extends V> collection, Transformer<V, K> keyTransformer) {
public static <K, V> void populateMap(final Map<K, V> map, final Collection<? extends V> collection, final Transformer<V, K> keyTransformer) {
populateMap(map, collection, keyTransformer, TransformerUtils.<V>nopTransformer());
}
@ -1634,12 +1634,12 @@ public class MapUtils {
* @param valueTransformer the <code>Transformer</code> used to transform the collection value into a value
* @throws NullPointerException if the map, collection or transformers are null
*/
public static <K, V, E> void populateMap(Map<K, V> map, Collection<? extends E> collection,
Transformer<E, K> keyTransformer,
Transformer<E, V> valueTransformer) {
Iterator<? extends E> iter = collection.iterator();
public static <K, V, E> void populateMap(final Map<K, V> map, final Collection<? extends E> collection,
final Transformer<E, K> keyTransformer,
final Transformer<E, V> valueTransformer) {
final Iterator<? extends E> iter = collection.iterator();
while (iter.hasNext()) {
E temp = iter.next();
final E temp = iter.next();
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
}
}
@ -1652,7 +1652,7 @@ public class MapUtils {
* @return IterableMap<K, V>
* @since 4.0
*/
public static <K, V> IterableMap<K, V> iterableMap(Map<K, V> map) {
public static <K, V> IterableMap<K, V> iterableMap(final Map<K, V> map) {
if (map == null) {
throw new IllegalArgumentException("Map must not be null");
}
@ -1669,7 +1669,7 @@ public class MapUtils {
* @return {@link IterableSortedMap}<K, V>
* @since 4.0
*/
public static <K, V> IterableSortedMap<K, V> iterableSortedMap(SortedMap<K, V> sortedMap) {
public static <K, V> IterableSortedMap<K, V> iterableSortedMap(final SortedMap<K, V> sortedMap) {
if (sortedMap == null) {
throw new IllegalArgumentException("Map must not be null");
}

View File

@ -154,7 +154,7 @@ public class PredicateUtils {
* @deprecated use {@link EqualPredicate#equalPredicate(Object)} instead.
*/
@Deprecated
public static <T> Predicate<T> equalPredicate(T value) {
public static <T> Predicate<T> equalPredicate(final T value) {
return EqualPredicate.equalPredicate(value);
}
@ -167,7 +167,7 @@ public class PredicateUtils {
* @param value the value to compare against
* @return the predicate
*/
public static <T> Predicate<T> identityPredicate(T value) {
public static <T> Predicate<T> identityPredicate(final T value) {
return IdentityPredicate.<T>identityPredicate(value);
}
@ -182,7 +182,7 @@ public class PredicateUtils {
* @return the predicate
* @throws IllegalArgumentException if the class is null
*/
public static Predicate<Object> instanceofPredicate(Class<?> type) {
public static Predicate<Object> instanceofPredicate(final Class<?> type) {
return InstanceofPredicate.instanceOfPredicate(type);
}
@ -219,7 +219,7 @@ public class PredicateUtils {
* @return the predicate
* @throws IllegalArgumentException if the methodName is null.
*/
public static <T> Predicate<T> invokerPredicate(String methodName){
public static <T> Predicate<T> invokerPredicate(final String methodName){
// reuse transformer as it has caching - this is lazy really, should have inner class here
return asPredicate(InvokerTransformer.<Object, Boolean>invokerTransformer(methodName));
}
@ -244,7 +244,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the method name is null
* @throws IllegalArgumentException if the paramTypes and args don't match
*/
public static <T> Predicate<T> invokerPredicate(String methodName, Class<?>[] paramTypes, Object[] args){
public static <T> Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args){
// reuse transformer as it has caching - this is lazy really, should have inner class here
return asPredicate(InvokerTransformer.<Object, Boolean>invokerTransformer(methodName, paramTypes, args));
}
@ -263,7 +263,7 @@ public class PredicateUtils {
* @return the <code>and</code> predicate
* @throws IllegalArgumentException if either predicate is null
*/
public static <T> Predicate<T> andPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) {
return AndPredicate.<T>andPredicate(predicate1, predicate2);
}
@ -281,7 +281,7 @@ public class PredicateUtils {
* @deprecated use {@link AllPredicate#allPredicate(Predicate...)} instead.
*/
@Deprecated
public static <T> Predicate<T> allPredicate(Predicate<? super T>... predicates) {
public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) {
return AllPredicate.allPredicate(predicates);
}
@ -297,7 +297,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates collection is null
* @throws IllegalArgumentException if any predicate in the collection is null
*/
public static <T> Predicate<T> allPredicate(Collection<? extends Predicate<T>> predicates) {
public static <T> Predicate<T> allPredicate(final Collection<? extends Predicate<T>> predicates) {
return AllPredicate.allPredicate(predicates);
}
@ -312,7 +312,7 @@ public class PredicateUtils {
* @return the <code>or</code> predicate
* @throws IllegalArgumentException if either predicate is null
*/
public static <T> Predicate<T> orPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) {
return OrPredicate.<T>orPredicate(predicate1, predicate2);
}
@ -328,7 +328,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates array is null
* @throws IllegalArgumentException if any predicate in the array is null
*/
public static <T> Predicate<T> anyPredicate(Predicate<? super T>... predicates) {
public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) {
return AnyPredicate.anyPredicate(predicates);
}
@ -344,7 +344,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates collection is null
* @throws IllegalArgumentException if any predicate in the collection is null
*/
public static <T> Predicate<T> anyPredicate(Collection<? extends Predicate<T>> predicates) {
public static <T> Predicate<T> anyPredicate(final Collection<? extends Predicate<T>> predicates) {
return AnyPredicate.anyPredicate(predicates);
}
@ -359,8 +359,9 @@ public class PredicateUtils {
* @return the <code>either</code> predicate
* @throws IllegalArgumentException if either predicate is null
*/
public static <T> Predicate<T> eitherPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
public static <T> Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) {
@SuppressWarnings("unchecked")
final
Predicate<T> onePredicate = PredicateUtils.<T>onePredicate(predicate1, predicate2);
return onePredicate;
}
@ -377,7 +378,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates array is null
* @throws IllegalArgumentException if any predicate in the array is null
*/
public static <T> Predicate<T> onePredicate(Predicate<? super T>... predicates) {
public static <T> Predicate<T> onePredicate(final Predicate<? super T>... predicates) {
return OnePredicate.onePredicate(predicates);
}
@ -393,7 +394,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates collection is null
* @throws IllegalArgumentException if any predicate in the collection is null
*/
public static <T> Predicate<T> onePredicate(Collection<Predicate<T>> predicates) {
public static <T> Predicate<T> onePredicate(final Collection<Predicate<T>> predicates) {
return OnePredicate.onePredicate(predicates);
}
@ -408,8 +409,9 @@ public class PredicateUtils {
* @return the <code>neither</code> predicate
* @throws IllegalArgumentException if either predicate is null
*/
public static <T> Predicate<T> neitherPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
public static <T> Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) {
@SuppressWarnings("unchecked")
final
Predicate<T> nonePredicate = PredicateUtils.<T>nonePredicate(predicate1, predicate2);
return nonePredicate;
}
@ -426,7 +428,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates array is null
* @throws IllegalArgumentException if any predicate in the array is null
*/
public static <T> Predicate<T> nonePredicate(Predicate<? super T>... predicates) {
public static <T> Predicate<T> nonePredicate(final Predicate<? super T>... predicates) {
return NonePredicate.nonePredicate(predicates);
}
@ -442,7 +444,7 @@ public class PredicateUtils {
* @throws IllegalArgumentException if the predicates collection is null
* @throws IllegalArgumentException if any predicate in the collection is null
*/
public static <T> Predicate<T> nonePredicate(Collection<? extends Predicate<T>> predicates) {
public static <T> Predicate<T> nonePredicate(final Collection<? extends Predicate<T>> predicates) {
return NonePredicate.nonePredicate(predicates);
}
@ -456,7 +458,7 @@ public class PredicateUtils {
* @return the <code>not</code> predicate
* @throws IllegalArgumentException if the predicate is null
*/
public static <T> Predicate<T> notPredicate(Predicate<? super T> predicate) {
public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) {
return NotPredicate.notPredicate(predicate);
}
@ -474,7 +476,7 @@ public class PredicateUtils {
* @return the transformer wrapping predicate
* @throws IllegalArgumentException if the transformer is null
*/
public static <T> Predicate<T> asPredicate(Transformer<? super T, Boolean> transformer) {
public static <T> Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer) {
return TransformerPredicate.transformerPredicate(transformer);
}
@ -492,7 +494,7 @@ public class PredicateUtils {
* @return the predicate
* @throws IllegalArgumentException if the predicate is null.
*/
public static <T> Predicate<T> nullIsExceptionPredicate(Predicate<? super T> predicate){
public static <T> Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate){
return NullIsExceptionPredicate.nullIsExceptionPredicate(predicate);
}
@ -507,7 +509,7 @@ public class PredicateUtils {
* @return the predicate
* @throws IllegalArgumentException if the predicate is null.
*/
public static <T> Predicate<T> nullIsFalsePredicate(Predicate<? super T> predicate){
public static <T> Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate){
return NullIsFalsePredicate.nullIsFalsePredicate(predicate);
}
@ -522,7 +524,7 @@ public class PredicateUtils {
* @return the predicate
* @throws IllegalArgumentException if the predicate is null.
*/
public static <T> Predicate<T> nullIsTruePredicate(Predicate<? super T> predicate){
public static <T> Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate){
return NullIsTruePredicate.nullIsTruePredicate(predicate);
}
@ -541,7 +543,7 @@ public class PredicateUtils {
* @since 3.1
*/
public static <T> Predicate<T> transformedPredicate(
Transformer<? super T, ? extends T> transformer, Predicate<? super T> predicate) {
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate) {
return TransformedPredicate.<T>transformedPredicate(transformer, predicate);
}

View File

@ -90,7 +90,7 @@ public class SetUtils {
* @param set the set, possibly <code>null</code>
* @return an empty set if the argument is <code>null</code>
*/
public static <T> Set<T> emptyIfNull(Set<T> set) {
public static <T> Set<T> emptyIfNull(final Set<T> set) {
return set == null ? Collections.<T>emptySet() : set;
}
@ -152,7 +152,7 @@ public class SetUtils {
}
int hashCode = 0;
for (T obj : set) {
for (final T obj : set) {
if (obj != null) {
hashCode += obj.hashCode();
}
@ -184,7 +184,7 @@ public class SetUtils {
* @return a synchronized set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
public static <E> Set<E> synchronizedSet(Set<E> set) {
public static <E> Set<E> synchronizedSet(final Set<E> set) {
return SynchronizedSet.synchronizedSet(set);
}
@ -198,7 +198,7 @@ public class SetUtils {
* @return an unmodifiable set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
public static <E> Set<E> unmodifiableSet(Set<E> set) {
public static <E> Set<E> unmodifiableSet(final Set<E> set) {
return UnmodifiableSet.unmodifiableSet(set);
}
@ -216,7 +216,7 @@ public class SetUtils {
* @return a predicated set backed by the given set
* @throws IllegalArgumentException if the Set or Predicate is null
*/
public static <E> Set<E> predicatedSet(Set<E> set, Predicate<? super E> predicate) {
public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) {
return PredicatedSet.predicatedSet(set, predicate);
}
@ -236,7 +236,7 @@ public class SetUtils {
* @return a transformed set backed by the given set
* @throws IllegalArgumentException if the Set or Transformer is null
*/
public static <E> Set<E> transformedSet(Set<E> set, Transformer<? super E, ? extends E> transformer) {
public static <E> Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer) {
return TransformedSet.transformingSet(set, transformer);
}
@ -252,7 +252,7 @@ public class SetUtils {
* @return an ordered set backed by the given set
* @throws IllegalArgumentException if the Set is null
*/
public static <E> Set<E> orderedSet(Set<E> set) {
public static <E> Set<E> orderedSet(final Set<E> set) {
return ListOrderedSet.listOrderedSet(set);
}
@ -280,7 +280,7 @@ public class SetUtils {
* @return a synchronized set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
public static <E> SortedSet<E> synchronizedSortedSet(SortedSet<E> set) {
public static <E> SortedSet<E> synchronizedSortedSet(final SortedSet<E> set) {
return SynchronizedSortedSet.synchronizedSortedSet(set);
}
@ -294,7 +294,7 @@ public class SetUtils {
* @return an unmodifiable set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
public static <E> SortedSet<E> unmodifiableSortedSet(SortedSet<E> set) {
public static <E> SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set) {
return UnmodifiableSortedSet.unmodifiableSortedSet(set);
}
@ -312,7 +312,7 @@ public class SetUtils {
* @return a predicated sorted set backed by the given sorted set
* @throws IllegalArgumentException if the Set or Predicate is null
*/
public static <E> SortedSet<E> predicatedSortedSet(SortedSet<E> set, Predicate<? super E> predicate) {
public static <E> SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate) {
return PredicatedSortedSet.predicatedSortedSet(set, predicate);
}
@ -332,8 +332,8 @@ public class SetUtils {
* @return a transformed set backed by the given set
* @throws IllegalArgumentException if the Set or Transformer is null
*/
public static <E> SortedSet<E> transformedSortedSet(SortedSet<E> set,
Transformer<? super E, ? extends E> transformer) {
public static <E> SortedSet<E> transformedSortedSet(final SortedSet<E> set,
final Transformer<? super E, ? extends E> transformer) {
return TransformedSortedSet.transformingSortedSet(set, transformer);
}

View File

@ -47,7 +47,7 @@ public class SplitMapUtils {
private static class WrappedGet<K, V> implements IterableMap<K, V>, Unmodifiable {
private final Get<K, V> get;
private WrappedGet(Get<K, V> get) {
private WrappedGet(final Get<K, V> get) {
this.get = get;
}
@ -55,11 +55,11 @@ public class SplitMapUtils {
throw new UnsupportedOperationException();
}
public boolean containsKey(Object key) {
public boolean containsKey(final Object key) {
return get.containsKey(key);
}
public boolean containsValue(Object value) {
public boolean containsValue(final Object value) {
return get.containsValue(value);
}
@ -68,14 +68,14 @@ public class SplitMapUtils {
}
@Override
public boolean equals(Object arg0) {
public boolean equals(final Object arg0) {
if (arg0 == this) {
return true;
}
return arg0 instanceof WrappedGet && ((WrappedGet<?, ?>) arg0).get.equals(this.get);
}
public V get(Object key) {
public V get(final Object key) {
return get.get(key);
}
@ -92,15 +92,15 @@ public class SplitMapUtils {
return UnmodifiableSet.unmodifiableSet(get.keySet());
}
public V put(K key, V value) {
public V put(final K key, final V value) {
throw new UnsupportedOperationException();
}
public void putAll(Map<? extends K, ? extends V> t) {
public void putAll(final Map<? extends K, ? extends V> t) {
throw new UnsupportedOperationException();
}
public V remove(Object key) {
public V remove(final Object key) {
return get.remove(key);
}
@ -126,7 +126,7 @@ public class SplitMapUtils {
private static class WrappedPut<K, V> implements Map<K, V>, Put<K, V> {
private final Put<K, V> put;
private WrappedPut(Put<K, V> put) {
private WrappedPut(final Put<K, V> put) {
this.put = put;
}
@ -134,11 +134,11 @@ public class SplitMapUtils {
put.clear();
}
public boolean containsKey(Object key) {
public boolean containsKey(final Object key) {
throw new UnsupportedOperationException();
}
public boolean containsValue(Object value) {
public boolean containsValue(final Object value) {
throw new UnsupportedOperationException();
}
@ -147,14 +147,14 @@ public class SplitMapUtils {
}
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
return obj instanceof WrappedPut && ((WrappedPut<?, ?>) obj).put.equals(this.put);
}
public V get(Object key) {
public V get(final Object key) {
throw new UnsupportedOperationException();
}
@ -172,15 +172,15 @@ public class SplitMapUtils {
}
@SuppressWarnings("unchecked")
public V put(K key, V value) {
public V put(final K key, final V value) {
return (V) put.put(key, value);
}
public void putAll(Map<? extends K, ? extends V> t) {
public void putAll(final Map<? extends K, ? extends V> t) {
put.putAll(t);
}
public V remove(Object key) {
public V remove(final Object key) {
throw new UnsupportedOperationException();
}
@ -204,7 +204,7 @@ public class SplitMapUtils {
* @return {@link IterableMap}
*/
@SuppressWarnings("unchecked")
public static <K, V> IterableMap<K, V> readableMap(Get<K, V> get) {
public static <K, V> IterableMap<K, V> readableMap(final Get<K, V> get) {
if (get == null) {
throw new IllegalArgumentException("Get must not be null");
}
@ -228,7 +228,7 @@ public class SplitMapUtils {
* @return {@link Map}
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> writableMap(Put<K, V> put) {
public static <K, V> Map<K, V> writableMap(final Put<K, V> put) {
if (put == null) {
throw new IllegalArgumentException("Put must not be null");
}

View File

@ -131,7 +131,7 @@ public class TransformerUtils {
* @param constantToReturn the constant object to return each time in the transformer
* @return the transformer.
*/
public static <I, O> Transformer<I, O> constantTransformer(O constantToReturn) {
public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) {
return ConstantTransformer.constantTransformer(constantToReturn);
}
@ -145,7 +145,7 @@ public class TransformerUtils {
* @return the transformer
* @throws IllegalArgumentException if the closure is null
*/
public static <T> Transformer<T, T> asTransformer(Closure<? super T> closure) {
public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) {
return ClosureTransformer.closureTransformer(closure);
}
@ -159,7 +159,7 @@ public class TransformerUtils {
* @return the transformer
* @throws IllegalArgumentException if the predicate is null
*/
public static <T> Transformer<T, Boolean> asTransformer(Predicate<? super T> predicate) {
public static <T> Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate) {
return PredicateTransformer.predicateTransformer(predicate);
}
@ -173,7 +173,7 @@ public class TransformerUtils {
* @return the transformer
* @throws IllegalArgumentException if the factory is null
*/
public static <I, O> Transformer<I, O> asTransformer(Factory<? extends O> factory) {
public static <I, O> Transformer<I, O> asTransformer(final Factory<? extends O> factory) {
return FactoryTransformer.factoryTransformer(factory);
}
@ -190,8 +190,8 @@ public class TransformerUtils {
*/
@SuppressWarnings("unchecked")
public static <T> Transformer<T, T> chainedTransformer(
Transformer<? super T, ? extends T> transformer1,
Transformer<? super T, ? extends T> transformer2) {
final Transformer<? super T, ? extends T> transformer1,
final Transformer<? super T, ? extends T> transformer2) {
return ChainedTransformer.<T> chainedTransformer(transformer1, transformer2);
}
@ -206,7 +206,7 @@ public class TransformerUtils {
* @throws IllegalArgumentException if the transformers array is null
* @throws IllegalArgumentException if any transformer in the array is null
*/
public static <T> Transformer<T, T> chainedTransformer(Transformer<? super T, ? extends T>[] transformers) {
public static <T> Transformer<T, T> chainedTransformer(final Transformer<? super T, ? extends T>[] transformers) {
return ChainedTransformer.chainedTransformer(transformers);
}
@ -223,7 +223,7 @@ public class TransformerUtils {
* @throws IllegalArgumentException if any transformer in the collection is null
*/
public static <T> Transformer<T, T> chainedTransformer(
Collection<? extends Transformer<T, T>> transformers) {
final Collection<? extends Transformer<T, T>> transformers) {
return ChainedTransformer.chainedTransformer(transformers);
}
@ -241,9 +241,9 @@ public class TransformerUtils {
* @throws IllegalArgumentException if either transformer is null
*/
@SuppressWarnings("unchecked")
public static <I, O> Transformer<I, O> switchTransformer(Predicate<? super I> predicate,
Transformer<? super I, ? extends O> trueTransformer,
Transformer<? super I, ? extends O> falseTransformer) {
public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer) {
return SwitchTransformer.switchTransformer(new Predicate[] { predicate },
new Transformer[] { trueTransformer }, falseTransformer);
}
@ -264,8 +264,8 @@ public class TransformerUtils {
* @throws IllegalArgumentException if any element in the arrays is null
* @throws IllegalArgumentException if the arrays are different sizes
*/
public static <I, O> Transformer<I, O> switchTransformer(Predicate<? super I>[] predicates,
Transformer<? super I, ? extends O>[] transformers) {
public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers) {
return SwitchTransformer.<I, O>switchTransformer(predicates, transformers, null);
}
@ -287,9 +287,9 @@ public class TransformerUtils {
* @throws IllegalArgumentException if any element in the arrays is null
* @throws IllegalArgumentException if the arrays are different sizes
*/
public static <I, O> Transformer<I, O> switchTransformer(Predicate<? super I>[] predicates,
Transformer<? super I, ? extends O>[] transformers,
Transformer<? super I, ? extends O> defaultTransformer) {
public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer) {
return SwitchTransformer.<I, O>switchTransformer(predicates, transformers, defaultTransformer);
}
@ -315,7 +315,7 @@ public class TransformerUtils {
* @throws ClassCastException if the map elements are of the wrong type
*/
public static <I, O> Transformer<I, O> switchTransformer(
Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers) {
final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers) {
return SwitchTransformer.<I, O>switchTransformer(predicatesAndTransformers);
}
@ -337,18 +337,18 @@ public class TransformerUtils {
* @throws IllegalArgumentException if any transformer in the map is null
*/
@SuppressWarnings("unchecked")
public static <I, O> Transformer<I, O> switchMapTransformer(Map<I, Transformer<I, O>> objectsAndTransformers) {
public static <I, O> Transformer<I, O> switchMapTransformer(final Map<I, Transformer<I, O>> objectsAndTransformers) {
Transformer<? super I, ? extends O>[] trs = null;
Predicate<I>[] preds = null;
if (objectsAndTransformers == null) {
throw new IllegalArgumentException("The object and transformer map must not be null");
}
Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null);
int size = objectsAndTransformers.size();
final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null);
final int size = objectsAndTransformers.size();
trs = new Transformer[size];
preds = new Predicate[size];
int i = 0;
for (Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) {
for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) {
preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey());
trs[i++] = entry.getValue();
}
@ -379,7 +379,7 @@ public class TransformerUtils {
* @throws IllegalArgumentException if the paramTypes and args don't match
*/
public static <T> Transformer<Class<? extends T>, T> instantiateTransformer(
Class<?>[] paramTypes, Object[] args) {
final Class<?>[] paramTypes, final Object[] args) {
return InstantiateTransformer.<T>instantiateTransformer(paramTypes, args);
}
@ -392,7 +392,7 @@ public class TransformerUtils {
* @param map the map to use to transform the objects
* @return the transformer, or a {@link ConstantTransformer#NULL_INSTANCE} if the {@code map} is {@code null}
*/
public static <I, O> Transformer<I, O> mapTransformer(Map<? super I, ? extends O> map) {
public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) {
return MapTransformer.mapTransformer(map);
}
@ -411,7 +411,7 @@ public class TransformerUtils {
* @return the transformer
* @throws IllegalArgumentException if the methodName is null.
*/
public static <I, O> Transformer<I, O> invokerTransformer(String methodName){
public static <I, O> Transformer<I, O> invokerTransformer(final String methodName){
return InvokerTransformer.<I, O>invokerTransformer(methodName, null, null);
}
@ -429,7 +429,7 @@ public class TransformerUtils {
* @throws IllegalArgumentException if the method name is null
* @throws IllegalArgumentException if the paramTypes and args don't match
*/
public static <I, O> Transformer<I, O> invokerTransformer(String methodName, Class<?>[] paramTypes, Object[] args){
public static <I, O> Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes, final Object[] args){
return InvokerTransformer.<I, O>invokerTransformer(methodName, paramTypes, args);
}

View File

@ -37,7 +37,7 @@ public class TrieUtils {
*
* @see Collections#synchronizedMap(Map)
*/
public static <K, V> Trie<K, V> synchronizedTrie(Trie<K, V> trie) {
public static <K, V> Trie<K, V> synchronizedTrie(final Trie<K, V> trie) {
return SynchronizedTrie.synchronizedTrie(trie);
}
@ -46,7 +46,7 @@ public class TrieUtils {
*
* @see Collections#unmodifiableMap(Map)
*/
public static <K, V> Trie<K, V> unmodifiableTrie(Trie<K, V> trie) {
public static <K, V> Trie<K, V> unmodifiableTrie(final Trie<K, V> trie) {
return UnmodifiableTrie.unmodifiableTrie(trie);
}

View File

@ -49,7 +49,7 @@ public abstract class AbstractBagDecorator<E>
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
protected AbstractBagDecorator(Bag<E> bag) {
protected AbstractBagDecorator(final Bag<E> bag) {
super(bag);
}
@ -65,15 +65,15 @@ public abstract class AbstractBagDecorator<E>
//-----------------------------------------------------------------------
public int getCount(Object object) {
public int getCount(final Object object) {
return decorated().getCount(object);
}
public boolean add(E object, int count) {
public boolean add(final E object, final int count) {
return decorated().add(object, count);
}
public boolean remove(Object object, int count) {
public boolean remove(final Object object, final int count) {
return decorated().remove(object, count);
}

View File

@ -65,7 +65,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
*
* @param map the map to assign
*/
protected AbstractMapBag(Map<E, MutableInteger> map) {
protected AbstractMapBag(final Map<E, MutableInteger> map) {
super();
this.map = map;
}
@ -106,8 +106,8 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param object the object to search for
* @return the number of occurrences of the object, zero if not found
*/
public int getCount(Object object) {
MutableInteger count = map.get(object);
public int getCount(final Object object) {
final MutableInteger count = map.get(object);
if (count != null) {
return count.value;
}
@ -122,7 +122,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param object the object to search for
* @return true if the bag contains the given element
*/
public boolean contains(Object object) {
public boolean contains(final Object object) {
return map.containsKey(object);
}
@ -132,7 +132,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param coll the collection to check against
* @return <code>true</code> if the Bag contains all the collection
*/
public boolean containsAll(Collection<?> coll) {
public boolean containsAll(final Collection<?> coll) {
if (coll instanceof Bag) {
return containsAll((Bag<?>) coll);
}
@ -146,12 +146,12 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param other the bag to check against
* @return <code>true</code> if the Bag contains all the collection
*/
boolean containsAll(Bag<?> other) {
boolean containsAll(final Bag<?> other) {
boolean result = true;
Iterator<?> it = other.uniqueSet().iterator();
final Iterator<?> it = other.uniqueSet().iterator();
while (it.hasNext()) {
Object current = it.next();
boolean contains = getCount(current) >= other.getCount(current);
final Object current = it.next();
final boolean contains = getCount(current) >= other.getCount(current);
result = result && contains;
}
return result;
@ -184,7 +184,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
*
* @param parent the parent bag
*/
public BagIterator(AbstractMapBag<E> parent) {
public BagIterator(final AbstractMapBag<E> parent) {
this.parent = parent;
this.entryIterator = parent.map.entrySet().iterator();
this.current = null;
@ -219,7 +219,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
if (canRemove == false) {
throw new IllegalStateException();
}
MutableInteger mut = current.getValue();
final MutableInteger mut = current.getValue();
if (mut.value > 1) {
mut.value--;
} else {
@ -239,7 +239,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @return <code>true</code> if the object was not already in the
* <code>uniqueSet</code>
*/
public boolean add(E object) {
public boolean add(final E object) {
return add(object, 1);
}
@ -251,10 +251,10 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @return <code>true</code> if the object was not already in the
* <code>uniqueSet</code>
*/
public boolean add(E object, int nCopies) {
public boolean add(final E object, final int nCopies) {
modCount++;
if (nCopies > 0) {
MutableInteger mut = map.get(object);
final MutableInteger mut = map.get(object);
size += nCopies;
if (mut == null) {
map.put(object, new MutableInteger(nCopies));
@ -272,11 +272,11 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param coll the collection to add
* @return <code>true</code> if this call changed the bag
*/
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
boolean changed = false;
Iterator<? extends E> i = coll.iterator();
final Iterator<? extends E> i = coll.iterator();
while (i.hasNext()) {
boolean added = add(i.next());
final boolean added = add(i.next());
changed = changed || added;
}
return changed;
@ -298,8 +298,8 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param object the object to remove
* @return true if the bag changed
*/
public boolean remove(Object object) {
MutableInteger mut = map.get(object);
public boolean remove(final Object object) {
final MutableInteger mut = map.get(object);
if (mut == null) {
return false;
}
@ -316,8 +316,8 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param nCopies the number of copies to remove
* @return true if the bag changed
*/
public boolean remove(Object object, int nCopies) {
MutableInteger mut = map.get(object);
public boolean remove(final Object object, final int nCopies) {
final MutableInteger mut = map.get(object);
if (mut == null) {
return false;
}
@ -342,12 +342,12 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param coll the collection to use
* @return true if the bag changed
*/
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
boolean result = false;
if (coll != null) {
Iterator<?> i = coll.iterator();
final Iterator<?> i = coll.iterator();
while (i.hasNext()) {
boolean changed = remove(i.next(), 1);
final boolean changed = remove(i.next(), 1);
result = result || changed;
}
}
@ -361,7 +361,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param coll the collection to retain
* @return true if this call changed the collection
*/
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
if (coll instanceof Bag) {
return retainAll((Bag<?>) coll);
}
@ -376,14 +376,14 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param other the bag to retain
* @return <code>true</code> if this call changed the collection
*/
boolean retainAll(Bag<?> other) {
boolean retainAll(final Bag<?> other) {
boolean result = false;
Bag<E> excess = new HashBag<E>();
Iterator<E> i = uniqueSet().iterator();
final Bag<E> excess = new HashBag<E>();
final Iterator<E> i = uniqueSet().iterator();
while (i.hasNext()) {
E current = i.next();
int myCount = getCount(current);
int otherCount = other.getCount(current);
final E current = i.next();
final int myCount = getCount(current);
final int otherCount = other.getCount(current);
if (1 <= otherCount && otherCount <= myCount) {
excess.add(current, myCount - otherCount);
} else {
@ -408,12 +408,12 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* Constructor.
* @param value the initial value
*/
MutableInteger(int value) {
MutableInteger(final int value) {
this.value = value;
}
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (obj instanceof MutableInteger == false) {
return false;
}
@ -433,11 +433,11 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @return an array of all of this bag's elements
*/
public Object[] toArray() {
Object[] result = new Object[size()];
final Object[] result = new Object[size()];
int i = 0;
Iterator<E> it = map.keySet().iterator();
final Iterator<E> it = map.keySet().iterator();
while (it.hasNext()) {
E current = it.next();
final E current = it.next();
for (int index = getCount(current); index > 0; index--) {
result[i++] = current;
}
@ -454,15 +454,15 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
*/
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] array) {
int size = size();
final int size = size();
if (array.length < size) {
array = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
}
int i = 0;
Iterator<E> it = map.keySet().iterator();
final Iterator<E> it = map.keySet().iterator();
while (it.hasNext()) {
E current = it.next();
final E current = it.next();
for (int index = getCount(current); index > 0; index--) {
array[i++] = (T) current;
}
@ -491,9 +491,9 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @param out the output stream
* @throws IOException any of the usual I/O related exceptions
*/
protected void doWriteObject(ObjectOutputStream out) throws IOException {
protected void doWriteObject(final ObjectOutputStream out) throws IOException {
out.writeInt(map.size());
for (Entry<E, MutableInteger> entry : map.entrySet()) {
for (final Entry<E, MutableInteger> entry : map.entrySet()) {
out.writeObject(entry.getKey());
out.writeInt(entry.getValue().value);
}
@ -507,14 +507,15 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @throws ClassNotFoundException if the stream contains an object which class can not be loaded
* @throws ClassCastException if the stream does not contain the correct objects
*/
protected void doReadObject(Map<E, MutableInteger> map, ObjectInputStream in)
protected void doReadObject(final Map<E, MutableInteger> map, final ObjectInputStream in)
throws IOException, ClassNotFoundException {
this.map = map;
int entrySize = in.readInt();
final int entrySize = in.readInt();
for (int i = 0; i < entrySize; i++) {
@SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect
final
E obj = (E) in.readObject();
int count = in.readInt();
final int count = in.readInt();
map.put(obj, new MutableInteger(count));
size += count;
}
@ -529,18 +530,18 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
* @return true if equal
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
if (object == this) {
return true;
}
if (object instanceof Bag == false) {
return false;
}
Bag<?> other = (Bag<?>) object;
final Bag<?> other = (Bag<?>) object;
if (other.size() != size()) {
return false;
}
for (E element : map.keySet()) {
for (final E element : map.keySet()) {
if (other.getCount(element) != getCount(element)) {
return false;
}
@ -560,9 +561,9 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
@Override
public int hashCode() {
int total = 0;
for (Entry<E, MutableInteger> entry : map.entrySet()) {
E element = entry.getKey();
MutableInteger count = entry.getValue();
for (final Entry<E, MutableInteger> entry : map.entrySet()) {
final E element = entry.getKey();
final MutableInteger count = entry.getValue();
total += (element == null ? 0 : element.hashCode()) ^ count.value;
}
return total;
@ -578,12 +579,12 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
if (size() == 0) {
return "[]";
}
StringBuilder buf = new StringBuilder();
final StringBuilder buf = new StringBuilder();
buf.append('[');
Iterator<E> it = uniqueSet().iterator();
final Iterator<E> it = uniqueSet().iterator();
while (it.hasNext()) {
Object current = it.next();
int count = getCount(current);
final Object current = it.next();
final int count = getCount(current);
buf.append(count);
buf.append(':');
buf.append(current);

View File

@ -48,7 +48,7 @@ public abstract class AbstractSortedBagDecorator<E>
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
protected AbstractSortedBagDecorator(SortedBag<E> bag) {
protected AbstractSortedBagDecorator(final SortedBag<E> bag) {
super(bag);
}

View File

@ -55,7 +55,7 @@ public class HashBag<E> extends AbstractMapBag<E> implements Bag<E>, Serializabl
*
* @param coll a collection to copy into this bag
*/
public HashBag(Collection<? extends E> coll) {
public HashBag(final Collection<? extends E> coll) {
this();
addAll(coll);
}
@ -64,7 +64,7 @@ public class HashBag<E> extends AbstractMapBag<E> implements Bag<E>, Serializabl
/**
* Write the bag out using a custom routine.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
super.doWriteObject(out);
}
@ -72,7 +72,7 @@ public class HashBag<E> extends AbstractMapBag<E> implements Bag<E>, Serializabl
/**
* Read the bag in using a custom routine.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
super.doReadObject(new HashMap<E, MutableInteger>(), in);
}

View File

@ -56,7 +56,7 @@ public class PredicatedBag<E> extends PredicatedCollection<E> implements Bag<E>
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
public static <E> PredicatedBag<E> predicatedBag(Bag<E> bag, Predicate<? super E> predicate) {
public static <E> PredicatedBag<E> predicatedBag(final Bag<E> bag, final Predicate<? super E> predicate) {
return new PredicatedBag<E>(bag, predicate);
}
@ -72,7 +72,7 @@ public class PredicatedBag<E> extends PredicatedCollection<E> implements Bag<E>
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
protected PredicatedBag(Bag<E> bag, Predicate<? super E> predicate) {
protected PredicatedBag(final Bag<E> bag, final Predicate<? super E> predicate) {
super(bag, predicate);
}
@ -88,12 +88,12 @@ public class PredicatedBag<E> extends PredicatedCollection<E> implements Bag<E>
//-----------------------------------------------------------------------
public boolean add(E object, int count) {
public boolean add(final E object, final int count) {
validate(object);
return decorated().add(object, count);
}
public boolean remove(Object object, int count) {
public boolean remove(final Object object, final int count) {
return decorated().remove(object, count);
}
@ -101,7 +101,7 @@ public class PredicatedBag<E> extends PredicatedCollection<E> implements Bag<E>
return decorated().uniqueSet();
}
public int getCount(Object object) {
public int getCount(final Object object) {
return decorated().getCount(object);
}

View File

@ -55,7 +55,7 @@ public class PredicatedSortedBag<E> extends PredicatedBag<E> implements SortedBa
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
public static <E> PredicatedSortedBag<E> predicatedSortedBag(SortedBag<E> bag, Predicate<? super E> predicate) {
public static <E> PredicatedSortedBag<E> predicatedSortedBag(final SortedBag<E> bag, final Predicate<? super E> predicate) {
return new PredicatedSortedBag<E>(bag, predicate);
}
@ -70,7 +70,7 @@ public class PredicatedSortedBag<E> extends PredicatedBag<E> implements SortedBa
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
protected PredicatedSortedBag(SortedBag<E> bag, Predicate<? super E> predicate) {
protected PredicatedSortedBag(final SortedBag<E> bag, final Predicate<? super E> predicate) {
super(bag, predicate);
}

View File

@ -47,7 +47,7 @@ public class SynchronizedBag<E> extends SynchronizedCollection<E> implements Bag
* @return a new synchronized Bag
* @throws IllegalArgumentException if bag is null
*/
public static <E> SynchronizedBag<E> synchronizedBag(Bag<E> bag) {
public static <E> SynchronizedBag<E> synchronizedBag(final Bag<E> bag) {
return new SynchronizedBag<E>(bag);
}
@ -58,7 +58,7 @@ public class SynchronizedBag<E> extends SynchronizedCollection<E> implements Bag
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
protected SynchronizedBag(Bag<E> bag) {
protected SynchronizedBag(final Bag<E> bag) {
super(bag);
}
@ -69,7 +69,7 @@ public class SynchronizedBag<E> extends SynchronizedCollection<E> implements Bag
* @param lock the lock to use, must not be null
* @throws IllegalArgumentException if bag is null
*/
protected SynchronizedBag(Bag<E> bag, Object lock) {
protected SynchronizedBag(final Bag<E> bag, final Object lock) {
super(bag, lock);
}
@ -84,13 +84,13 @@ public class SynchronizedBag<E> extends SynchronizedCollection<E> implements Bag
//-----------------------------------------------------------------------
public boolean add(E object, int count) {
public boolean add(final E object, final int count) {
synchronized (lock) {
return getBag().add(object, count);
}
}
public boolean remove(Object object, int count) {
public boolean remove(final Object object, final int count) {
synchronized (lock) {
return getBag().remove(object, count);
}
@ -98,12 +98,12 @@ public class SynchronizedBag<E> extends SynchronizedCollection<E> implements Bag
public Set<E> uniqueSet() {
synchronized (lock) {
Set<E> set = getBag().uniqueSet();
final Set<E> set = getBag().uniqueSet();
return new SynchronizedBagSet(set, lock);
}
}
public int getCount(Object object) {
public int getCount(final Object object) {
synchronized (lock) {
return getBag().getCount(object);
}
@ -122,7 +122,7 @@ public class SynchronizedBag<E> extends SynchronizedCollection<E> implements Bag
* @param set the set to decorate
* @param lock the lock to use, shared with the bag
*/
SynchronizedBagSet(Set<E> set, Object lock) {
SynchronizedBagSet(final Set<E> set, final Object lock) {
super(set, lock);
}
}

View File

@ -46,7 +46,7 @@ public class SynchronizedSortedBag<E> extends SynchronizedBag<E> implements Sort
* @return a new synchronized SortedBag
* @throws IllegalArgumentException if bag is null
*/
public static <E> SynchronizedSortedBag<E> synchronizedSortedBag(SortedBag<E> bag) {
public static <E> SynchronizedSortedBag<E> synchronizedSortedBag(final SortedBag<E> bag) {
return new SynchronizedSortedBag<E>(bag);
}
@ -57,7 +57,7 @@ public class SynchronizedSortedBag<E> extends SynchronizedBag<E> implements Sort
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
protected SynchronizedSortedBag(SortedBag<E> bag) {
protected SynchronizedSortedBag(final SortedBag<E> bag) {
super(bag);
}
@ -68,7 +68,7 @@ public class SynchronizedSortedBag<E> extends SynchronizedBag<E> implements Sort
* @param lock the lock to use, must not be null
* @throws IllegalArgumentException if bag is null
*/
protected SynchronizedSortedBag(Bag<E> bag, Object lock) {
protected SynchronizedSortedBag(final Bag<E> bag, final Object lock) {
super(bag, lock);
}

View File

@ -53,7 +53,7 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
* @return a new transformed Bag
* @throws IllegalArgumentException if bag or transformer is null
*/
public static <E> Bag<E> transformingBag(Bag<E> bag, Transformer<? super E, ? extends E> transformer) {
public static <E> Bag<E> transformingBag(final Bag<E> bag, final Transformer<? super E, ? extends E> transformer) {
return new TransformedBag<E>(bag, transformer);
}
@ -72,13 +72,14 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
* @throws IllegalArgumentException if bag or transformer is null
* @since 3.3
*/
public static <E> Bag<E> transformedBag(Bag<E> bag, Transformer<? super E, ? extends E> transformer) {
TransformedBag<E> decorated = new TransformedBag<E>(bag, transformer);
public static <E> Bag<E> transformedBag(final Bag<E> bag, final Transformer<? super E, ? extends E> transformer) {
final TransformedBag<E> decorated = new TransformedBag<E>(bag, transformer);
if (transformer != null && bag != null && bag.size() > 0) {
@SuppressWarnings("unchecked") // Bag is of type E
final
E[] values = (E[]) bag.toArray();
bag.clear();
for (E value : values) {
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
}
@ -96,7 +97,7 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if bag or transformer is null
*/
protected TransformedBag(Bag<E> bag, Transformer<? super E, ? extends E> transformer) {
protected TransformedBag(final Bag<E> bag, final Transformer<? super E, ? extends E> transformer) {
super(bag, transformer);
}
@ -111,22 +112,22 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
//-----------------------------------------------------------------------
public int getCount(Object object) {
public int getCount(final Object object) {
return getBag().getCount(object);
}
public boolean remove(Object object, int nCopies) {
public boolean remove(final Object object, final int nCopies) {
return getBag().remove(object, nCopies);
}
//-----------------------------------------------------------------------
public boolean add(E object, int nCopies) {
public boolean add(final E object, final int nCopies) {
return getBag().add(transform(object), nCopies);
}
public Set<E> uniqueSet() {
Set<E> set = getBag().uniqueSet();
final Set<E> set = getBag().uniqueSet();
return TransformedSet.<E>transformingSet(set, transformer);
}

View File

@ -51,8 +51,8 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
* @return a new transformed SortedBag
* @throws IllegalArgumentException if bag or transformer is null
*/
public static <E> TransformedSortedBag<E> transformingSortedBag(SortedBag<E> bag,
Transformer<? super E, ? extends E> transformer) {
public static <E> TransformedSortedBag<E> transformingSortedBag(final SortedBag<E> bag,
final Transformer<? super E, ? extends E> transformer) {
return new TransformedSortedBag<E>(bag, transformer);
}
@ -71,14 +71,15 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
* @throws IllegalArgumentException if bag or transformer is null
* @since 3.3
*/
public static <E> TransformedSortedBag<E> transformedSortedBag(SortedBag<E> bag,
Transformer<? super E, ? extends E> transformer) {
TransformedSortedBag<E> decorated = new TransformedSortedBag<E>(bag, transformer);
public static <E> TransformedSortedBag<E> transformedSortedBag(final SortedBag<E> bag,
final Transformer<? super E, ? extends E> transformer) {
final TransformedSortedBag<E> decorated = new TransformedSortedBag<E>(bag, transformer);
if (transformer != null && bag != null && bag.size() > 0) {
@SuppressWarnings("unchecked") // bag is type E
final
E[] values = (E[]) bag.toArray();
bag.clear();
for (E value : values) {
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
}
@ -96,7 +97,7 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if bag or transformer is null
*/
protected TransformedSortedBag(SortedBag<E> bag, Transformer<? super E, ? extends E> transformer) {
protected TransformedSortedBag(final SortedBag<E> bag, final Transformer<? super E, ? extends E> transformer) {
super(bag, transformer);
}

View File

@ -61,7 +61,7 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria
*
* @param comparator the comparator to use
*/
public TreeBag(Comparator<? super E> comparator) {
public TreeBag(final Comparator<? super E> comparator) {
super(new TreeMap<E, MutableInteger>(comparator));
}
@ -71,7 +71,7 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria
*
* @param coll the collection to copy into the bag
*/
public TreeBag(Collection<? extends E> coll) {
public TreeBag(final Collection<? extends E> coll) {
this();
addAll(coll);
}
@ -84,7 +84,7 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria
* {@link Comparable} and the {@link TreeBag} is using natural ordering
*/
@Override
public boolean add(E object) {
public boolean add(final E object) {
if(comparator() == null && !(object instanceof Comparable)) {
throw new IllegalArgumentException("Objects of type " + object.getClass() + " cannot be added to " +
"a naturally ordered TreeBag as it does not implement Comparable");
@ -115,7 +115,7 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria
/**
* Write the bag out using a custom routine.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(comparator());
super.doWriteObject(out);
@ -124,9 +124,10 @@ public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Seria
/**
* Read the bag in using a custom routine.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
@SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect
final
Comparator<? super E> comp = (Comparator<? super E>) in.readObject();
super.doReadObject(new TreeMap<E, MutableInteger>(comp), in);
}

View File

@ -55,7 +55,7 @@ public final class UnmodifiableBag<E>
* @return an unmodifiable Bag
* @throws IllegalArgumentException if bag is null
*/
public static <E> Bag<E> unmodifiableBag(Bag<E> bag) {
public static <E> Bag<E> unmodifiableBag(final Bag<E> bag) {
if (bag instanceof Unmodifiable) {
return bag;
}
@ -69,7 +69,7 @@ public final class UnmodifiableBag<E>
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
private UnmodifiableBag(Bag<E> bag) {
private UnmodifiableBag(final Bag<E> bag) {
super(bag);
}
@ -80,7 +80,7 @@ public final class UnmodifiableBag<E>
* @param out the output stream
* @throws IOException
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(collection);
}
@ -93,7 +93,7 @@ public final class UnmodifiableBag<E>
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
collection = (Collection<E>) in.readObject();
}
@ -106,12 +106,12 @@ public final class UnmodifiableBag<E>
}
@Override
public boolean add(E object) {
public boolean add(final E object) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@ -121,34 +121,34 @@ public final class UnmodifiableBag<E>
}
@Override
public boolean remove(Object object) {
public boolean remove(final Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
@Override
public boolean add(E object, int count) {
public boolean add(final E object, final int count) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object object, int count) {
public boolean remove(final Object object, final int count) {
throw new UnsupportedOperationException();
}
@Override
public Set<E> uniqueSet() {
Set<E> set = decorated().uniqueSet();
final Set<E> set = decorated().uniqueSet();
return UnmodifiableSet.<E> unmodifiableSet(set);
}

View File

@ -55,7 +55,7 @@ public final class UnmodifiableSortedBag<E>
* @return an unmodifiable SortedBag
* @throws IllegalArgumentException if bag is null
*/
public static <E> SortedBag<E> unmodifiableSortedBag(SortedBag<E> bag) {
public static <E> SortedBag<E> unmodifiableSortedBag(final SortedBag<E> bag) {
if (bag instanceof Unmodifiable) {
return bag;
}
@ -69,7 +69,7 @@ public final class UnmodifiableSortedBag<E>
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
private UnmodifiableSortedBag(SortedBag<E> bag) {
private UnmodifiableSortedBag(final SortedBag<E> bag) {
super(bag);
}
@ -80,7 +80,7 @@ public final class UnmodifiableSortedBag<E>
* @param out the output stream
* @throws IOException
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(collection);
}
@ -93,7 +93,7 @@ public final class UnmodifiableSortedBag<E>
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
collection = (Collection<E>) in.readObject();
}
@ -105,12 +105,12 @@ public final class UnmodifiableSortedBag<E>
}
@Override
public boolean add(E object) {
public boolean add(final E object) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@ -120,34 +120,34 @@ public final class UnmodifiableSortedBag<E>
}
@Override
public boolean remove(Object object) {
public boolean remove(final Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
@Override
public boolean add(E object, int count) {
public boolean add(final E object, final int count) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object object, int count) {
public boolean remove(final Object object, final int count) {
throw new UnsupportedOperationException();
}
@Override
public Set<E> uniqueSet() {
Set<E> set = decorated().uniqueSet();
final Set<E> set = decorated().uniqueSet();
return UnmodifiableSet.unmodifiableSet(set);
}

View File

@ -44,7 +44,7 @@ public abstract class AbstractBidiMapDecorator<K, V>
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected AbstractBidiMapDecorator(BidiMap<K, V> map) {
protected AbstractBidiMapDecorator(final BidiMap<K, V> map) {
super(map);
}
@ -64,11 +64,11 @@ public abstract class AbstractBidiMapDecorator<K, V>
return decorated().mapIterator();
}
public K getKey(Object value) {
public K getKey(final Object value) {
return decorated().getKey(value);
}
public K removeValue(Object value) {
public K removeValue(final Object value) {
return decorated().removeValue(value);
}

View File

@ -96,7 +96,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param reverseMap the reverse direction map
* @since 3.1
*/
protected AbstractDualBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap) {
protected AbstractDualBidiMap(final Map<K, V> normalMap, final Map<V, K> reverseMap) {
super();
this.normalMap = normalMap;
this.reverseMap = reverseMap;
@ -110,7 +110,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param reverseMap the reverse direction map
* @param inverseBidiMap the inverse BidiMap
*/
protected AbstractDualBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap, BidiMap<V, K> inverseBidiMap) {
protected AbstractDualBidiMap(final Map<K, V> normalMap, final Map<V, K> reverseMap, final BidiMap<V, K> inverseBidiMap) {
super();
this.normalMap = normalMap;
this.reverseMap = reverseMap;
@ -130,7 +130,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
// Map delegation
//-----------------------------------------------------------------------
public V get(Object key) {
public V get(final Object key) {
return normalMap.get(key);
}
@ -142,12 +142,12 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
return normalMap.isEmpty();
}
public boolean containsKey(Object key) {
public boolean containsKey(final Object key) {
return normalMap.containsKey(key);
}
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
return normalMap.equals(obj);
}
@ -164,7 +164,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
// BidiMap changes
//-----------------------------------------------------------------------
public V put(K key, V value) {
public V put(final K key, final V value) {
if (normalMap.containsKey(key)) {
reverseMap.remove(normalMap.get(key));
}
@ -176,13 +176,13 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
return obj;
}
public void putAll(Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
public void putAll(final Map<? extends K, ? extends V> map) {
for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
public V remove(Object key) {
public V remove(final Object key) {
V value = null;
if (normalMap.containsKey(key)) {
value = normalMap.remove(key);
@ -196,7 +196,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
reverseMap.clear();
}
public boolean containsValue(Object value) {
public boolean containsValue(final Object value) {
return reverseMap.containsKey(value);
}
@ -217,11 +217,11 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
return new BidiMapIterator<K, V>(this);
}
public K getKey(Object value) {
public K getKey(final Object value) {
return reverseMap.get(value);
}
public K removeValue(Object value) {
public K removeValue(final Object value) {
K key = null;
if (reverseMap.containsKey(value)) {
key = reverseMap.remove(value);
@ -260,7 +260,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param iterator the iterator to decorate
* @return the keySet iterator
*/
protected Iterator<K> createKeySetIterator(Iterator<K> iterator) {
protected Iterator<K> createKeySetIterator(final Iterator<K> iterator) {
return new KeySetIterator<K>(iterator, this);
}
@ -285,7 +285,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param iterator the iterator to decorate
* @return the values iterator
*/
protected Iterator<V> createValuesIterator(Iterator<V> iterator) {
protected Iterator<V> createValuesIterator(final Iterator<V> iterator) {
return new ValuesIterator<V>(iterator, this);
}
@ -314,7 +314,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param iterator the iterator to decorate
* @return the entrySet iterator
*/
protected Iterator<Map.Entry<K, V>> createEntrySetIterator(Iterator<Map.Entry<K, V>> iterator) {
protected Iterator<Map.Entry<K, V>> createEntrySetIterator(final Iterator<Map.Entry<K, V>> iterator) {
return new EntrySetIterator<K, V>(iterator, this);
}
@ -334,13 +334,13 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param coll the collection view being decorated
* @param parent the parent BidiMap
*/
protected View(Collection<E> coll, AbstractDualBidiMap<K, V> parent) {
protected View(final Collection<E> coll, final AbstractDualBidiMap<K, V> parent) {
super(coll);
this.parent = parent;
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
if (parent.isEmpty() || coll.isEmpty()) {
return false;
}
@ -353,7 +353,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
if (parent.isEmpty()) {
return false;
}
@ -362,7 +362,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
return true;
}
boolean modified = false;
Iterator<E> it = iterator();
final Iterator<E> it = iterator();
while (it.hasNext()) {
if (coll.contains(it.next()) == false) {
it.remove();
@ -393,7 +393,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param parent the parent BidiMap
*/
@SuppressWarnings("unchecked")
protected KeySet(AbstractDualBidiMap<K, ?> parent) {
protected KeySet(final AbstractDualBidiMap<K, ?> parent) {
super(parent.normalMap.keySet(), (AbstractDualBidiMap<K, Object>) parent);
}
@ -403,14 +403,14 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
}
@Override
public boolean contains(Object key) {
public boolean contains(final Object key) {
return parent.normalMap.containsKey(key);
}
@Override
public boolean remove(Object key) {
public boolean remove(final Object key) {
if (parent.normalMap.containsKey(key)) {
Object value = parent.normalMap.remove(key);
final Object value = parent.normalMap.remove(key);
parent.reverseMap.remove(value);
return true;
}
@ -437,7 +437,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param iterator the iterator to decorate
* @param parent the parent map
*/
protected KeySetIterator(Iterator<K> iterator, AbstractDualBidiMap<K, ?> parent) {
protected KeySetIterator(final Iterator<K> iterator, final AbstractDualBidiMap<K, ?> parent) {
super(iterator);
this.parent = parent;
}
@ -454,7 +454,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
if (canRemove == false) {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
}
Object value = parent.normalMap.get(lastKey);
final Object value = parent.normalMap.get(lastKey);
super.remove();
parent.reverseMap.remove(value);
lastKey = null;
@ -477,7 +477,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param parent the parent BidiMap
*/
@SuppressWarnings("unchecked")
protected Values(AbstractDualBidiMap<?, V> parent) {
protected Values(final AbstractDualBidiMap<?, V> parent) {
super(parent.normalMap.values(), (AbstractDualBidiMap<Object, V>) parent);
}
@ -487,14 +487,14 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
}
@Override
public boolean contains(Object value) {
public boolean contains(final Object value) {
return parent.reverseMap.containsKey(value);
}
@Override
public boolean remove(Object value) {
public boolean remove(final Object value) {
if (parent.reverseMap.containsKey(value)) {
Object key = parent.reverseMap.remove(value);
final Object key = parent.reverseMap.remove(value);
parent.normalMap.remove(key);
return true;
}
@ -522,7 +522,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param parent the parent map
*/
@SuppressWarnings("unchecked")
protected ValuesIterator(Iterator<V> iterator, AbstractDualBidiMap<?, V> parent) {
protected ValuesIterator(final Iterator<V> iterator, final AbstractDualBidiMap<?, V> parent) {
super(iterator);
this.parent = (AbstractDualBidiMap<Object, V>) parent;
}
@ -560,7 +560,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
*
* @param parent the parent BidiMap
*/
protected EntrySet(AbstractDualBidiMap<K, V> parent) {
protected EntrySet(final AbstractDualBidiMap<K, V> parent) {
super(parent.normalMap.entrySet(), parent);
}
@ -570,14 +570,14 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
}
@Override
public boolean remove(Object obj) {
public boolean remove(final Object obj) {
if (obj instanceof Map.Entry == false) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
Object key = entry.getKey();
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
final Object key = entry.getKey();
if (parent.containsKey(key)) {
V value = parent.normalMap.get(key);
final V value = parent.normalMap.get(key);
if (value == null ? entry.getValue() == null : value.equals(entry.getValue())) {
parent.normalMap.remove(key);
parent.reverseMap.remove(value);
@ -607,7 +607,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param iterator the iterator to decorate
* @param parent the parent map
*/
protected EntrySetIterator(Iterator<Map.Entry<K, V>> iterator, AbstractDualBidiMap<K, V> parent) {
protected EntrySetIterator(final Iterator<Map.Entry<K, V>> iterator, final AbstractDualBidiMap<K, V> parent) {
super(iterator);
this.parent = parent;
}
@ -625,7 +625,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
}
// store value as remove may change the entry in the decorator (eg.TreeMap)
Object value = last.getValue();
final Object value = last.getValue();
super.remove();
parent.reverseMap.remove(value);
last = null;
@ -646,14 +646,14 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* @param entry the entry to decorate
* @param parent the parent map
*/
protected MapEntry(Map.Entry<K, V> entry, AbstractDualBidiMap<K, V> parent) {
protected MapEntry(final Map.Entry<K, V> entry, final AbstractDualBidiMap<K, V> parent) {
super(entry);
this.parent = parent;
}
@Override
public V setValue(V value) {
K key = MapEntry.this.getKey();
public V setValue(final V value) {
final K key = MapEntry.this.getKey();
if (parent.reverseMap.containsKey(value) &&
parent.reverseMap.get(value) != key) {
throw new IllegalArgumentException(
@ -686,7 +686,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
* Constructor.
* @param parent the parent map
*/
protected BidiMapIterator(AbstractDualBidiMap<K, V> parent) {
protected BidiMapIterator(final AbstractDualBidiMap<K, V> parent) {
super();
this.parent = parent;
this.iterator = parent.normalMap.entrySet().iterator();
@ -707,7 +707,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
}
// store value as remove may change the entry in the decorator (eg.TreeMap)
V value = last.getValue();
final V value = last.getValue();
iterator.remove();
parent.reverseMap.remove(value);
last = null;
@ -730,7 +730,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
return last.getValue();
}
public V setValue(V value) {
public V setValue(final V value) {
if (last == null) {
throw new IllegalStateException(
"Iterator setValue() can only be called after next() and before remove()");

View File

@ -44,7 +44,7 @@ public abstract class AbstractOrderedBidiMapDecorator<K, V>
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected AbstractOrderedBidiMapDecorator(OrderedBidiMap<K, V> map) {
protected AbstractOrderedBidiMapDecorator(final OrderedBidiMap<K, V> map) {
super(map);
}
@ -72,11 +72,11 @@ public abstract class AbstractOrderedBidiMapDecorator<K, V>
return decorated().lastKey();
}
public K nextKey(K key) {
public K nextKey(final K key) {
return decorated().nextKey(key);
}
public K previousKey(K key) {
public K previousKey(final K key) {
return decorated().previousKey(key);
}

View File

@ -45,7 +45,7 @@ public abstract class AbstractSortedBidiMapDecorator<K, V>
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
public AbstractSortedBidiMapDecorator(SortedBidiMap<K, V> map) {
public AbstractSortedBidiMapDecorator(final SortedBidiMap<K, V> map) {
super(map);
}
@ -73,15 +73,15 @@ public abstract class AbstractSortedBidiMapDecorator<K, V>
return decorated().valueComparator();
}
public SortedMap<K, V> subMap(K fromKey, K toKey) {
public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
return decorated().subMap(fromKey, toKey);
}
public SortedMap<K, V> headMap(K toKey) {
public SortedMap<K, V> headMap(final K toKey) {
return decorated().headMap(toKey);
}
public SortedMap<K, V> tailMap(K fromKey) {
public SortedMap<K, V> tailMap(final K fromKey) {
return decorated().tailMap(fromKey);
}

View File

@ -57,7 +57,7 @@ public class DualHashBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
*
* @param map the map whose mappings are to be placed in this map
*/
public DualHashBidiMap(Map<K, V> map) {
public DualHashBidiMap(final Map<K, V> map) {
super(new HashMap<K, V>(), new HashMap<V, K>());
putAll(map);
}
@ -69,7 +69,7 @@ public class DualHashBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
* @param reverseMap the reverse direction map
* @param inverseBidiMap the inverse BidiMap
*/
protected DualHashBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap, BidiMap<V, K> inverseBidiMap) {
protected DualHashBidiMap(final Map<K, V> normalMap, final Map<V, K> reverseMap, final BidiMap<V, K> inverseBidiMap) {
super(normalMap, reverseMap, inverseBidiMap);
}
@ -82,22 +82,23 @@ public class DualHashBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
* @return new bidi map
*/
@Override
protected BidiMap<V, K> createBidiMap(Map<V, K> normalMap, Map<K, V> reverseMap, BidiMap<K, V> inverseBidiMap) {
protected BidiMap<V, K> createBidiMap(final Map<V, K> normalMap, final Map<K, V> reverseMap, final BidiMap<K, V> inverseBidiMap) {
return new DualHashBidiMap<V, K>(normalMap, reverseMap, inverseBidiMap);
}
// Serialization
//-----------------------------------------------------------------------
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(normalMap);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
normalMap = new HashMap<K, V>();
reverseMap = new HashMap<V, K>();
@SuppressWarnings("unchecked") // will fail at runtime if stream is incorrect
final
Map<K, V> map = (Map<K, V>) in.readObject();
putAll(map);
}

View File

@ -79,7 +79,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
*
* @param map the map whose mappings are to be placed in this map
*/
public DualTreeBidiMap(Map<K, V> map) {
public DualTreeBidiMap(final Map<K, V> map) {
super(new TreeMap<K, V>(), new TreeMap<V, K>());
putAll(map);
this.comparator = null;
@ -92,7 +92,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
* @param keyComparator the comparator
* @param valueComparator the values comparator to use
*/
public DualTreeBidiMap(Comparator<? super K> keyComparator, Comparator<? super V> valueComparator) {
public DualTreeBidiMap(final Comparator<? super K> keyComparator, final Comparator<? super V> valueComparator) {
super(new TreeMap<K, V>(keyComparator), new TreeMap<V, K>(valueComparator));
this.comparator = keyComparator;
this.valueComparator = valueComparator;
@ -105,7 +105,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
* @param reverseMap the reverse direction map
* @param inverseBidiMap the inverse BidiMap
*/
protected DualTreeBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap, BidiMap<V, K> inverseBidiMap) {
protected DualTreeBidiMap(final Map<K, V> normalMap, final Map<V, K> reverseMap, final BidiMap<V, K> inverseBidiMap) {
super(normalMap, reverseMap, inverseBidiMap);
this.comparator = ((SortedMap<K, V>) normalMap).comparator();
this.valueComparator = ((SortedMap<V, K>) reverseMap).comparator();
@ -120,7 +120,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
* @return new bidi map
*/
@Override
protected DualTreeBidiMap<V, K> createBidiMap(Map<V, K> normalMap, Map<K, V> reverseMap, BidiMap<K, V> inverseMap) {
protected DualTreeBidiMap<V, K> createBidiMap(final Map<V, K> normalMap, final Map<K, V> reverseMap, final BidiMap<K, V> inverseMap) {
return new DualTreeBidiMap<V, K>(normalMap, reverseMap, inverseMap);
}
@ -143,15 +143,15 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
return ((SortedMap<K, V>) normalMap).lastKey();
}
public K nextKey(K key) {
public K nextKey(final K key) {
if (isEmpty()) {
return null;
}
if (normalMap instanceof OrderedMap) {
return ((OrderedMap<K, ?>) normalMap).nextKey(key);
}
SortedMap<K, V> sm = (SortedMap<K, V>) normalMap;
Iterator<K> it = sm.tailMap(key).keySet().iterator();
final SortedMap<K, V> sm = (SortedMap<K, V>) normalMap;
final Iterator<K> it = sm.tailMap(key).keySet().iterator();
it.next();
if (it.hasNext()) {
return it.next();
@ -159,15 +159,15 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
return null;
}
public K previousKey(K key) {
public K previousKey(final K key) {
if (isEmpty()) {
return null;
}
if (normalMap instanceof OrderedMap) {
return ((OrderedMap<K, V>) normalMap).previousKey(key);
}
SortedMap<K, V> sm = (SortedMap<K, V>) normalMap;
SortedMap<K, V> hm = sm.headMap(key);
final SortedMap<K, V> sm = (SortedMap<K, V>) normalMap;
final SortedMap<K, V> hm = sm.headMap(key);
if (hm.isEmpty()) {
return null;
}
@ -198,18 +198,18 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
//-----------------------------------------------------------------------
public SortedMap<K, V> headMap(K toKey) {
SortedMap<K, V> sub = ((SortedMap<K, V>) normalMap).headMap(toKey);
public SortedMap<K, V> headMap(final K toKey) {
final SortedMap<K, V> sub = ((SortedMap<K, V>) normalMap).headMap(toKey);
return new ViewMap<K, V>(this, sub);
}
public SortedMap<K, V> tailMap(K fromKey) {
SortedMap<K, V> sub = ((SortedMap<K, V>) normalMap).tailMap(fromKey);
public SortedMap<K, V> tailMap(final K fromKey) {
final SortedMap<K, V> sub = ((SortedMap<K, V>) normalMap).tailMap(fromKey);
return new ViewMap<K, V>(this, sub);
}
public SortedMap<K, V> subMap(K fromKey, K toKey) {
SortedMap<K, V> sub = ((SortedMap<K, V>) normalMap).subMap(fromKey, toKey);
public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
final SortedMap<K, V> sub = ((SortedMap<K, V>) normalMap).subMap(fromKey, toKey);
return new ViewMap<K, V>(this, sub);
}
@ -231,7 +231,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
* @param bidi the parent bidi map
* @param sm the subMap sorted map
*/
protected ViewMap(DualTreeBidiMap<K, V> bidi, SortedMap<K, V> sm) {
protected ViewMap(final DualTreeBidiMap<K, V> bidi, final SortedMap<K, V> sm) {
// the implementation is not great here...
// use the normalMap as the filtered map, but reverseMap as the full map
// this forces containsValue and clear to be overridden
@ -240,7 +240,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
}
@Override
public boolean containsValue(Object value) {
public boolean containsValue(final Object value) {
// override as default implementation uses reverseMap
return decorated().normalMap.containsValue(value);
}
@ -248,24 +248,24 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
@Override
public void clear() {
// override as default implementation uses reverseMap
for (Iterator<K> it = keySet().iterator(); it.hasNext();) {
for (final Iterator<K> it = keySet().iterator(); it.hasNext();) {
it.next();
it.remove();
}
}
@Override
public SortedMap<K, V> headMap(K toKey) {
public SortedMap<K, V> headMap(final K toKey) {
return new ViewMap<K, V>(decorated(), super.headMap(toKey));
}
@Override
public SortedMap<K, V> tailMap(K fromKey) {
public SortedMap<K, V> tailMap(final K fromKey) {
return new ViewMap<K, V>(decorated(), super.tailMap(fromKey));
}
@Override
public SortedMap<K, V> subMap(K fromKey, K toKey) {
public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
return new ViewMap<K, V>(decorated(), super.subMap(fromKey, toKey));
}
@ -275,12 +275,12 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
}
@Override
public K previousKey(K key) {
public K previousKey(final K key) {
return decorated().previousKey(key);
}
@Override
public K nextKey(K key) {
public K nextKey(final K key) {
return decorated().nextKey(key);
}
}
@ -304,7 +304,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
* Constructor.
* @param parent the parent map
*/
protected BidiOrderedMapIterator(AbstractDualBidiMap<K, V> parent) {
protected BidiOrderedMapIterator(final AbstractDualBidiMap<K, V> parent) {
super();
this.parent = parent;
iterator = new ArrayList<Map.Entry<K, V>>(parent.entrySet()).listIterator();
@ -350,7 +350,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
return last.getValue();
}
public V setValue(V value) {
public V setValue(final V value) {
if (last == null) {
throw new IllegalStateException(
"Iterator setValue() can only be called after next() and before remove()");
@ -379,16 +379,17 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
// Serialization
//-----------------------------------------------------------------------
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(normalMap);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
normalMap = new TreeMap<K, V>(comparator);
reverseMap = new TreeMap<V, K>(valueComparator);
@SuppressWarnings("unchecked") // will fail at runtime if the stream is incorrect
final
Map<K, V> map = (Map<K, V>) in.readObject();
putAll(map);
}

View File

@ -84,7 +84,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
*
* @param description the description for the element
*/
private DataElement(String description) {
private DataElement(final String description) {
this.description = description;
}
@ -188,7 +188,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
*/
public V get(final Object key) {
checkKey(key);
Node<K, V> node = lookupKey(key);
final Node<K, V> node = lookupKey(key);
return node == null ? null : node.getValue();
}
@ -217,7 +217,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @throws NullPointerException if the key is null
*/
public V put(final K key, final V value) {
V result = get(key);
final V result = get(key);
doPut(key, value);
return result;
}
@ -229,8 +229,8 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
*
* @param map the map to copy from
*/
public void putAll(Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> e : map.entrySet()) {
public void putAll(final Map<? extends K, ? extends V> map) {
for (final Map.Entry<? extends K, ? extends V> e : map.entrySet()) {
put(e.getKey(), e.getValue());
}
}
@ -276,7 +276,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
*/
public K getKey(final Object value) {
checkValue(value);
Node<K, V> node = lookupValue(value);
final Node<K, V> node = lookupValue(value);
return node == null ? null : node.getKey();
}
@ -330,9 +330,9 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param key the key to search for next from
* @return the next key, null if no match or at end
*/
public K nextKey(K key) {
public K nextKey(final K key) {
checkKey(key);
Node<K, V> node = nextGreater(lookupKey(key), KEY);
final Node<K, V> node = nextGreater(lookupKey(key), KEY);
return node == null ? null : node.getKey();
}
@ -344,9 +344,9 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param key the key to search for previous from
* @return the previous key, null if no match or at start
*/
public K previousKey(K key) {
public K previousKey(final K key) {
checkKey(key);
Node<K, V> node = nextSmaller(lookupKey(key), KEY);
final Node<K, V> node = nextSmaller(lookupKey(key), KEY);
return node == null ? null : node.getKey();
}
@ -442,7 +442,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @return true if equal
*/
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
return this.doEquals(obj, KEY);
}
@ -483,7 +483,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
Node<K, V> node = rootNode[KEY.ordinal()];
if (node == null) {
// map is empty
Node<K, V> root = new Node<K, V>(key, value);
final Node<K, V> root = new Node<K, V>(key, value);
rootNode[KEY.ordinal()] = root;
rootNode[VALUE.ordinal()] = root;
grow();
@ -491,7 +491,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
} else {
// add new mapping
while (true) {
int cmp = compare(key, node.getKey());
final int cmp = compare(key, node.getKey());
if (cmp == 0) {
// shouldn't happen
@ -500,7 +500,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
if (node.getLeft(KEY) != null) {
node = node.getLeft(KEY);
} else {
Node<K, V> newNode = new Node<K, V>(key, value);
final Node<K, V> newNode = new Node<K, V>(key, value);
insertValue(newNode);
node.setLeft(newNode, KEY);
@ -514,7 +514,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
if (node.getRight(KEY) != null) {
node = node.getRight(KEY);
} else {
Node<K, V> newNode = new Node<K, V>(key, value);
final Node<K, V> newNode = new Node<K, V>(key, value);
insertValue(newNode);
node.setRight(newNode, KEY);
@ -529,8 +529,8 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
}
}
private V doRemoveKey(Object key) {
Node<K, V> node = lookupKey(key);
private V doRemoveKey(final Object key) {
final Node<K, V> node = lookupKey(key);
if (node == null) {
return null;
}
@ -538,8 +538,8 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
return node.getValue();
}
private K doRemoveValue(Object value) {
Node<K, V> node = lookupValue(value);
private K doRemoveValue(final Object value) {
final Node<K, V> node = lookupValue(value);
if (node == null) {
return null;
}
@ -561,7 +561,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
Node<K, V> node = rootNode[dataElement.ordinal()];
while (node != null) {
int cmp = compare((T) data, (T) node.getData(dataElement));
final int cmp = compare((T) data, (T) node.getData(dataElement));
if (cmp == 0) {
rval = node;
break;
@ -573,11 +573,11 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
return rval;
}
private Node<K, V> lookupKey(Object key) {
private Node<K, V> lookupKey(final Object key) {
return this.<K>lookup(key, KEY);
}
private Node<K, V> lookupValue(Object value) {
private Node<K, V> lookupValue(final Object value) {
return this.<V>lookup(value, VALUE);
}
@ -815,7 +815,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param index the KEY or VALUE int
*/
private void rotateLeft(final Node<K, V> node, final DataElement dataElement) {
Node<K, V> rightChild = node.getRight(dataElement);
final Node<K, V> rightChild = node.getRight(dataElement);
node.setRight(rightChild.getLeft(dataElement), dataElement);
if (rightChild.getLeft(dataElement) != null) {
@ -843,7 +843,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param index the KEY or VALUE int
*/
private void rotateRight(final Node<K, V> node, final DataElement dataElement) {
Node<K, V> leftChild = node.getLeft(dataElement);
final Node<K, V> leftChild = node.getLeft(dataElement);
node.setLeft(leftChild.getRight(dataElement), dataElement);
if (leftChild.getRight(dataElement) != null) {
leftChild.getRight(dataElement).setParent(node, dataElement);
@ -878,7 +878,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
&& currentNode != rootNode[dataElement.ordinal()]
&& isRed(currentNode.getParent(dataElement), dataElement)) {
if (currentNode.isLeftChild(dataElement)) {
Node<K, V> y = getRightChild(getGrandParent(currentNode, dataElement), dataElement);
final Node<K, V> y = getRightChild(getGrandParent(currentNode, dataElement), dataElement);
if (isRed(y, dataElement)) {
makeBlack(getParent(currentNode, dataElement), dataElement);
@ -904,7 +904,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
} else {
// just like clause above, except swap left for right
Node<K, V> y = getLeftChild(getGrandParent(currentNode, dataElement), dataElement);
final Node<K, V> y = getLeftChild(getGrandParent(currentNode, dataElement), dataElement);
if (isRed(y, dataElement)) {
makeBlack(getParent(currentNode, dataElement), dataElement);
@ -940,14 +940,14 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param deletedNode the node to be deleted
*/
private void doRedBlackDelete(final Node<K, V> deletedNode) {
for (DataElement dataElement : DataElement.values()) {
for (final DataElement dataElement : DataElement.values()) {
// if deleted node has both left and children, swap with
// the next greater node
if (deletedNode.getLeft(dataElement) != null && deletedNode.getRight(dataElement) != null) {
swapPosition(nextGreater(deletedNode, dataElement), deletedNode, dataElement);
}
Node<K, V> replacement = deletedNode.getLeft(dataElement) != null ?
final Node<K, V> replacement = deletedNode.getLeft(dataElement) != null ?
deletedNode.getLeft(dataElement) : deletedNode.getRight(dataElement);
if (replacement != null) {
@ -1091,15 +1091,15 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
*/
private void swapPosition(final Node<K, V> x, final Node<K, V> y, final DataElement dataElement) {
// Save initial values.
Node<K, V> xFormerParent = x.getParent(dataElement);
Node<K, V> xFormerLeftChild = x.getLeft(dataElement);
Node<K, V> xFormerRightChild = x.getRight(dataElement);
Node<K, V> yFormerParent = y.getParent(dataElement);
Node<K, V> yFormerLeftChild = y.getLeft(dataElement);
Node<K, V> yFormerRightChild = y.getRight(dataElement);
boolean xWasLeftChild =
final Node<K, V> xFormerParent = x.getParent(dataElement);
final Node<K, V> xFormerLeftChild = x.getLeft(dataElement);
final Node<K, V> xFormerRightChild = x.getRight(dataElement);
final Node<K, V> yFormerParent = y.getParent(dataElement);
final Node<K, V> yFormerLeftChild = y.getLeft(dataElement);
final Node<K, V> yFormerRightChild = y.getRight(dataElement);
final boolean xWasLeftChild =
x.getParent(dataElement) != null && x == x.getParent(dataElement).getLeft(dataElement);
boolean yWasLeftChild =
final boolean yWasLeftChild =
y.getParent(dataElement) != null && y == y.getParent(dataElement).getLeft(dataElement);
// Swap, handling special cases of one being the other's parent.
@ -1276,7 +1276,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
Node<K, V> node = rootNode[VALUE.ordinal()];
while (true) {
int cmp = compare(newNode.getValue(), node.getValue());
final int cmp = compare(newNode.getValue(), node.getValue());
if (cmp == 0) {
throw new IllegalArgumentException(
@ -1313,30 +1313,30 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param type the KEY or VALUE int
* @return true if equal
*/
private boolean doEquals(Object obj, DataElement dataElement) {
private boolean doEquals(final Object obj, final DataElement dataElement) {
if (obj == this) {
return true;
}
if (obj instanceof Map == false) {
return false;
}
Map<?, ?> other = (Map<?, ?>) obj;
final Map<?, ?> other = (Map<?, ?>) obj;
if (other.size() != size()) {
return false;
}
if (nodeCount > 0) {
try {
for (MapIterator<?, ?> it = getMapIterator(dataElement); it.hasNext(); ) {
Object key = it.next();
Object value = it.getValue();
for (final MapIterator<?, ?> it = getMapIterator(dataElement); it.hasNext(); ) {
final Object key = it.next();
final Object value = it.getValue();
if (value.equals(other.get(key)) == false) {
return false;
}
}
} catch (ClassCastException ex) {
} catch (final ClassCastException ex) {
return false;
} catch (NullPointerException ex) {
} catch (final NullPointerException ex) {
return false;
}
}
@ -1349,12 +1349,12 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param type the KEY or VALUE int
* @return the hash code value for this map
*/
private int doHashCode(DataElement dataElement) {
private int doHashCode(final DataElement dataElement) {
int total = 0;
if (nodeCount > 0) {
for (MapIterator<?, ?> it = getMapIterator(dataElement); it.hasNext(); ) {
Object key = it.next();
Object value = it.getValue();
for (final MapIterator<?, ?> it = getMapIterator(dataElement); it.hasNext(); ) {
final Object key = it.next();
final Object value = it.getValue();
total += key.hashCode() ^ value.hashCode();
}
}
@ -1367,17 +1367,17 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
* @param type the KEY or VALUE int
* @return the string form of this map
*/
private String doToString(DataElement dataElement) {
private String doToString(final DataElement dataElement) {
if (nodeCount == 0) {
return "{}";
}
StringBuilder buf = new StringBuilder(nodeCount * 32);
final StringBuilder buf = new StringBuilder(nodeCount * 32);
buf.append('{');
MapIterator<?, ?> it = getMapIterator(dataElement);
final MapIterator<?, ?> it = getMapIterator(dataElement);
boolean hasNext = it.hasNext();
while (hasNext) {
Object key = it.next();
Object value = it.getValue();
final Object key = it.next();
final Object value = it.getValue();
buf.append(key == this ? "(this Map)" : key)
.append('=')
.append(value == this ? "(this Map)" : value);
@ -1392,7 +1392,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
return buf.toString();
}
private MapIterator<?, ?> getMapIterator(DataElement dataElement) {
private MapIterator<?, ?> getMapIterator(final DataElement dataElement) {
switch (dataElement) {
case KEY:
return new ViewMapIterator(KEY);
@ -1438,7 +1438,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
/**
* Create a new TreeBidiMap.KeyView.
*/
public KeyView(DataElement orderType) {
public KeyView(final DataElement orderType) {
super(orderType);
}
@ -1454,7 +1454,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
}
@Override
public boolean remove(Object o) {
public boolean remove(final Object o) {
return doRemoveKey(o) != null;
}
@ -1465,7 +1465,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
/**
* Create a new TreeBidiMap.ValueView.
*/
public ValueView(DataElement orderType) {
public ValueView(final DataElement orderType) {
super(orderType);
}
@ -1481,7 +1481,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
}
@Override
public boolean remove(Object o) {
public boolean remove(final Object o) {
return doRemoveValue(o) != null;
}
@ -1497,24 +1497,24 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
}
@Override
public boolean contains(Object obj) {
public boolean contains(final Object obj) {
if (obj instanceof Map.Entry == false) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
Object value = entry.getValue();
Node<K, V> node = lookupKey(entry.getKey());
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
final Object value = entry.getValue();
final Node<K, V> node = lookupKey(entry.getKey());
return node != null && node.getValue().equals(value);
}
@Override
public boolean remove(Object obj) {
public boolean remove(final Object obj) {
if (obj instanceof Map.Entry == false) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
Object value = entry.getValue();
Node<K, V> node = lookupKey(entry.getKey());
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
final Object value = entry.getValue();
final Node<K, V> node = lookupKey(entry.getKey());
if (node != null && node.getValue().equals(value)) {
doRedBlackDelete(node);
return true;
@ -1538,24 +1538,24 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
}
@Override
public boolean contains(Object obj) {
public boolean contains(final Object obj) {
if (obj instanceof Map.Entry == false) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
Object value = entry.getValue();
Node<K, V> node = lookupValue(entry.getKey());
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
final Object value = entry.getValue();
final Node<K, V> node = lookupValue(entry.getKey());
return node != null && node.getKey().equals(value);
}
@Override
public boolean remove(Object obj) {
public boolean remove(final Object obj) {
if (obj instanceof Map.Entry == false) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
Object value = entry.getValue();
Node<K, V> node = lookupValue(entry.getKey());
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
final Object value = entry.getValue();
final Node<K, V> node = lookupValue(entry.getKey());
if (node != null && node.getKey().equals(value)) {
doRedBlackDelete(node);
return true;
@ -1664,7 +1664,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
/**
* Constructor.
*/
ViewMapIterator(DataElement orderType) {
ViewMapIterator(final DataElement orderType) {
super(orderType);
}
@ -1705,7 +1705,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
/**
* Create a new TreeBidiMap.InverseViewMapIterator.
*/
public InverseViewMapIterator(DataElement orderType) {
public InverseViewMapIterator(final DataElement orderType) {
super(orderType);
}
@ -1779,7 +1779,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
return createEntry(navigatePrevious());
}
private Map.Entry<V, K> createEntry(Node<K, V> node) {
private Map.Entry<V, K> createEntry(final Node<K, V> node) {
return new UnmodifiableMapEntry<V, K>(node.getValue(), node.getKey());
}
}
@ -1983,7 +1983,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
if (!(obj instanceof Map.Entry)) {
return false;
}
Map.Entry<?, ?> e = (Map.Entry<?, ?>) obj;
final Map.Entry<?, ?> e = (Map.Entry<?, ?>) obj;
return getKey().equals(e.getKey()) && getValue().equals(e.getValue());
}
@ -2051,26 +2051,26 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
return greatestNode(TreeBidiMap.this.rootNode[VALUE.ordinal()], VALUE).getValue();
}
public V nextKey(V key) {
public V nextKey(final V key) {
checkKey(key);
Node<K, V> node = nextGreater(TreeBidiMap.this.<V>lookup(key, VALUE), VALUE);
final Node<K, V> node = nextGreater(TreeBidiMap.this.<V>lookup(key, VALUE), VALUE);
return node == null ? null : node.getValue();
}
public V previousKey(V key) {
public V previousKey(final V key) {
checkKey(key);
Node<K, V> node = TreeBidiMap.this.nextSmaller(TreeBidiMap.this.<V>lookup(key, VALUE), VALUE);
final Node<K, V> node = TreeBidiMap.this.nextSmaller(TreeBidiMap.this.<V>lookup(key, VALUE), VALUE);
return node == null ? null : node.getValue();
}
public K put(final V key, final K value) {
K result = get(key);
final K result = get(key);
TreeBidiMap.this.doPut(value, key);
return result;
}
public void putAll(Map<? extends V, ? extends K> map) {
for (Map.Entry<? extends V, ? extends K> e : map.entrySet()) {
public void putAll(final Map<? extends V, ? extends K> map) {
for (final Map.Entry<? extends V, ? extends K> e : map.entrySet()) {
put(e.getKey(), e.getValue());
}
}
@ -2120,7 +2120,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
}
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
return TreeBidiMap.this.doEquals(obj, DataElement.VALUE);
}

View File

@ -53,7 +53,7 @@ public final class UnmodifiableBidiMap<K, V>
* @return an unmodifiable BidiMap
* @throws IllegalArgumentException if map is null
*/
public static <K, V> BidiMap<K, V> unmodifiableBidiMap(BidiMap<K, V> map) {
public static <K, V> BidiMap<K, V> unmodifiableBidiMap(final BidiMap<K, V> map) {
if (map instanceof Unmodifiable) {
return map;
}
@ -67,7 +67,7 @@ public final class UnmodifiableBidiMap<K, V>
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
private UnmodifiableBidiMap(BidiMap<K, V> map) {
private UnmodifiableBidiMap(final BidiMap<K, V> map) {
super(map);
}
@ -78,47 +78,47 @@ public final class UnmodifiableBidiMap<K, V>
}
@Override
public V put(K key, V value) {
public V put(final K key, final V value) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map<? extends K, ? extends V> mapToCopy) {
public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
throw new UnsupportedOperationException();
}
@Override
public V remove(Object key) {
public V remove(final Object key) {
throw new UnsupportedOperationException();
}
@Override
public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> set = super.entrySet();
final Set<Map.Entry<K, V>> set = super.entrySet();
return UnmodifiableEntrySet.unmodifiableEntrySet(set);
}
@Override
public Set<K> keySet() {
Set<K> set = super.keySet();
final Set<K> set = super.keySet();
return UnmodifiableSet.unmodifiableSet(set);
}
@Override
public Collection<V> values() {
Collection<V> coll = super.values();
final Collection<V> coll = super.values();
return UnmodifiableCollection.unmodifiableCollection(coll);
}
//-----------------------------------------------------------------------
@Override
public K removeValue(Object value) {
public K removeValue(final Object value) {
throw new UnsupportedOperationException();
}
@Override
public MapIterator<K, V> mapIterator() {
MapIterator<K, V> it = decorated().mapIterator();
final MapIterator<K, V> it = decorated().mapIterator();
return UnmodifiableMapIterator.unmodifiableMapIterator(it);
}

View File

@ -53,7 +53,7 @@ public final class UnmodifiableOrderedBidiMap<K, V>
* @return an unmodifiable OrderedBidiMap
* @throws IllegalArgumentException if map is null
*/
public static <K, V> OrderedBidiMap<K, V> unmodifiableOrderedBidiMap(OrderedBidiMap<K, V> map) {
public static <K, V> OrderedBidiMap<K, V> unmodifiableOrderedBidiMap(final OrderedBidiMap<K, V> map) {
if (map instanceof Unmodifiable) {
return map;
}
@ -67,7 +67,7 @@ public final class UnmodifiableOrderedBidiMap<K, V>
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
private UnmodifiableOrderedBidiMap(OrderedBidiMap<K, V> map) {
private UnmodifiableOrderedBidiMap(final OrderedBidiMap<K, V> map) {
super(map);
}
@ -78,41 +78,41 @@ public final class UnmodifiableOrderedBidiMap<K, V>
}
@Override
public V put(K key, V value) {
public V put(final K key, final V value) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map<? extends K, ? extends V> mapToCopy) {
public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
throw new UnsupportedOperationException();
}
@Override
public V remove(Object key) {
public V remove(final Object key) {
throw new UnsupportedOperationException();
}
@Override
public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> set = super.entrySet();
final Set<Map.Entry<K, V>> set = super.entrySet();
return UnmodifiableEntrySet.unmodifiableEntrySet(set);
}
@Override
public Set<K> keySet() {
Set<K> set = super.keySet();
final Set<K> set = super.keySet();
return UnmodifiableSet.unmodifiableSet(set);
}
@Override
public Collection<V> values() {
Collection<V> coll = super.values();
final Collection<V> coll = super.values();
return UnmodifiableCollection.unmodifiableCollection(coll);
}
//-----------------------------------------------------------------------
@Override
public K removeValue(Object value) {
public K removeValue(final Object value) {
throw new UnsupportedOperationException();
}
@ -124,7 +124,7 @@ public final class UnmodifiableOrderedBidiMap<K, V>
//-----------------------------------------------------------------------
@Override
public OrderedMapIterator<K, V> mapIterator() {
OrderedMapIterator<K, V> it = decorated().mapIterator();
final OrderedMapIterator<K, V> it = decorated().mapIterator();
return UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it);
}

View File

@ -55,7 +55,7 @@ public final class UnmodifiableSortedBidiMap<K, V>
* @return an unmodifiable SortedBidiMap
* @throws IllegalArgumentException if map is null
*/
public static <K, V> SortedBidiMap<K, V> unmodifiableSortedBidiMap(SortedBidiMap<K, V> map) {
public static <K, V> SortedBidiMap<K, V> unmodifiableSortedBidiMap(final SortedBidiMap<K, V> map) {
if (map instanceof Unmodifiable) {
return map;
}
@ -69,7 +69,7 @@ public final class UnmodifiableSortedBidiMap<K, V>
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
private UnmodifiableSortedBidiMap(SortedBidiMap<K, V> map) {
private UnmodifiableSortedBidiMap(final SortedBidiMap<K, V> map) {
super(map);
}
@ -80,48 +80,48 @@ public final class UnmodifiableSortedBidiMap<K, V>
}
@Override
public V put(K key, V value) {
public V put(final K key, final V value) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map<? extends K, ? extends V> mapToCopy) {
public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
throw new UnsupportedOperationException();
}
@Override
public V remove(Object key) {
public V remove(final Object key) {
throw new UnsupportedOperationException();
}
@Override
public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> set = super.entrySet();
final Set<Map.Entry<K, V>> set = super.entrySet();
return UnmodifiableEntrySet.unmodifiableEntrySet(set);
}
@Override
public Set<K> keySet() {
Set<K> set = super.keySet();
final Set<K> set = super.keySet();
return UnmodifiableSet.unmodifiableSet(set);
}
@Override
public Collection<V> values() {
Collection<V> coll = super.values();
final Collection<V> coll = super.values();
return UnmodifiableCollection.unmodifiableCollection(coll);
}
//-----------------------------------------------------------------------
@Override
public K removeValue(Object value) {
public K removeValue(final Object value) {
throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
@Override
public OrderedMapIterator<K, V> mapIterator() {
OrderedMapIterator<K, V> it = decorated().mapIterator();
final OrderedMapIterator<K, V> it = decorated().mapIterator();
return UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it);
}
@ -136,20 +136,20 @@ public final class UnmodifiableSortedBidiMap<K, V>
}
@Override
public SortedMap<K, V> subMap(K fromKey, K toKey) {
SortedMap<K, V> sm = decorated().subMap(fromKey, toKey);
public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
final SortedMap<K, V> sm = decorated().subMap(fromKey, toKey);
return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
}
@Override
public SortedMap<K, V> headMap(K toKey) {
SortedMap<K, V> sm = decorated().headMap(toKey);
public SortedMap<K, V> headMap(final K toKey) {
final SortedMap<K, V> sm = decorated().headMap(toKey);
return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
}
@Override
public SortedMap<K, V> tailMap(K fromKey) {
SortedMap<K, V> sm = decorated().tailMap(fromKey);
public SortedMap<K, V> tailMap(final K fromKey) {
final SortedMap<K, V> sm = decorated().tailMap(fromKey);
return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
}

View File

@ -48,7 +48,7 @@ public abstract class AbstractBufferDecorator<E> extends AbstractCollectionDecor
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
protected AbstractBufferDecorator(Buffer<E> buffer) {
protected AbstractBufferDecorator(final Buffer<E> buffer) {
super(buffer);
}

View File

@ -60,7 +60,7 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
* @return a new blocking Buffer
* @throws IllegalArgumentException if buffer is null
*/
public static <E> BlockingBuffer<E> blockingBuffer(Buffer<E> buffer) {
public static <E> BlockingBuffer<E> blockingBuffer(final Buffer<E> buffer) {
return new BlockingBuffer<E>(buffer);
}
@ -74,7 +74,7 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
* @throws IllegalArgumentException if the buffer is null
* @since 3.2
*/
public static <E> BlockingBuffer<E> blockingBuffer(Buffer<E> buffer, long timeoutMillis) {
public static <E> BlockingBuffer<E> blockingBuffer(final Buffer<E> buffer, final long timeoutMillis) {
return new BlockingBuffer<E>(buffer, timeoutMillis);
}
@ -85,7 +85,7 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if the buffer is null
*/
protected BlockingBuffer(Buffer<E> buffer) {
protected BlockingBuffer(final Buffer<E> buffer) {
super(buffer);
this.timeout = 0;
}
@ -98,25 +98,25 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
* @throws IllegalArgumentException if the buffer is null
* @since 3.2
*/
protected BlockingBuffer(Buffer<E> buffer, long timeoutMillis) {
protected BlockingBuffer(final Buffer<E> buffer, final long timeoutMillis) {
super(buffer);
this.timeout = timeoutMillis < 0 ? 0 : timeoutMillis;
}
//-----------------------------------------------------------------------
@Override
public boolean add(E o) {
public boolean add(final E o) {
synchronized (lock) {
boolean result = collection.add(o);
final boolean result = collection.add(o);
lock.notifyAll();
return result;
}
}
@Override
public boolean addAll(Collection<? extends E> c) {
public boolean addAll(final Collection<? extends E> c) {
synchronized (lock) {
boolean result = collection.addAll(c);
final boolean result = collection.addAll(c);
lock.notifyAll();
return result;
}
@ -140,8 +140,8 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
} else {
return get(timeout);
}
} catch (InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter());
} catch (final InterruptedException e) {
final PrintWriter out = new PrintWriter(new StringWriter());
e.printStackTrace(out);
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
}
@ -168,8 +168,8 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
try {
lock.wait(timeLeft);
timeLeft = expiration - System.currentTimeMillis();
} catch(InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter());
} catch(final InterruptedException e) {
final PrintWriter out = new PrintWriter(new StringWriter());
e.printStackTrace(out);
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
}
@ -199,8 +199,8 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
} else {
return remove(timeout);
}
} catch (InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter());
} catch (final InterruptedException e) {
final PrintWriter out = new PrintWriter(new StringWriter());
e.printStackTrace(out);
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
}
@ -227,8 +227,8 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
try {
lock.wait(timeLeft);
timeLeft = expiration - System.currentTimeMillis();
} catch(InterruptedException e) {
PrintWriter out = new PrintWriter(new StringWriter());
} catch(final InterruptedException e) {
final PrintWriter out = new PrintWriter(new StringWriter());
e.printStackTrace(out);
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
}

View File

@ -66,7 +66,7 @@ public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCo
* @throws IllegalArgumentException if the buffer is null
* @throws IllegalArgumentException if the maximum size is zero or less
*/
public static <E> BoundedBuffer<E> boundedBuffer(Buffer<E> buffer, int maximumSize) {
public static <E> BoundedBuffer<E> boundedBuffer(final Buffer<E> buffer, final int maximumSize) {
return new BoundedBuffer<E>(buffer, maximumSize, 0L);
}
@ -82,7 +82,7 @@ public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCo
* @throws IllegalArgumentException if the buffer is null
* @throws IllegalArgumentException if the maximum size is zero or less
*/
public static <E> BoundedBuffer<E> boundedBuffer(Buffer<E> buffer, int maximumSize, long timeout) {
public static <E> BoundedBuffer<E> boundedBuffer(final Buffer<E> buffer, final int maximumSize, final long timeout) {
return new BoundedBuffer<E>(buffer, maximumSize, timeout);
}
@ -97,7 +97,7 @@ public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCo
* @throws IllegalArgumentException if the buffer is null
* @throws IllegalArgumentException if the maximum size is zero or less
*/
protected BoundedBuffer(Buffer<E> buffer, int maximumSize, long timeout) {
protected BoundedBuffer(final Buffer<E> buffer, final int maximumSize, final long timeout) {
super(buffer);
if (maximumSize < 1) {
throw new IllegalArgumentException();
@ -110,14 +110,14 @@ public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCo
@Override
public E remove() {
synchronized (lock) {
E returnValue = decorated().remove();
final E returnValue = decorated().remove();
lock.notifyAll();
return returnValue;
}
}
@Override
public boolean add(E o) {
public boolean add(final E o) {
synchronized (lock) {
timeoutWait(1);
return decorated().add(o);
@ -165,8 +165,8 @@ public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCo
try {
lock.wait(timeLeft);
timeLeft = expiration - System.currentTimeMillis();
} catch (InterruptedException ex) {
PrintWriter out = new PrintWriter(new StringWriter());
} catch (final InterruptedException ex) {
final PrintWriter out = new PrintWriter(new StringWriter());
ex.printStackTrace(out);
throw new BufferUnderflowException(
"Caused by InterruptedException: " + out.toString());
@ -197,7 +197,7 @@ public class BoundedBuffer<E> extends SynchronizedBuffer<E> implements BoundedCo
*
* @param it the decorated {@link Iterator}
*/
public NotifyingIterator(Iterator<E> it) {
public NotifyingIterator(final Iterator<E> it) {
super(it);
}

View File

@ -99,7 +99,7 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
* @throws IllegalArgumentException if the size is less than 1
*/
@SuppressWarnings("unchecked")
public BoundedFifoBuffer(int size) {
public BoundedFifoBuffer(final int size) {
if (size <= 0) {
throw new IllegalArgumentException("The size must be greater than 0");
}
@ -115,7 +115,7 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
* @param coll the collection whose elements to add, may not be null
* @throws NullPointerException if the collection is null
*/
public BoundedFifoBuffer(Collection<? extends E> coll) {
public BoundedFifoBuffer(final Collection<? extends E> coll) {
this(coll.size());
addAll(coll);
}
@ -127,10 +127,10 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
* @param out the output stream
* @throws IOException if an I/O error occurs while writing to the output stream
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeInt(size());
for (E e : this) {
for (final E e : this) {
out.writeObject(e);
}
}
@ -143,10 +143,10 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
* @throws ClassNotFoundException if the class of a serialized object can not be found
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
elements = (E[]) new Object[maxElements];
int size = in.readInt();
final int size = in.readInt();
for (int i = 0; i < size; i++) {
elements[i] = (E) in.readObject();
}
@ -228,7 +228,7 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
* @throws BufferOverflowException if this buffer is full
*/
@Override
public boolean add(E element) {
public boolean add(final E element) {
if (null == element) {
throw new NullPointerException("Attempted to add null object to buffer");
}
@ -270,7 +270,7 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
* @return the element at position {@code index}
* @throws NoSuchElementException if the requested position is outside the range [0, size)
*/
public E get(int index) {
public E get(final int index) {
final int sz = size();
if (index < 0 || index >= sz) {
throw new NoSuchElementException(
@ -293,7 +293,7 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
throw new BufferUnderflowException("The buffer is already empty");
}
E element = elements[start];
final E element = elements[start];
if (null != element) {
elements[start++] = null;

View File

@ -61,7 +61,7 @@ public class CircularFifoBuffer<E> extends BoundedFifoBuffer<E> {
* @param size the size of the buffer (cannot be changed)
* @throws IllegalArgumentException if the size is less than 1
*/
public CircularFifoBuffer(int size) {
public CircularFifoBuffer(final int size) {
super(size);
}
@ -72,7 +72,7 @@ public class CircularFifoBuffer<E> extends BoundedFifoBuffer<E> {
* @param coll the collection to copy into the buffer, may not be null
* @throws NullPointerException if the collection is null
*/
public CircularFifoBuffer(Collection<E> coll) {
public CircularFifoBuffer(final Collection<E> coll) {
super(coll);
}
@ -84,7 +84,7 @@ public class CircularFifoBuffer<E> extends BoundedFifoBuffer<E> {
* @return true, always
*/
@Override
public boolean add(E element) {
public boolean add(final E element) {
if (isFull()) {
remove();
}

View File

@ -54,7 +54,7 @@ public class PredicatedBuffer<E> extends PredicatedCollection<E> implements Buff
* @throws IllegalArgumentException if buffer or predicate is null
* @throws IllegalArgumentException if the buffer contains invalid elements
*/
public static <E> PredicatedBuffer<E> predicatedBuffer(Buffer<E> buffer, Predicate<? super E> predicate) {
public static <E> PredicatedBuffer<E> predicatedBuffer(final Buffer<E> buffer, final Predicate<? super E> predicate) {
return new PredicatedBuffer<E>(buffer, predicate);
}
@ -70,7 +70,7 @@ public class PredicatedBuffer<E> extends PredicatedCollection<E> implements Buff
* @throws IllegalArgumentException if buffer or predicate is null
* @throws IllegalArgumentException if the buffer contains invalid elements
*/
protected PredicatedBuffer(Buffer<E> buffer, Predicate<? super E> predicate) {
protected PredicatedBuffer(final Buffer<E> buffer, final Predicate<? super E> predicate) {
super(buffer, predicate);
}

View File

@ -104,7 +104,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @param comparator the comparator used to order the elements,
* null means use natural order
*/
public PriorityBuffer(Comparator<? super E> comparator) {
public PriorityBuffer(final Comparator<? super E> comparator) {
this(DEFAULT_CAPACITY, true, comparator);
}
@ -115,7 +115,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @param ascendingOrder if <code>true</code> the heap is created as a
* minimum heap; otherwise, the heap is created as a maximum heap
*/
public PriorityBuffer(boolean ascendingOrder) {
public PriorityBuffer(final boolean ascendingOrder) {
this(DEFAULT_CAPACITY, ascendingOrder, null);
}
@ -127,7 +127,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @param comparator the comparator used to order the elements,
* null means use natural order
*/
public PriorityBuffer(boolean ascendingOrder, Comparator<? super E> comparator) {
public PriorityBuffer(final boolean ascendingOrder, final Comparator<? super E> comparator) {
this(DEFAULT_CAPACITY, ascendingOrder, comparator);
}
@ -138,7 +138,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @param capacity the initial capacity for the buffer, greater than zero
* @throws IllegalArgumentException if <code>capacity</code> is &lt;= <code>0</code>
*/
public PriorityBuffer(int capacity) {
public PriorityBuffer(final int capacity) {
this(capacity, true, null);
}
@ -151,7 +151,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* null means use natural order
* @throws IllegalArgumentException if <code>capacity</code> is &lt;= <code>0</code>
*/
public PriorityBuffer(int capacity, Comparator<? super E> comparator) {
public PriorityBuffer(final int capacity, final Comparator<? super E> comparator) {
this(capacity, true, comparator);
}
@ -164,7 +164,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* minimum heap; otherwise, the heap is created as a maximum heap.
* @throws IllegalArgumentException if <code>capacity</code> is <code>&lt;= 0</code>
*/
public PriorityBuffer(int capacity, boolean ascendingOrder) {
public PriorityBuffer(final int capacity, final boolean ascendingOrder) {
this(capacity, ascendingOrder, null);
}
@ -180,7 +180,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @throws IllegalArgumentException if <code>capacity</code> is <code>&lt;= 0</code>
*/
@SuppressWarnings("unchecked")
public PriorityBuffer(int capacity, boolean ascendingOrder, Comparator<? super E> comparator) {
public PriorityBuffer(final int capacity, final boolean ascendingOrder, final Comparator<? super E> comparator) {
super();
if (capacity <= 0) {
throw new IllegalArgumentException("invalid capacity");
@ -241,7 +241,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @return true always
*/
@Override
public boolean add(E element) {
public boolean add(final E element) {
if (isAtCapacity()) {
grow();
}
@ -378,7 +378,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
*/
protected void percolateUpMinHeap(final int index) {
int hole = index;
E element = elements[hole];
final E element = elements[hole];
while (hole > 1 && compare(element, elements[hole / 2]) < 0) {
// save element that is being pushed down
// as the element "bubble" is percolated up
@ -410,7 +410,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
*/
protected void percolateUpMaxHeap(final int index) {
int hole = index;
E element = elements[hole];
final E element = elements[hole];
while (hole > 1 && compare(element, elements[hole / 2]) > 0) {
// save element that is being pushed down
@ -443,7 +443,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @param b the second object
* @return -ve if a less than b, 0 if they are equal, +ve if a greater than b
*/
protected int compare(E a, E b) {
protected int compare(final E a, final E b) {
return comparator.compare(a, b);
}

View File

@ -46,7 +46,7 @@ public class SynchronizedBuffer<E>
* @return a new synchronized Buffer
* @throws IllegalArgumentException if buffer is null
*/
public static <E> SynchronizedBuffer<E> synchronizedBuffer(Buffer<E> buffer) {
public static <E> SynchronizedBuffer<E> synchronizedBuffer(final Buffer<E> buffer) {
return new SynchronizedBuffer<E>(buffer);
}
@ -57,7 +57,7 @@ public class SynchronizedBuffer<E>
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if the buffer is null
*/
protected SynchronizedBuffer(Buffer<E> buffer) {
protected SynchronizedBuffer(final Buffer<E> buffer) {
super(buffer);
}
@ -68,7 +68,7 @@ public class SynchronizedBuffer<E>
* @param lock the lock object to use, must not be null
* @throws IllegalArgumentException if the buffer is null
*/
protected SynchronizedBuffer(Buffer<E> buffer, Object lock) {
protected SynchronizedBuffer(final Buffer<E> buffer, final Object lock) {
super(buffer, lock);
}

View File

@ -51,8 +51,8 @@ public class TransformedBuffer<E> extends TransformedCollection<E> implements Bu
* @return a new transformed Buffer
* @throws IllegalArgumentException if buffer or transformer is null
*/
public static <E> TransformedBuffer<E> transformingBuffer(Buffer<E> buffer,
Transformer<? super E, ? extends E> transformer) {
public static <E> TransformedBuffer<E> transformingBuffer(final Buffer<E> buffer,
final Transformer<? super E, ? extends E> transformer) {
return new TransformedBuffer<E>(buffer, transformer);
}
@ -71,15 +71,16 @@ public class TransformedBuffer<E> extends TransformedCollection<E> implements Bu
* @throws IllegalArgumentException if buffer or transformer is null
* @since 3.3
*/
public static <E> TransformedBuffer<E> transformedBuffer(Buffer<E> buffer,
Transformer<? super E, ? extends E> transformer) {
public static <E> TransformedBuffer<E> transformedBuffer(final Buffer<E> buffer,
final Transformer<? super E, ? extends E> transformer) {
// throws IAE if buffer or transformer is null
final TransformedBuffer<E> decorated = new TransformedBuffer<E>(buffer, transformer);
if (buffer.size() > 0) {
@SuppressWarnings("unchecked") // buffer is type <E>
final
E[] values = (E[]) buffer.toArray();
buffer.clear();
for (E value : values) {
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
}
@ -97,7 +98,7 @@ public class TransformedBuffer<E> extends TransformedCollection<E> implements Bu
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if buffer or transformer is null
*/
protected TransformedBuffer(Buffer<E> buffer, Transformer<? super E, ? extends E> transformer) {
protected TransformedBuffer(final Buffer<E> buffer, final Transformer<? super E, ? extends E> transformer) {
super(buffer, transformer);
}

View File

@ -90,7 +90,7 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
* @throws IllegalArgumentException if the size is less than 1
*/
@SuppressWarnings("unchecked")
public UnboundedFifoBuffer(int initialSize) {
public UnboundedFifoBuffer(final int initialSize) {
if (initialSize <= 0) {
throw new IllegalArgumentException("The size must be greater than 0");
}
@ -106,11 +106,11 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
* @param out the output stream
* @throws IOException if an I/O error occurs while writing to the output stream
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeInt(size());
out.writeInt(buffer.length);
for (E e : this) {
for (final E e : this) {
out.writeObject(e);
}
}
@ -123,10 +123,10 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
* @throws ClassNotFoundException if the class of a serialized object can not be found
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
int size = in.readInt();
int length = in.readInt();
final int size = in.readInt();
final int length = in.readInt();
buffer = (E[]) new Object[length];
for (int i = 0; i < size; i++) {
buffer[i] = (E) in.readObject();
@ -180,7 +180,7 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
if (size() + 1 >= buffer.length) {
// copy contents to a new buffer array
E[] tmp = (E[]) new Object[(buffer.length - 1) * 2 + 1];
final E[] tmp = (E[]) new Object[(buffer.length - 1) * 2 + 1];
int j = 0;
// move head to element zero in the new array
for (int i = head; i != tail;) {
@ -225,7 +225,7 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
throw new BufferUnderflowException("The buffer is already empty");
}
E element = buffer[head];
final E element = buffer[head];
if (element != null) {
buffer[head] = null;
head = increment(head);

View File

@ -54,7 +54,7 @@ public final class UnmodifiableBuffer<E>
* @return an unmodifiable Buffer
* @throws IllegalArgumentException if buffer is null
*/
public static <E> Buffer<E> unmodifiableBuffer(Buffer<E> buffer) {
public static <E> Buffer<E> unmodifiableBuffer(final Buffer<E> buffer) {
if (buffer instanceof Unmodifiable) {
return buffer;
}
@ -68,7 +68,7 @@ public final class UnmodifiableBuffer<E>
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if buffer is null
*/
private UnmodifiableBuffer(Buffer<E> buffer) {
private UnmodifiableBuffer(final Buffer<E> buffer) {
super(buffer);
}
@ -79,7 +79,7 @@ public final class UnmodifiableBuffer<E>
* @param out the output stream
* @throws IOException if an I/O error occurs while writing to the output stream
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(final ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(collection);
}
@ -92,7 +92,7 @@ public final class UnmodifiableBuffer<E>
* @throws ClassNotFoundException if the class of a serialized object can not be found
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
collection = (Collection<E>) in.readObject();
}
@ -104,12 +104,12 @@ public final class UnmodifiableBuffer<E>
}
@Override
public boolean add(Object object) {
public boolean add(final Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@ -119,17 +119,17 @@ public final class UnmodifiableBuffer<E>
}
@Override
public boolean remove(Object object) {
public boolean remove(final Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}

View File

@ -62,7 +62,7 @@ public abstract class AbstractCollectionDecorator<E>
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected AbstractCollectionDecorator(Collection<E> coll) {
protected AbstractCollectionDecorator(final Collection<E> coll) {
if (coll == null) {
throw new IllegalArgumentException("Collection must not be null");
}
@ -81,11 +81,11 @@ public abstract class AbstractCollectionDecorator<E>
//-----------------------------------------------------------------------
public boolean add(E object) {
public boolean add(final E object) {
return decorated().add(object);
}
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
return decorated().addAll(coll);
}
@ -93,7 +93,7 @@ public abstract class AbstractCollectionDecorator<E>
decorated().clear();
}
public boolean contains(Object object) {
public boolean contains(final Object object) {
return decorated().contains(object);
}
@ -105,7 +105,7 @@ public abstract class AbstractCollectionDecorator<E>
return decorated().iterator();
}
public boolean remove(Object object) {
public boolean remove(final Object object) {
return decorated().remove(object);
}
@ -117,24 +117,24 @@ public abstract class AbstractCollectionDecorator<E>
return decorated().toArray();
}
public <T> T[] toArray(T[] object) {
public <T> T[] toArray(final T[] object) {
return decorated().toArray(object);
}
public boolean containsAll(Collection<?> coll) {
public boolean containsAll(final Collection<?> coll) {
return decorated().containsAll(coll);
}
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
return decorated().removeAll(coll);
}
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
return decorated().retainAll(coll);
}
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
return object == this || decorated().equals(object);
}

View File

@ -70,7 +70,7 @@ public abstract class AbstractUntypedCollectionDecorator<E, D> implements Collec
decorated().clear();
}
public boolean contains(Object object) {
public boolean contains(final Object object) {
return decorated().contains(object);
}
@ -78,7 +78,7 @@ public abstract class AbstractUntypedCollectionDecorator<E, D> implements Collec
return decorated().isEmpty();
}
public boolean remove(Object object) {
public boolean remove(final Object object) {
return decorated().remove(object);
}
@ -90,24 +90,24 @@ public abstract class AbstractUntypedCollectionDecorator<E, D> implements Collec
return decorated().toArray();
}
public <T> T[] toArray(T[] object) {
public <T> T[] toArray(final T[] object) {
return decorated().toArray(object);
}
public boolean containsAll(Collection<?> coll) {
public boolean containsAll(final Collection<?> coll) {
return decorated().containsAll(coll);
}
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
return decorated().removeAll(coll);
}
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
return decorated().retainAll(coll);
}
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
return object == this || decorated().equals(object);
}

View File

@ -62,7 +62,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*
* @param compositeCollection the Collection to be appended to the composite
*/
public CompositeCollection(Collection<E> compositeCollection) {
public CompositeCollection(final Collection<E> compositeCollection) {
super();
addComposited(compositeCollection);
}
@ -73,7 +73,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @param compositeCollection1 the Collection to be appended to the composite
* @param compositeCollection2 the Collection to be appended to the composite
*/
public CompositeCollection(Collection<E> compositeCollection1, Collection<E> compositeCollection2) {
public CompositeCollection(final Collection<E> compositeCollection1, final Collection<E> compositeCollection2) {
super();
addComposited(compositeCollection1, compositeCollection2);
}
@ -83,7 +83,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*
* @param compositeCollections the collections to composite
*/
public CompositeCollection(Collection<E>[] compositeCollections) {
public CompositeCollection(final Collection<E>[] compositeCollections) {
super();
addComposited(compositeCollections);
}
@ -108,7 +108,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*/
public int size() {
int size = 0;
for (Collection<E> item : all) {
for (final Collection<E> item : all) {
size += item.size();
}
return size;
@ -122,7 +122,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @return true if all of the contained collections are empty
*/
public boolean isEmpty() {
for (Collection<? extends E> item : all) {
for (final Collection<? extends E> item : all) {
if (item.isEmpty() == false) {
return false;
}
@ -138,8 +138,8 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @param obj the object to search for
* @return true if obj is contained in any of the contained collections
*/
public boolean contains(Object obj) {
for (Collection<? extends E> item : all) {
public boolean contains(final Object obj) {
for (final Collection<? extends E> item : all) {
if (item.contains(obj)) {
return true;
}
@ -161,8 +161,8 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
if (all.isEmpty()) {
return EmptyIterator.<E>emptyIterator();
}
IteratorChain<E> chain = new IteratorChain<E>();
for (Collection<? extends E> item : all) {
final IteratorChain<E> chain = new IteratorChain<E>();
for (final Collection<? extends E> item : all) {
chain.addIterator(item.iterator());
}
return chain;
@ -176,7 +176,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
public Object[] toArray() {
final Object[] result = new Object[size()];
int i = 0;
for (Iterator<E> it = iterator(); it.hasNext(); i++) {
for (final Iterator<E> it = iterator(); it.hasNext(); i++) {
result[i] = it.next();
}
return result;
@ -191,8 +191,8 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @return an array of all the elements in the collection
*/
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] array) {
int size = size();
public <T> T[] toArray(final T[] array) {
final int size = size();
Object[] result = null;
if (array.length >= size) {
result = array;
@ -201,8 +201,8 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
}
int offset = 0;
for (Collection<? extends E> item : all) {
for (E e : item) {
for (final Collection<? extends E> item : all) {
for (final E e : item) {
result[offset++] = e;
}
}
@ -224,7 +224,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @throws NullPointerException if the object cannot be added because its null
* @throws IllegalArgumentException if the object cannot be added
*/
public boolean add(E obj) {
public boolean add(final E obj) {
if (mutator == null) {
throw new UnsupportedOperationException(
"add() is not supported on CompositeCollection without a CollectionMutator strategy");
@ -243,7 +243,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @throws NullPointerException if the object cannot be removed because its null
* @throws IllegalArgumentException if the object cannot be removed
*/
public boolean remove(Object obj) {
public boolean remove(final Object obj) {
if (mutator == null) {
throw new UnsupportedOperationException(
"remove() is not supported on CompositeCollection without a CollectionMutator strategy");
@ -260,8 +260,8 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @param coll the collection to check for
* @return true if all elements contained
*/
public boolean containsAll(Collection<?> coll) {
for (Object item : coll) {
public boolean containsAll(final Collection<?> coll) {
for (final Object item : coll) {
if (contains(item) == false) {
return false;
}
@ -281,7 +281,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @throws NullPointerException if the object cannot be added because its null
* @throws IllegalArgumentException if the object cannot be added
*/
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
if (mutator == null) {
throw new UnsupportedOperationException(
"addAll() is not supported on CompositeCollection without a CollectionMutator strategy");
@ -298,12 +298,12 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @return true if the collection was modified
* @throws UnsupportedOperationException if removeAll is unsupported
*/
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
if (coll.size() == 0) {
return false;
}
boolean changed = false;
for (Collection<? extends E> item : all) {
for (final Collection<? extends E> item : all) {
changed |= item.removeAll(coll);
}
return changed;
@ -321,7 +321,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*/
public boolean retainAll(final Collection<?> coll) {
boolean changed = false;
for (Collection<? extends E> item : all) {
for (final Collection<? extends E> item : all) {
changed |= item.retainAll(coll);
}
return changed;
@ -335,7 +335,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @throws UnsupportedOperationException if clear is unsupported
*/
public void clear() {
for (Collection<? extends E> coll : all) {
for (final Collection<? extends E> coll : all) {
coll.clear();
}
}
@ -346,7 +346,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*
* @param mutator the mutator to use
*/
public void setMutator(CollectionMutator<E> mutator) {
public void setMutator(final CollectionMutator<E> mutator) {
this.mutator = mutator;
}
@ -355,7 +355,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*
* @param compositeCollection the Collection to be appended to the composite
*/
public void addComposited(Collection<E> compositeCollection) {
public void addComposited(final Collection<E> compositeCollection) {
all.add(compositeCollection);
}
@ -365,7 +365,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
* @param compositeCollection1 the Collection to be appended to the composite
* @param compositeCollection2 the Collection to be appended to the composite
*/
public void addComposited(Collection<E> compositeCollection1, Collection<E> compositeCollection2) {
public void addComposited(final Collection<E> compositeCollection1, final Collection<E> compositeCollection2) {
all.add(compositeCollection1);
all.add(compositeCollection2);
}
@ -375,7 +375,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*
* @param compositeCollections the Collections to be appended to the composite
*/
public void addComposited(Collection<E>[] compositeCollections) {
public void addComposited(final Collection<E>[] compositeCollections) {
all.addAll(Arrays.asList(compositeCollections));
}
@ -395,7 +395,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
*
* @param coll collection to be removed
*/
public void removeComposited(Collection<E> coll) {
public void removeComposited(final Collection<E> coll) {
all.remove(coll);
}

View File

@ -73,7 +73,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
* @param keyTransformer {@link Transformer} for generating index keys
* @param map map to use as index
*/
public IndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer, HashMap<K, C> map) {
public IndexedCollection(final Collection<C> coll, final Transformer<C, K> keyTransformer, final HashMap<K, C> map) {
super(coll);
this.keyTransformer = keyTransformer;
this.index = new HashMap<K, C>();
@ -81,7 +81,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
}
@Override
public boolean add(C object) {
public boolean add(final C object) {
final boolean added = super.add(object);
if (added) {
addToIndex(object);
@ -90,9 +90,9 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
}
@Override
public boolean addAll(Collection<? extends C> coll) {
public boolean addAll(final Collection<? extends C> coll) {
boolean changed = false;
for (C c: coll) {
for (final C c: coll) {
changed |= add(c);
}
return changed;
@ -111,7 +111,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
*/
@SuppressWarnings("unchecked")
@Override
public boolean contains(Object object) {
public boolean contains(final Object object) {
return index.containsKey(keyTransformer.transform((C) object));
}
@ -121,8 +121,8 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
* Note: uses the index for fast lookup
*/
@Override
public boolean containsAll(Collection<?> coll) {
for (Object o : coll) {
public boolean containsAll(final Collection<?> coll) {
for (final Object o : coll) {
if (!contains(o)) {
return false;
}
@ -136,7 +136,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
* @param key key to look up
* @return element found
*/
public C get(K key) {
public C get(final K key) {
return index.get(key);
}
@ -145,14 +145,14 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
*/
public void reindex() {
index.clear();
for (C c : decorated()) {
for (final C c : decorated()) {
addToIndex(c);
}
}
@SuppressWarnings("unchecked")
@Override
public boolean remove(Object object) {
public boolean remove(final Object object) {
final boolean removed = super.remove(object);
if (removed) {
removeFromIndex((C) object);
@ -161,16 +161,16 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
boolean changed = false;
for (Object o : coll) {
for (final Object o : coll) {
changed |= remove(o);
}
return changed;
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
final boolean changed = super.retainAll(coll);
if (changed) {
reindex();
@ -185,7 +185,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
*
* @param object the object to index
*/
private void addToIndex(C object) {
private void addToIndex(final C object) {
final C existingObject = index.put(keyTransformer.transform(object), object);
if (existingObject != null) {
throw new IllegalArgumentException("Duplicate key in uniquely indexed collection.");
@ -197,7 +197,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
*
* @param object the object to remove
*/
private void removeFromIndex(C object) {
private void removeFromIndex(final C object) {
index.remove(keyTransformer.transform(object));
}

View File

@ -58,8 +58,8 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
* @throws IllegalArgumentException if collection or predicate is null
* @throws IllegalArgumentException if the collection contains invalid elements
*/
public static <T> PredicatedCollection<T> predicatedCollection(Collection<T> coll,
Predicate<? super T> predicate) {
public static <T> PredicatedCollection<T> predicatedCollection(final Collection<T> coll,
final Predicate<? super T> predicate) {
return new PredicatedCollection<T>(coll, predicate);
}
@ -75,13 +75,13 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
* @throws IllegalArgumentException if collection or predicate is null
* @throws IllegalArgumentException if the collection contains invalid elements
*/
protected PredicatedCollection(Collection<E> coll, Predicate<? super E> predicate) {
protected PredicatedCollection(final Collection<E> coll, final Predicate<? super E> predicate) {
super(coll);
if (predicate == null) {
throw new IllegalArgumentException("Predicate must not be null");
}
this.predicate = predicate;
for (E item : coll) {
for (final E item : coll) {
validate(item);
}
}
@ -95,7 +95,7 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
* @param object the object being added
* @throws IllegalArgumentException if the add is invalid
*/
protected void validate(E object) {
protected void validate(final E object) {
if (predicate.evaluate(object) == false) {
throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate '" +
predicate + "' rejected it");
@ -112,7 +112,7 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
* @throws IllegalArgumentException if the add is invalid
*/
@Override
public boolean add(E object) {
public boolean add(final E object) {
validate(object);
return decorated().add(object);
}
@ -127,8 +127,8 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
* @throws IllegalArgumentException if the add is invalid
*/
@Override
public boolean addAll(Collection<? extends E> coll) {
for (E item : coll) {
public boolean addAll(final Collection<? extends E> coll) {
for (final E item : coll) {
validate(item);
}
return decorated().addAll(coll);

View File

@ -56,7 +56,7 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
* @return a new synchronized collection
* @throws IllegalArgumentException if collection is null
*/
public static <T> SynchronizedCollection<T> synchronizedCollection(Collection<T> coll) {
public static <T> SynchronizedCollection<T> synchronizedCollection(final Collection<T> coll) {
return new SynchronizedCollection<T>(coll);
}
@ -67,7 +67,7 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
* @param collection the collection to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected SynchronizedCollection(Collection<E> collection) {
protected SynchronizedCollection(final Collection<E> collection) {
if (collection == null) {
throw new IllegalArgumentException("Collection must not be null");
}
@ -82,7 +82,7 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
* @param lock the lock object to use, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected SynchronizedCollection(Collection<E> collection, Object lock) {
protected SynchronizedCollection(final Collection<E> collection, final Object lock) {
if (collection == null) {
throw new IllegalArgumentException("Collection must not be null");
}
@ -101,13 +101,13 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
//-----------------------------------------------------------------------
public boolean add(E object) {
public boolean add(final E object) {
synchronized (lock) {
return decorated().add(object);
}
}
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
synchronized (lock) {
return decorated().addAll(coll);
}
@ -119,13 +119,13 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
}
}
public boolean contains(Object object) {
public boolean contains(final Object object) {
synchronized (lock) {
return decorated().contains(object);
}
}
public boolean containsAll(Collection<?> coll) {
public boolean containsAll(final Collection<?> coll) {
synchronized (lock) {
return decorated().containsAll(coll);
}
@ -157,25 +157,25 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
}
}
public <T> T[] toArray(T[] object) {
public <T> T[] toArray(final T[] object) {
synchronized (lock) {
return decorated().toArray(object);
}
}
public boolean remove(Object object) {
public boolean remove(final Object object) {
synchronized (lock) {
return decorated().remove(object);
}
}
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
synchronized (lock) {
return decorated().removeAll(coll);
}
}
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
synchronized (lock) {
return decorated().retainAll(coll);
}
@ -188,7 +188,7 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
}
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
synchronized (lock) {
if (object == this) {
return true;

View File

@ -57,8 +57,8 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
* @return a new transformed collection
* @throws IllegalArgumentException if collection or transformer is null
*/
public static <E> TransformedCollection<E> transformingCollection(Collection<E> coll,
Transformer<? super E, ? extends E> transformer) {
public static <E> TransformedCollection<E> transformingCollection(final Collection<E> coll,
final Transformer<? super E, ? extends E> transformer) {
return new TransformedCollection<E>(coll, transformer);
}
@ -77,15 +77,16 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
* @throws IllegalArgumentException if collection or transformer is null
* @since 3.3
*/
public static <E> TransformedCollection<E> transformedCollection(Collection<E> collection,
Transformer<? super E, ? extends E> transformer) {
TransformedCollection<E> decorated = new TransformedCollection<E>(collection, transformer);
public static <E> TransformedCollection<E> transformedCollection(final Collection<E> collection,
final Transformer<? super E, ? extends E> transformer) {
final TransformedCollection<E> decorated = new TransformedCollection<E>(collection, transformer);
// null collection & transformer are disallowed by the constructor call above
if (collection.size() > 0) {
@SuppressWarnings("unchecked") // collection is of type E
final
E[] values = (E[]) collection.toArray();
collection.clear();
for (E value : values) {
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
}
@ -103,7 +104,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if collection or transformer is null
*/
protected TransformedCollection(Collection<E> coll, Transformer<? super E, ? extends E> transformer) {
protected TransformedCollection(final Collection<E> coll, final Transformer<? super E, ? extends E> transformer) {
super(coll);
if (transformer == null) {
throw new IllegalArgumentException("Transformer must not be null");
@ -119,7 +120,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
* @param object the object to transform
* @return a transformed object
*/
protected E transform(E object) {
protected E transform(final E object) {
return transformer.transform(object);
}
@ -131,9 +132,9 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
* @param coll the collection to transform
* @return a transformed object
*/
protected Collection<E> transform(Collection<? extends E> coll) {
List<E> list = new ArrayList<E>(coll.size());
for (E item : coll) {
protected Collection<E> transform(final Collection<? extends E> coll) {
final List<E> list = new ArrayList<E>(coll.size());
for (final E item : coll) {
list.add(transform(item));
}
return list;
@ -141,12 +142,12 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
//-----------------------------------------------------------------------
@Override
public boolean add(E object) {
public boolean add(final E object) {
return decorated().add(transform(object));
}
@Override
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
return decorated().addAll(transform(coll));
}

View File

@ -53,7 +53,7 @@ public final class UnmodifiableBoundedCollection<E> extends AbstractCollectionDe
* @return a new unmodifiable bounded collection
* @throws IllegalArgumentException if {@code coll} is {@code null}
*/
public static <E> BoundedCollection<E> unmodifiableBoundedCollection(BoundedCollection<E> coll) {
public static <E> BoundedCollection<E> unmodifiableBoundedCollection(final BoundedCollection<E> coll) {
return new UnmodifiableBoundedCollection<E>(coll);
}
@ -98,7 +98,7 @@ public final class UnmodifiableBoundedCollection<E> extends AbstractCollectionDe
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if coll is null
*/
private UnmodifiableBoundedCollection(BoundedCollection<E> coll) {
private UnmodifiableBoundedCollection(final BoundedCollection<E> coll) {
super(coll);
}
@ -109,12 +109,12 @@ public final class UnmodifiableBoundedCollection<E> extends AbstractCollectionDe
}
@Override
public boolean add(E object) {
public boolean add(final E object) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@ -124,17 +124,17 @@ public final class UnmodifiableBoundedCollection<E> extends AbstractCollectionDe
}
@Override
public boolean remove(Object object) {
public boolean remove(final Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}

View File

@ -50,7 +50,7 @@ public final class UnmodifiableCollection<E>
* @return an unmodifiable collection
* @throws IllegalArgumentException if collection is null
*/
public static <T> Collection<T> unmodifiableCollection(Collection<T> coll) {
public static <T> Collection<T> unmodifiableCollection(final Collection<T> coll) {
if (coll instanceof Unmodifiable) {
return coll;
}
@ -64,7 +64,7 @@ public final class UnmodifiableCollection<E>
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if collection is null
*/
private UnmodifiableCollection(Collection<E> coll) {
private UnmodifiableCollection(final Collection<E> coll) {
super(coll);
}
@ -75,12 +75,12 @@ public final class UnmodifiableCollection<E>
}
@Override
public boolean add(E object) {
public boolean add(final E object) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> coll) {
public boolean addAll(final Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@ -90,17 +90,17 @@ public final class UnmodifiableCollection<E>
}
@Override
public boolean remove(Object object) {
public boolean remove(final Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> coll) {
public boolean removeAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> coll) {
public boolean retainAll(final Collection<?> coll) {
throw new UnsupportedOperationException();
}

View File

@ -92,7 +92,7 @@ public final class BooleanComparator implements Comparator<Boolean>, Serializabl
* <code>true</code> <code>Boolean</code>s before <code>false</code>
* @return a singleton BooleanComparator instance
*/
public static BooleanComparator booleanComparator(boolean trueFirst) {
public static BooleanComparator booleanComparator(final boolean trueFirst) {
return trueFirst ? TRUE_FIRST : FALSE_FIRST;
}
@ -119,7 +119,7 @@ public final class BooleanComparator implements Comparator<Boolean>, Serializabl
* @param trueFirst when <code>true</code>, sort
* <code>true</code> boolean values before <code>false</code>
*/
public BooleanComparator(boolean trueFirst) {
public BooleanComparator(final boolean trueFirst) {
this.trueFirst = trueFirst;
}
@ -133,9 +133,9 @@ public final class BooleanComparator implements Comparator<Boolean>, Serializabl
* @return negative if obj1 is less, positive if greater, zero if equal
* @throws NullPointerException when either argument <code>null</code>
*/
public int compare(Boolean b1, Boolean b2) {
boolean v1 = b1.booleanValue();
boolean v2 = b2.booleanValue();
public int compare(final Boolean b1, final Boolean b2) {
final boolean v1 = b1.booleanValue();
final boolean v2 = b2.booleanValue();
return (v1 ^ v2) ? ( (v1 ^ trueFirst) ? 1 : -1 ) : 0;
}
@ -149,7 +149,7 @@ public final class BooleanComparator implements Comparator<Boolean>, Serializabl
*/
@Override
public int hashCode() {
int hash = "BooleanComparator".hashCode();
final int hash = "BooleanComparator".hashCode();
return trueFirst ? -1 * hash : hash;
}
@ -166,7 +166,7 @@ public final class BooleanComparator implements Comparator<Boolean>, Serializabl
* @return true if equal
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
return (this == object) ||
((object instanceof BooleanComparator) &&
(this.trueFirst == ((BooleanComparator)object).trueFirst));

View File

@ -88,7 +88,7 @@ public class ComparableComparator<E extends Comparable<? super E>> implements Co
* @throws ClassCastException if <i>obj1</i> is not a <code>Comparable</code>,
* or when <code>((Comparable)obj1).compareTo(obj2)</code> does
*/
public int compare(E obj1, E obj2) {
public int compare(final E obj1, final E obj2) {
return obj1.compareTo(obj2);
}
@ -119,7 +119,7 @@ public class ComparableComparator<E extends Comparable<? super E>> implements Co
* @since 3.0
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
return this == object ||
null != object && object.getClass().equals(this.getClass());
}

View File

@ -76,7 +76,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
*
* @param comparator First comparator in the Comparator chain
*/
public ComparatorChain(Comparator<E> comparator) {
public ComparatorChain(final Comparator<E> comparator) {
this(comparator, false);
}
@ -87,7 +87,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @param comparator First Comparator in the ComparatorChain
* @param reverse false = forward sort; true = reverse sort
*/
public ComparatorChain(Comparator<E> comparator, boolean reverse) {
public ComparatorChain(final Comparator<E> comparator, final boolean reverse) {
comparatorChain = new ArrayList<Comparator<E>>(1);
comparatorChain.add(comparator);
orderingBits = new BitSet(1);
@ -104,7 +104,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @param list List of Comparators
* @see #ComparatorChain(List,BitSet)
*/
public ComparatorChain(List<Comparator<E>> list) {
public ComparatorChain(final List<Comparator<E>> list) {
this(list, new BitSet(list.size()));
}
@ -123,7 +123,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @param bits Sort order for each Comparator. Extra bits are ignored,
* unless extra Comparators are added by another method.
*/
public ComparatorChain(List<Comparator<E>> list, BitSet bits) {
public ComparatorChain(final List<Comparator<E>> list, final BitSet bits) {
comparatorChain = list;
orderingBits = bits;
}
@ -135,7 +135,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
*
* @param comparator Comparator with the forward sort order
*/
public void addComparator(Comparator<E> comparator) {
public void addComparator(final Comparator<E> comparator) {
addComparator(comparator, false);
}
@ -146,7 +146,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @param comparator Comparator to add to the end of the chain
* @param reverse false = forward sort order; true = reverse sort order
*/
public void addComparator(Comparator<E> comparator, boolean reverse) {
public void addComparator(final Comparator<E> comparator, final boolean reverse) {
checkLocked();
comparatorChain.add(comparator);
@ -164,7 +164,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @exception IndexOutOfBoundsException
* if index &lt; 0 or index &gt;= size()
*/
public void setComparator(int index, Comparator<E> comparator) throws IndexOutOfBoundsException {
public void setComparator(final int index, final Comparator<E> comparator) throws IndexOutOfBoundsException {
setComparator(index, comparator, false);
}
@ -176,7 +176,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @param comparator Comparator to set
* @param reverse false = forward sort order; true = reverse sort order
*/
public void setComparator(int index, Comparator<E> comparator, boolean reverse) {
public void setComparator(final int index, final Comparator<E> comparator, final boolean reverse) {
checkLocked();
comparatorChain.set(index,comparator);
@ -193,7 +193,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
*
* @param index Index of the ComparatorChain
*/
public void setForwardSort(int index) {
public void setForwardSort(final int index) {
checkLocked();
orderingBits.clear(index);
}
@ -204,7 +204,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
*
* @param index Index of the ComparatorChain
*/
public void setReverseSort(int index) {
public void setReverseSort(final int index) {
checkLocked();
orderingBits.set(index);
}
@ -265,17 +265,17 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* if the ComparatorChain does not contain at least one
* Comparator
*/
public int compare(E o1, E o2) throws UnsupportedOperationException {
public int compare(final E o1, final E o2) throws UnsupportedOperationException {
if (isLocked == false) {
checkChainIntegrity();
isLocked = true;
}
// iterate over all comparators in the chain
Iterator<Comparator<E>> comparators = comparatorChain.iterator();
final Iterator<Comparator<E>> comparators = comparatorChain.iterator();
for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex) {
Comparator<E> comparator = comparators.next();
final Comparator<E> comparator = comparators.next();
int retval = comparator.compare(o1,o2);
if (retval != 0) {
// invert the order if it is a reverse sort
@ -331,7 +331,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
* @since 3.0
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
if (this == object) {
return true;
}
@ -339,7 +339,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
return false;
}
if (object.getClass().equals(this.getClass())) {
ComparatorChain<?> chain = (ComparatorChain<?>) object;
final ComparatorChain<?> chain = (ComparatorChain<?>) object;
return (null == orderingBits ? null == chain.orderingBits : orderingBits
.equals(chain.orderingBits)) && (null == comparatorChain ? null == chain.comparatorChain
: comparatorChain.equals(chain.comparatorChain));

View File

@ -89,12 +89,12 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* @param items the items that the comparator can compare in order
* @throws IllegalArgumentException if the array is null
*/
public FixedOrderComparator(T[] items) {
public FixedOrderComparator(final T[] items) {
super();
if (items == null) {
throw new IllegalArgumentException("The list of items must not be null");
}
for (T item : items) {
for (final T item : items) {
add(item);
}
}
@ -108,12 +108,12 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* @param items the items that the comparator can compare in order
* @throws IllegalArgumentException if the list is null
*/
public FixedOrderComparator(List<T> items) {
public FixedOrderComparator(final List<T> items) {
super();
if (items == null) {
throw new IllegalArgumentException("The list of items must not be null");
}
for (T t : items) {
for (final T t : items) {
add(t);
}
}
@ -159,7 +159,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* @throws UnsupportedOperationException if a comparison has been performed
* @throws IllegalArgumentException if the unknown flag is not valid
*/
public void setUnknownObjectBehavior(UnknownObjectBehavior unknownObjectBehavior) {
public void setUnknownObjectBehavior(final UnknownObjectBehavior unknownObjectBehavior) {
checkLocked();
if (unknownObjectBehavior == null) {
throw new IllegalArgumentException("Unknown object behavior must not be null");
@ -179,9 +179,9 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* it was already known to the Comparator.
* @throws UnsupportedOperationException if a comparison has already been made
*/
public boolean add(T obj) {
public boolean add(final T obj) {
checkLocked();
Integer position = map.put(obj, new Integer(counter++));
final Integer position = map.put(obj, new Integer(counter++));
return position == null;
}
@ -198,13 +198,13 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* Comparator's set of known objects.
* @throws UnsupportedOperationException if a comparison has already been made
*/
public boolean addAsEqual(T existingObj, T newObj) {
public boolean addAsEqual(final T existingObj, final T newObj) {
checkLocked();
Integer position = map.get(existingObj);
final Integer position = map.get(existingObj);
if (position == null) {
throw new IllegalArgumentException(existingObj + " not known to " + this);
}
Integer result = map.put(newObj, position);
final Integer result = map.put(newObj, position);
return result == null;
}
@ -224,10 +224,10 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* to this Comparator and an alternative behavior has not been set
* via {@link #setUnknownObjectBehavior(UnknownObjectBehavior)}.
*/
public int compare(T obj1, T obj2) {
public int compare(final T obj1, final T obj2) {
isLocked = true;
Integer position1 = map.get(obj1);
Integer position2 = map.get(obj2);
final Integer position1 = map.get(obj1);
final Integer position2 = map.get(obj2);
if (position1 == null || position2 == null) {
switch (unknownObjectBehavior) {
case BEFORE:
@ -235,7 +235,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
case AFTER:
return position1 == null ? position2 == null ? 0 : 1 : -1;
case EXCEPTION:
Object unknownObj = position1 == null ? obj1 : obj2;
final Object unknownObj = position1 == null ? obj1 : obj2;
throw new IllegalArgumentException("Attempting to compare unknown object "
+ unknownObj);
default: //could be null
@ -276,7 +276,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
* @return true if equal
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
if (this == object) {
return true;
}
@ -284,7 +284,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
return false;
}
if (object.getClass().equals(this.getClass())) {
FixedOrderComparator<?> comp = (FixedOrderComparator<?>) object;
final FixedOrderComparator<?> comp = (FixedOrderComparator<?>) object;
return null == map ? null == comp.map : map.equals(comp.map) &&
null == unknownObjectBehavior ? null == comp.unknownObjectBehavior :
unknownObjectBehavior == comp.unknownObjectBehavior &&

View File

@ -69,7 +69,7 @@ public class NullComparator<E> implements Comparator<E>, Serializable {
* @exception NullPointerException if <code>nonNullComparator</code> is
* <code>null</code>
**/
public NullComparator(Comparator<E> nonNullComparator) {
public NullComparator(final Comparator<E> nonNullComparator) {
this(nonNullComparator, true);
}
@ -86,7 +86,7 @@ public class NullComparator<E> implements Comparator<E>, Serializable {
* non-<code>null</code> object.
**/
@SuppressWarnings("unchecked")
public NullComparator(boolean nullsAreHigh) {
public NullComparator(final boolean nullsAreHigh) {
this(ComparatorUtils.NATURAL_COMPARATOR, nullsAreHigh);
}
@ -109,7 +109,7 @@ public class NullComparator<E> implements Comparator<E>, Serializable {
* @exception NullPointerException if <code>nonNullComparator</code> is
* <code>null</code>
**/
public NullComparator(Comparator<E> nonNullComparator, boolean nullsAreHigh) {
public NullComparator(final Comparator<E> nonNullComparator, final boolean nullsAreHigh) {
this.nonNullComparator = nonNullComparator;
this.nullsAreHigh = nullsAreHigh;
@ -135,7 +135,7 @@ public class NullComparator<E> implements Comparator<E>, Serializable {
* "higher" than (greater than, after, etc.) <code>o2</code>; or
* <code>0</code> if <code>o1</code> and <code>o2</code> are equal.
**/
public int compare(E o1, E o2) {
public int compare(final E o1, final E o2) {
if(o1 == o2) { return 0; }
if(o1 == null) { return this.nullsAreHigh ? 1 : -1; }
if(o2 == null) { return this.nullsAreHigh ? -1 : 1; }
@ -166,12 +166,12 @@ public class NullComparator<E> implements Comparator<E>, Serializable {
* non-<code>null</code> object comparators.
**/
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if(obj == null) { return false; }
if(obj == this) { return true; }
if(!obj.getClass().equals(this.getClass())) { return false; }
NullComparator<?> other = (NullComparator<?>) obj;
final NullComparator<?> other = (NullComparator<?>) obj;
return this.nullsAreHigh == other.nullsAreHigh &&
this.nonNullComparator.equals(other.nonNullComparator);

View File

@ -61,7 +61,7 @@ public class ReverseComparator<E> implements Comparator<E>, Serializable {
* @param comparator Comparator to reverse
*/
@SuppressWarnings("unchecked")
public ReverseComparator(Comparator<E> comparator) {
public ReverseComparator(final Comparator<E> comparator) {
this.comparator = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : comparator;
}
@ -73,7 +73,7 @@ public class ReverseComparator<E> implements Comparator<E>, Serializable {
* @param obj2 the second object to compare
* @return negative if obj1 is less, positive if greater, zero if equal
*/
public int compare(E obj1, E obj2) {
public int compare(final E obj1, final E obj2) {
return comparator.compare(obj2, obj1);
}
@ -107,7 +107,7 @@ public class ReverseComparator<E> implements Comparator<E>, Serializable {
* @since 3.0
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
if (this == object) {
return true;
}
@ -115,7 +115,7 @@ public class ReverseComparator<E> implements Comparator<E>, Serializable {
return false;
}
if (object.getClass().equals(this.getClass())) {
ReverseComparator<?> thatrc = (ReverseComparator<?>) object;
final ReverseComparator<?> thatrc = (ReverseComparator<?>) object;
return comparator.equals(thatrc.comparator);
}
return false;

View File

@ -53,7 +53,7 @@ public class TransformingComparator<E> implements Comparator<E>, Serializable {
* @param transformer what will transform the arguments to <code>compare</code>
*/
@SuppressWarnings("unchecked")
public TransformingComparator(Transformer<? super E, ? extends E> transformer) {
public TransformingComparator(final Transformer<? super E, ? extends E> transformer) {
this(transformer, ComparatorUtils.NATURAL_COMPARATOR);
}
@ -63,7 +63,7 @@ public class TransformingComparator<E> implements Comparator<E>, Serializable {
* @param transformer what will transform the arguments to <code>compare</code>
* @param decorated the decorated Comparator
*/
public TransformingComparator(Transformer<? super E, ? extends E> transformer, Comparator<E> decorated) {
public TransformingComparator(final Transformer<? super E, ? extends E> transformer, final Comparator<E> decorated) {
this.decorated = decorated;
this.transformer = transformer;
}
@ -76,9 +76,9 @@ public class TransformingComparator<E> implements Comparator<E>, Serializable {
* @param obj2 the second object to transform then compare
* @return negative if obj1 is less, positive if greater, zero if equal
*/
public int compare(E obj1, E obj2) {
E value1 = this.transformer.transform(obj1);
E value2 = this.transformer.transform(obj2);
public int compare(final E obj1, final E obj2) {
final E value1 = this.transformer.transform(obj1);
final E value2 = this.transformer.transform(obj2);
return this.decorated.compare(value1, value2);
}
@ -110,7 +110,7 @@ public class TransformingComparator<E> implements Comparator<E>, Serializable {
* @return true if equal
*/
@Override
public boolean equals(Object object) {
public boolean equals(final Object object) {
if (this == object) {
return true;
}
@ -118,7 +118,7 @@ public class TransformingComparator<E> implements Comparator<E>, Serializable {
return false;
}
if (object.getClass().equals(this.getClass())) {
TransformingComparator<?> comp = (TransformingComparator<?>) object;
final TransformingComparator<?> comp = (TransformingComparator<?>) object;
return null == decorated ? null == comp.decorated : decorated.equals(comp.decorated) &&
null == transformer ? null == comp.transformer : transformer.equals(comp.transformer);
}

View File

@ -38,7 +38,7 @@ public class DeleteCommand<T> extends EditCommand<T> {
*
* @param object the object of the first sequence that should be deleted
*/
public DeleteCommand(T object) {
public DeleteCommand(final T object) {
super(object);
}
@ -49,7 +49,7 @@ public class DeleteCommand<T> extends EditCommand<T> {
* @param visitor the visitor to be accepted
*/
@Override
public void accept(CommandVisitor<T> visitor) {
public void accept(final CommandVisitor<T> visitor) {
visitor.visitDeleteCommand(object);
}
}

View File

@ -53,7 +53,7 @@ public abstract class EditCommand<T> {
* @param object reference to the object associated with this command, this
* refers to an element of one of the sequences being compared
*/
protected EditCommand(T object) {
protected EditCommand(final T object) {
this.object = object;
}

View File

@ -46,7 +46,7 @@ import java.util.List;
public class EditScript<T> {
/** Container for the commands. */
private List<EditCommand<T>> commands;
private final List<EditCommand<T>> commands;
/** Length of the longest common subsequence. */
private int lcsLength;
@ -68,7 +68,7 @@ public class EditScript<T> {
*
* @param command command to add
*/
public void append(KeepCommand<T> command) {
public void append(final KeepCommand<T> command) {
commands.add(command);
++lcsLength;
}
@ -78,7 +78,7 @@ public class EditScript<T> {
*
* @param command command to add
*/
public void append(InsertCommand<T> command) {
public void append(final InsertCommand<T> command) {
commands.add(command);
++modifications;
}
@ -88,7 +88,7 @@ public class EditScript<T> {
*
* @param command command to add
*/
public void append(DeleteCommand<T> command) {
public void append(final DeleteCommand<T> command) {
commands.add(command);
++modifications;
}
@ -102,8 +102,8 @@ public class EditScript<T> {
*
* @param visitor the visitor that will visit all commands in turn
*/
public void visit(CommandVisitor<T> visitor) {
for (EditCommand<T> command : commands) {
public void visit(final CommandVisitor<T> visitor) {
for (final EditCommand<T> command : commands) {
command.accept(visitor);
}
}

View File

@ -38,7 +38,7 @@ public class InsertCommand<T> extends EditCommand<T> {
*
* @param object the object of the second sequence that should be inserted
*/
public InsertCommand(T object) {
public InsertCommand(final T object) {
super(object);
}
@ -50,7 +50,7 @@ public class InsertCommand<T> extends EditCommand<T> {
* @param visitor the visitor to be accepted
*/
@Override
public void accept(CommandVisitor<T> visitor) {
public void accept(final CommandVisitor<T> visitor) {
visitor.visitInsertCommand(object);
}

View File

@ -40,7 +40,7 @@ public class KeepCommand<T> extends EditCommand<T> {
* reference to the instance in the first sequence which is known
* to be equal to an instance in the second sequence)
*/
public KeepCommand(T object) {
public KeepCommand(final T object) {
super(object);
}
@ -51,7 +51,7 @@ public class KeepCommand<T> extends EditCommand<T> {
* @param visitor the visitor to be accepted
*/
@Override
public void accept(CommandVisitor<T> visitor) {
public void accept(final CommandVisitor<T> visitor) {
visitor.visitKeepCommand(object);
}
}

View File

@ -50,19 +50,19 @@ import java.util.List;
*/
public class ReplacementsFinder<T> implements CommandVisitor<T> {
private List<T> pendingInsertions;
private List<T> pendingDeletions;
private final List<T> pendingInsertions;
private final List<T> pendingDeletions;
private int skipped;
/** Handler to call when synchronized sequences are found. */
private ReplacementsHandler<T> handler;
private final ReplacementsHandler<T> handler;
/**
* Simple constructor. Creates a new instance of {@link ReplacementsFinder}.
*
* @param handler handler to call when synchronized sequences are found
*/
public ReplacementsFinder(ReplacementsHandler<T> handler) {
public ReplacementsFinder(final ReplacementsHandler<T> handler) {
pendingInsertions = new ArrayList<T>();
pendingDeletions = new ArrayList<T>();
skipped = 0;
@ -74,7 +74,7 @@ public class ReplacementsFinder<T> implements CommandVisitor<T> {
*
* @param object object to insert
*/
public void visitInsertCommand(T object) {
public void visitInsertCommand(final T object) {
pendingInsertions.add(object);
}
@ -86,7 +86,7 @@ public class ReplacementsFinder<T> implements CommandVisitor<T> {
*
* @param object synchronization object detected
*/
public void visitKeepCommand(T object) {
public void visitKeepCommand(final T object) {
if (pendingDeletions.isEmpty() && pendingInsertions.isEmpty()) {
++skipped;
} else {
@ -102,7 +102,7 @@ public class ReplacementsFinder<T> implements CommandVisitor<T> {
*
* @param object object to delete
*/
public void visitDeleteCommand(T object) {
public void visitDeleteCommand(final T object) {
pendingDeletions.add(object);
}

View File

@ -56,14 +56,14 @@ import java.util.List;
public class SequencesComparator<T> {
/** First sequence. */
private List<T> sequence1;
private final List<T> sequence1;
/** Second sequence. */
private List<T> sequence2;
private final List<T> sequence2;
/** Temporary variables. */
private int[] vDown;
private int[] vUp;
private final int[] vDown;
private final int[] vUp;
/**
* Simple constructor.
@ -81,11 +81,11 @@ public class SequencesComparator<T> {
* @param sequence2
* second sequence to be compared
*/
public SequencesComparator(List<T> sequence1, List<T> sequence2) {
public SequencesComparator(final List<T> sequence1, final List<T> sequence2) {
this.sequence1 = sequence1;
this.sequence2 = sequence2;
int size = sequence1.size() + sequence2.size() + 2;
final int size = sequence1.size() + sequence2.size() + 2;
vDown = new int[size];
vUp = new int[size];
}
@ -99,7 +99,7 @@ public class SequencesComparator<T> {
* @param end2 the value of the end of the second sequence to be compared
* @return the snake built
*/
private Snake buildSnake(int start, int diag, int end1, int end2) {
private Snake buildSnake(final int start, final int diag, final int end1, final int end2) {
int end = start;
while (end - diag < end2
&& end < end1
@ -125,18 +125,18 @@ public class SequencesComparator<T> {
* @param end2 the end of the second sequence to be compared
* @return the middle snake
*/
private Snake getMiddleSnake(int start1, int end1, int start2, int end2) {
private Snake getMiddleSnake(final int start1, final int end1, final int start2, final int end2) {
// Myers Algorithm
// Initialisations
int m = end1 - start1;
int n = end2 - start2;
final int m = end1 - start1;
final int n = end2 - start2;
if (m == 0 || n == 0) {
return null;
}
int delta = m - n;
int sum = n + m;
int offset = (sum % 2 == 0 ? sum : sum + 1) / 2;
final int delta = m - n;
final int sum = n + m;
final int offset = (sum % 2 == 0 ? sum : sum + 1) / 2;
vDown[1+offset] = start1;
vUp[1+offset] = end1 + 1;
@ -145,7 +145,7 @@ public class SequencesComparator<T> {
for (int k = -d; k <= d; k += 2) {
// First step
int i = k + offset;
final int i = k + offset;
if (k == -d || k != d && vDown[i-1] < vDown[i+1]) {
vDown[i] = vDown[i+1];
} else {
@ -170,7 +170,7 @@ public class SequencesComparator<T> {
// Up
for (int k = delta - d; k <= delta + d; k += 2) {
// First step
int i = k + offset - delta;
final int i = k + offset - delta;
if (k == delta - d
|| k != delta + d && vUp[i+1] <= vUp[i-1]) {
vUp[i] = vUp[i+1] - 1;
@ -208,10 +208,10 @@ public class SequencesComparator<T> {
* @param end2 the end of the second sequence to be compared
* @param script the edited script
*/
private void buildScript(int start1, int end1, int start2, int end2,
EditScript<T> script) {
private void buildScript(final int start1, final int end1, final int start2, final int end2,
final EditScript<T> script) {
Snake middle = getMiddleSnake(start1, end1, start2, end2);
final Snake middle = getMiddleSnake(start1, end1, start2, end2);
if (middle == null
|| middle.getStart() == end1 && middle.getDiag() == end1 - end2
@ -263,7 +263,7 @@ public class SequencesComparator<T> {
* sequences
*/
public EditScript<T> getScript() {
EditScript<T> script = new EditScript<T>();
final EditScript<T> script = new EditScript<T>();
buildScript(0, sequence1.size(), 0, sequence2.size(), script);
return script;
}

View File

@ -30,13 +30,13 @@ package org.apache.commons.collections.comparators.sequence;
public class Snake {
/** Start index. */
private int start;
private final int start;
/** End index. */
private int end;
private final int end;
/** Diagonal number. */
private int diag;
private final int diag;
/**
* Simple constructor. Creates a new instance of Snake with default indices.
@ -54,7 +54,7 @@ public class Snake {
* @param end end index of the snake
* @param diag diagonal number
*/
public Snake(int start, int end, int diag) {
public Snake(final int start, final int end, final int diag) {
this.start = start;
this.end = end;
this.diag = diag;

View File

@ -56,7 +56,7 @@ public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @throws IllegalArgumentException if the predicates array is null
* @throws IllegalArgumentException if any predicate in the array is null
*/
public static <T> Predicate<T> allPredicate(Predicate<? super T> ... predicates) {
public static <T> Predicate<T> allPredicate(final Predicate<? super T> ... predicates) {
FunctorUtils.validate(predicates);
if (predicates.length == 0) {
return truePredicate();
@ -80,7 +80,7 @@ public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @throws IllegalArgumentException if the predicates array is null
* @throws IllegalArgumentException if any predicate in the array is null
*/
public static <T> Predicate<T> allPredicate(Collection<? extends Predicate<T>> predicates) {
public static <T> Predicate<T> allPredicate(final Collection<? extends Predicate<T>> predicates) {
final Predicate<T>[] preds = validate(predicates);
if (preds.length == 0) {
return truePredicate();
@ -97,7 +97,7 @@ public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T
*
* @param predicates the predicates to check, not cloned, not null
*/
public AllPredicate(Predicate<? super T> ... predicates) {
public AllPredicate(final Predicate<? super T> ... predicates) {
super();
iPredicates = predicates;
}
@ -108,8 +108,8 @@ public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @param object the input object
* @return true if all decorated predicates return true
*/
public boolean evaluate(T object) {
for (Predicate<? super T> iPredicate : iPredicates) {
public boolean evaluate(final T object) {
for (final Predicate<? super T> iPredicate : iPredicates) {
if (!iPredicate.evaluate(object)) {
return false;
}

View File

@ -45,7 +45,7 @@ public final class AndPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @return the <code>and</code> predicate
* @throws IllegalArgumentException if either predicate is null
*/
public static <T> Predicate<T> andPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) {
if (predicate1 == null || predicate2 == null) {
throw new IllegalArgumentException("Predicate must not be null");
}
@ -59,7 +59,7 @@ public final class AndPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @param predicate1 the first predicate to check, not null
* @param predicate2 the second predicate to check, not null
*/
public AndPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
public AndPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) {
super();
iPredicate1 = predicate1;
iPredicate2 = predicate2;
@ -71,7 +71,7 @@ public final class AndPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @param object the input object
* @return true if both decorated predicates return true
*/
public boolean evaluate(T object) {
public boolean evaluate(final T object) {
return iPredicate1.evaluate(object) && iPredicate2.evaluate(object);
}

View File

@ -53,7 +53,7 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @throws IllegalArgumentException if any predicate in the array is null
*/
@SuppressWarnings("unchecked")
public static <T> Predicate<T> anyPredicate(Predicate<? super T>... predicates) {
public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) {
FunctorUtils.validate(predicates);
if (predicates.length == 0) {
return FalsePredicate.<T>falsePredicate();
@ -77,8 +77,8 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @throws IllegalArgumentException if any predicate in the array is null
*/
@SuppressWarnings("unchecked")
public static <T> Predicate<T> anyPredicate(Collection<? extends Predicate<T>> predicates) {
Predicate<? super T>[] preds = FunctorUtils.validate(predicates);
public static <T> Predicate<T> anyPredicate(final Collection<? extends Predicate<T>> predicates) {
final Predicate<? super T>[] preds = FunctorUtils.validate(predicates);
if (preds.length == 0) {
return FalsePredicate.<T>falsePredicate();
}
@ -94,7 +94,7 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
*
* @param predicates the predicates to check, not cloned, not null
*/
public AnyPredicate(Predicate<? super T>[] predicates) {
public AnyPredicate(final Predicate<? super T>[] predicates) {
super();
iPredicates = predicates;
}
@ -105,8 +105,8 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @param object the input object
* @return true if any decorated predicate return true
*/
public boolean evaluate(T object) {
for (Predicate<? super T> iPredicate : iPredicates) {
public boolean evaluate(final T object) {
for (final Predicate<? super T> iPredicate : iPredicates) {
if (iPredicate.evaluate(object)) {
return true;
}

View File

@ -55,12 +55,12 @@ public abstract class CatchAndRethrowClosure<E> implements Closure<E> {
* @throws FunctorException (runtime) if the closure execution resulted in a
* checked exception.
*/
public void execute(E input) {
public void execute(final E input) {
try {
executeAndThrow(input);
} catch (RuntimeException ex) {
} catch (final RuntimeException ex) {
throw ex;
} catch (Throwable t) {
} catch (final Throwable t) {
throw new FunctorException(t);
}
}

View File

@ -44,7 +44,7 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
* @throws IllegalArgumentException if the closures array is null
* @throws IllegalArgumentException if any closure in the array is null
*/
public static <E> Closure<E> chainedClosure(Closure<? super E>... closures) {
public static <E> Closure<E> chainedClosure(final Closure<? super E>... closures) {
FunctorUtils.validate(closures);
if (closures.length == 0) {
return NOPClosure.<E>nopClosure();
@ -64,7 +64,7 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
* @throws IllegalArgumentException if any closure in the collection is null
*/
@SuppressWarnings("unchecked")
public static <E> Closure<E> chainedClosure(Collection<Closure<E>> closures) {
public static <E> Closure<E> chainedClosure(final Collection<Closure<E>> closures) {
if (closures == null) {
throw new IllegalArgumentException("Closure collection must not be null");
}
@ -72,9 +72,9 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
return NOPClosure.<E>nopClosure();
}
// convert to array like this to guarantee iterator() ordering
Closure<? super E>[] cmds = new Closure[closures.size()];
final Closure<? super E>[] cmds = new Closure[closures.size()];
int i = 0;
for (Closure<? super E> closure : closures) {
for (final Closure<? super E> closure : closures) {
cmds[i++] = closure;
}
FunctorUtils.validate(cmds);
@ -87,7 +87,7 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
*
* @param closures the closures to chain, not copied, no nulls
*/
public ChainedClosure(Closure<? super E>[] closures) {
public ChainedClosure(final Closure<? super E>[] closures) {
super();
iClosures = closures;
}
@ -97,8 +97,8 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
*
* @param input the input object passed to each closure
*/
public void execute(E input) {
for (Closure<? super E> iClosure : iClosures) {
public void execute(final E input) {
for (final Closure<? super E> iClosure : iClosures) {
iClosure.execute(input);
}
}

View File

@ -46,7 +46,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
* @throws IllegalArgumentException if the transformers array is null
* @throws IllegalArgumentException if any transformer in the array is null
*/
public static <T> Transformer<T, T> chainedTransformer(Transformer<? super T, ? extends T>... transformers) {
public static <T> Transformer<T, T> chainedTransformer(final Transformer<? super T, ? extends T>... transformers) {
FunctorUtils.validate(transformers);
if (transformers.length == 0) {
return NOPTransformer.<T>nopTransformer();
@ -65,7 +65,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
* @throws IllegalArgumentException if any transformer in the collection is null
*/
@SuppressWarnings("unchecked")
public static <T> Transformer<T, T> chainedTransformer(Collection<? extends Transformer<T, T>> transformers) {
public static <T> Transformer<T, T> chainedTransformer(final Collection<? extends Transformer<T, T>> transformers) {
if (transformers == null) {
throw new IllegalArgumentException("Transformer collection must not be null");
}
@ -73,7 +73,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
return NOPTransformer.<T>nopTransformer();
}
// convert to array like this to guarantee iterator() ordering
Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
FunctorUtils.validate(cmds);
return new ChainedTransformer<T>(cmds);
}
@ -84,7 +84,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
*
* @param transformers the transformers to chain, not copied, no nulls
*/
public ChainedTransformer(Transformer<? super T, ? extends T>[] transformers) {
public ChainedTransformer(final Transformer<? super T, ? extends T>[] transformers) {
super();
iTransformers = transformers;
}
@ -96,7 +96,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
* @return the transformed result
*/
public T transform(T object) {
for (Transformer<? super T, ? extends T> iTransformer : iTransformers) {
for (final Transformer<? super T, ? extends T> iTransformer : iTransformers) {
object = iTransformer.transform(object);
}
return object;

View File

@ -60,7 +60,7 @@ public class CloneTransformer<T> implements Transformer<T, T>, Serializable {
* @param input the input object to transform
* @return the transformed result
*/
public T transform(T input) {
public T transform(final T input) {
if (input == null) {
return null;
}

View File

@ -43,7 +43,7 @@ public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {
* @return the <code>closure</code> transformer
* @throws IllegalArgumentException if the closure is null
*/
public static <T> Transformer<T, T> closureTransformer(Closure<? super T> closure) {
public static <T> Transformer<T, T> closureTransformer(final Closure<? super T> closure) {
if (closure == null) {
throw new IllegalArgumentException("Closure must not be null");
}
@ -56,7 +56,7 @@ public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {
*
* @param closure the closure to call, not null
*/
public ClosureTransformer(Closure<? super T> closure) {
public ClosureTransformer(final Closure<? super T> closure) {
super();
iClosure = closure;
}
@ -67,7 +67,7 @@ public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {
* @param input the input object to transform
* @return the transformed result
*/
public T transform(T input) {
public T transform(final T input) {
iClosure.execute(input);
return input;
}

View File

@ -104,7 +104,7 @@ public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
* @return the predicate
* @throws IllegalArgumentException if comparator is null
*/
public static <T> Predicate<T> comparatorPredicate(T object, Comparator<T> comparator) {
public static <T> Predicate<T> comparatorPredicate(final T object, final Comparator<T> comparator) {
return comparatorPredicate(object, comparator, Criterion.EQUAL);
}
@ -118,7 +118,7 @@ public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
* @return the predicate
* @throws IllegalArgumentException if comparator is null of criterion is invalid
*/
public static <T> Predicate<T> comparatorPredicate(T object, Comparator<T> comparator, Criterion criterion) {
public static <T> Predicate<T> comparatorPredicate(final T object, final Comparator<T> comparator, final Criterion criterion) {
if (comparator == null) {
throw new IllegalArgumentException("Comparator must not be null.");
}
@ -136,7 +136,7 @@ public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
* @param comparator the comparator to use for comparison
* @param criterion the criterion to use to evaluate comparison
*/
public ComparatorPredicate(T object, Comparator<T> comparator, Criterion criterion) {
public ComparatorPredicate(final T object, final Comparator<T> comparator, final Criterion criterion) {
super();
this.object = object;
this.comparator = comparator;
@ -159,10 +159,10 @@ public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
*
* @throws IllegalStateException if the criterion is invalid (really not possible)
*/
public boolean evaluate(T target) {
public boolean evaluate(final T target) {
boolean result = false;
int comparison = comparator.compare(object, target);
final int comparison = comparator.compare(object, target);
switch (criterion) {
case EQUAL:
result = comparison == 0;

View File

@ -48,7 +48,7 @@ public class ConstantFactory<T> implements Factory<T>, Serializable {
* @return the <code>constant</code> factory.
*/
@SuppressWarnings("unchecked")
public static <T> Factory<T> constantFactory(T constantToReturn) {
public static <T> Factory<T> constantFactory(final T constantToReturn) {
if (constantToReturn == null) {
return (Factory<T>) NULL_INSTANCE;
}
@ -61,7 +61,7 @@ public class ConstantFactory<T> implements Factory<T>, Serializable {
*
* @param constantToReturn the constant to return each time
*/
public ConstantFactory(T constantToReturn) {
public ConstantFactory(final T constantToReturn) {
super();
iConstant = constantToReturn;
}

View File

@ -58,7 +58,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
* @param constantToReturn the constant object to return each time in the factory
* @return the <code>constant</code> factory.
*/
public static <I, O> Transformer<I, O> constantTransformer(O constantToReturn) {
public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) {
if (constantToReturn == null) {
return nullTransformer();
}
@ -71,7 +71,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
*
* @param constantToReturn the constant to return each time
*/
public ConstantTransformer(O constantToReturn) {
public ConstantTransformer(final O constantToReturn) {
super();
iConstant = constantToReturn;
}
@ -82,7 +82,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
* @param input the input object which is ignored
* @return the stored constant
*/
public O transform(I input) {
public O transform(final I input) {
return iConstant;
}
@ -100,14 +100,14 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ConstantTransformer == false) {
return false;
}
Object otherConstant = ((ConstantTransformer<?, ?>) obj).getConstant();
final Object otherConstant = ((ConstantTransformer<?, ?>) obj).getConstant();
return otherConstant == getConstant() || otherConstant != null && otherConstant.equals(getConstant());
}

View File

@ -35,7 +35,7 @@ public class DefaultEquator<T> implements Equator<T> {
/**
* {@inheritDoc} Delegates to {@link Object#equals(Object)}.
*/
public boolean equate(T o1, T o2) {
public boolean equate(final T o1, final T o2) {
return o1 == o2 || o1 != null && o1.equals(o2);
}
@ -45,7 +45,7 @@ public class DefaultEquator<T> implements Equator<T> {
* @return <code>o.hashCode()</code> if <code>o</code> is non-
* <code>null</code>, else {@link #HASHCODE_NULL}.
*/
public int hash(T o) {
public int hash(final T o) {
return o == null ? HASHCODE_NULL : o.hashCode();
}

View File

@ -48,7 +48,7 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
* @return the predicate
* @throws IllegalArgumentException if the predicate is null
*/
public static <T> Predicate<T> equalPredicate(T object) {
public static <T> Predicate<T> equalPredicate(final T object) {
if (object == null) {
return nullPredicate();
}
@ -65,7 +65,7 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
* @throws IllegalArgumentException if the predicate is null
* @since 4.0
*/
public static <T> Predicate<T> equalPredicate(T object, Equator<T> equator) {
public static <T> Predicate<T> equalPredicate(final T object, final Equator<T> equator) {
if (object == null) {
return nullPredicate();
}
@ -78,7 +78,7 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
*
* @param object the object to compare to
*/
public EqualPredicate(T object) {
public EqualPredicate(final T object) {
// do not use the DefaultEquator to keep backwards compatibility
// the DefaultEquator returns also true if the two object references are equal
this(object, null);
@ -92,7 +92,7 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
* @param equator the equator to use for comparison
* @since 4.0
*/
public EqualPredicate(T object, Equator<T> equator) {
public EqualPredicate(final T object, final Equator<T> equator) {
super();
iValue = object;
this.equator = equator;
@ -104,7 +104,7 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
* @param object the input object
* @return true if input object equals stored value
*/
public boolean evaluate(T object) {
public boolean evaluate(final T object) {
if (equator != null) {
return equator.equate(iValue, object);
} else {

View File

@ -60,7 +60,7 @@ public final class ExceptionClosure<E> implements Closure<E>, Serializable {
* @param input the input object
* @throws FunctorException always
*/
public void execute(E input) {
public void execute(final E input) {
throw new FunctorException("ExceptionClosure invoked");
}

View File

@ -60,7 +60,7 @@ public final class ExceptionPredicate<T> implements Predicate<T>, Serializable {
* @return never
* @throws FunctorException always
*/
public boolean evaluate(T object) {
public boolean evaluate(final T object) {
throw new FunctorException("ExceptionPredicate invoked");
}

View File

@ -60,7 +60,7 @@ public final class ExceptionTransformer<I, O> implements Transformer<I, O>, Seri
* @return never
* @throws FunctorException always
*/
public O transform(I input) {
public O transform(final I input) {
throw new FunctorException("ExceptionTransformer invoked");
}

View File

@ -42,7 +42,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
* @return the <code>factory</code> transformer
* @throws IllegalArgumentException if the factory is null
*/
public static <I, O> Transformer<I, O> factoryTransformer(Factory<? extends O> factory) {
public static <I, O> Transformer<I, O> factoryTransformer(final Factory<? extends O> factory) {
if (factory == null) {
throw new IllegalArgumentException("Factory must not be null");
}
@ -55,7 +55,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
*
* @param factory the factory to call, not null
*/
public FactoryTransformer(Factory<? extends O> factory) {
public FactoryTransformer(final Factory<? extends O> factory) {
super();
iFactory = factory;
}
@ -67,7 +67,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
* @param input the input object to transform
* @return the transformed result
*/
public O transform(I input) {
public O transform(final I input) {
return iFactory.create();
}

View File

@ -59,7 +59,7 @@ public final class FalsePredicate<T> implements Predicate<T>, Serializable {
* @param object the input object
* @return false always
*/
public boolean evaluate(T object) {
public boolean evaluate(final T object) {
return false;
}

View File

@ -48,7 +48,7 @@ public class ForClosure<E> implements Closure<E>, Serializable {
* @return the <code>for</code> closure
*/
@SuppressWarnings("unchecked")
public static <E> Closure<E> forClosure(int count, Closure<? super E> closure) {
public static <E> Closure<E> forClosure(final int count, final Closure<? super E> closure) {
if (count <= 0 || closure == null) {
return NOPClosure.<E>nopClosure();
}
@ -65,7 +65,7 @@ public class ForClosure<E> implements Closure<E>, Serializable {
* @param count the number of times to execute the closure
* @param closure the closure to execute, not null
*/
public ForClosure(int count, Closure<? super E> closure) {
public ForClosure(final int count, final Closure<? super E> closure) {
super();
iCount = count;
iClosure = closure;
@ -76,7 +76,7 @@ public class ForClosure<E> implements Closure<E>, Serializable {
*
* @param input the input object
*/
public void execute(E input) {
public void execute(final E input) {
for (int i = 0; i < iCount; i++) {
iClosure.execute(input);
}

View File

@ -46,7 +46,7 @@ class FunctorUtils {
* @return the cloned predicates
*/
@SuppressWarnings("unchecked")
static <T> Predicate<T>[] copy(Predicate<? super T>[] predicates) {
static <T> Predicate<T>[] copy(final Predicate<? super T>[] predicates) {
if (predicates == null) {
return null;
}
@ -66,7 +66,7 @@ class FunctorUtils {
* @return the coerced predicate.
*/
@SuppressWarnings("unchecked")
static <T> Predicate<T> coerce(Predicate<? super T> predicate){
static <T> Predicate<T> coerce(final Predicate<? super T> predicate){
return (Predicate<T>) predicate;
}
@ -75,7 +75,7 @@ class FunctorUtils {
*
* @param predicates the predicates to validate
*/
static void validate(Predicate<?>[] predicates) {
static void validate(final Predicate<?>[] predicates) {
if (predicates == null) {
throw new IllegalArgumentException("The predicate array must not be null");
}
@ -93,15 +93,16 @@ class FunctorUtils {
* @param predicates the predicates to validate
* @return predicate array
*/
static <T> Predicate<T>[] validate(Collection<? extends Predicate<T>> predicates) {
static <T> Predicate<T>[] validate(final Collection<? extends Predicate<T>> predicates) {
if (predicates == null) {
throw new IllegalArgumentException("The predicate collection must not be null");
}
// convert to array like this to guarantee iterator() ordering
@SuppressWarnings("unchecked") // OK
final
Predicate<T>[] preds = new Predicate[predicates.size()];
int i = 0;
for (Predicate<T> predicate : predicates) {
for (final Predicate<T> predicate : predicates) {
preds[i] = predicate;
if (preds[i] == null) {
throw new IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null");
@ -118,7 +119,7 @@ class FunctorUtils {
* @return the cloned closures
*/
@SuppressWarnings("unchecked")
static <E> Closure<E>[] copy(Closure<? super E>[] closures) {
static <E> Closure<E>[] copy(final Closure<? super E>[] closures) {
if (closures == null) {
return null;
}
@ -130,7 +131,7 @@ class FunctorUtils {
*
* @param closures the closures to validate
*/
static void validate(Closure<?>[] closures) {
static void validate(final Closure<?>[] closures) {
if (closures == null) {
throw new IllegalArgumentException("The closure array must not be null");
}
@ -152,7 +153,7 @@ class FunctorUtils {
* @return the coerced closure.
*/
@SuppressWarnings("unchecked")
static <T> Closure<T> coerce(Closure<? super T> closure){
static <T> Closure<T> coerce(final Closure<? super T> closure){
return (Closure<T>) closure;
}
@ -163,7 +164,7 @@ class FunctorUtils {
* @return a clone of the transformers
*/
@SuppressWarnings("unchecked")
static <I, O> Transformer<I, O>[] copy(Transformer<? super I, ? extends O>[] transformers) {
static <I, O> Transformer<I, O>[] copy(final Transformer<? super I, ? extends O>[] transformers) {
if (transformers == null) {
return null;
}
@ -175,7 +176,7 @@ class FunctorUtils {
*
* @param transformers the transformers to validate
*/
static void validate(Transformer<?, ?>[] transformers) {
static void validate(final Transformer<?, ?>[] transformers) {
if (transformers == null) {
throw new IllegalArgumentException("The transformer array must not be null");
}
@ -198,7 +199,7 @@ class FunctorUtils {
* @return the coerced transformer.
*/
@SuppressWarnings("unchecked")
static <I, O> Transformer<I, O> coerce(Transformer<? super I, ? extends O> transformer) {
static <I, O> Transformer<I, O> coerce(final Transformer<? super I, ? extends O> transformer) {
return (Transformer<I, O>) transformer;
}

View File

@ -43,7 +43,7 @@ public final class IdentityPredicate<T> implements Predicate<T>, Serializable {
* @return the predicate
* @throws IllegalArgumentException if the predicate is null
*/
public static <T> Predicate<T> identityPredicate(T object) {
public static <T> Predicate<T> identityPredicate(final T object) {
if (object == null) {
return NullPredicate.<T>nullPredicate();
}
@ -56,7 +56,7 @@ public final class IdentityPredicate<T> implements Predicate<T>, Serializable {
*
* @param object the object to compare to
*/
public IdentityPredicate(T object) {
public IdentityPredicate(final T object) {
super();
iValue = object;
}
@ -68,7 +68,7 @@ public final class IdentityPredicate<T> implements Predicate<T>, Serializable {
* @param object the input object
* @return true if input is the same object as the stored value
*/
public boolean evaluate(T object) {
public boolean evaluate(final T object) {
return iValue == object;
}

View File

@ -53,7 +53,7 @@ public class IfClosure<E> implements Closure<E>, Serializable {
* @throws IllegalArgumentException if either argument is null
* @since 3.2
*/
public static <E> Closure<E> ifClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure) {
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure) {
return IfClosure.<E>ifClosure(predicate, trueClosure, NOPClosure.<E>nopClosure());
}
@ -67,9 +67,9 @@ public class IfClosure<E> implements Closure<E>, Serializable {
* @return the <code>if</code> closure
* @throws IllegalArgumentException if any argument is null
*/
public static <E> Closure<E> ifClosure(Predicate<? super E> predicate,
Closure<? super E> trueClosure,
Closure<? super E> falseClosure) {
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate,
final Closure<? super E> trueClosure,
final Closure<? super E> falseClosure) {
if (predicate == null) {
throw new IllegalArgumentException("Predicate must not be null");
}
@ -90,7 +90,7 @@ public class IfClosure<E> implements Closure<E>, Serializable {
* @param trueClosure closure used if true, not null
* @since 3.2
*/
public IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure) {
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure) {
this(predicate, trueClosure, NOPClosure.INSTANCE);
}
@ -102,7 +102,7 @@ public class IfClosure<E> implements Closure<E>, Serializable {
* @param trueClosure closure used if true, not null
* @param falseClosure closure used if false, not null
*/
public IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure) {
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure, final Closure<? super E> falseClosure) {
super();
iPredicate = predicate;
iTrueClosure = trueClosure;
@ -114,7 +114,7 @@ public class IfClosure<E> implements Closure<E>, Serializable {
*
* @param input the input object
*/
public void execute(E input) {
public void execute(final E input) {
if (iPredicate.evaluate(input)) {
iTrueClosure.execute(input);
} else {

Some files were not shown because too many files have changed in this diff Show More