mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-17 15:35:00 +00:00
No need to nest in an else clause.
This commit is contained in:
parent
92c5e6f1e1
commit
8b66a577f4
@ -87,9 +87,8 @@ public class ArrayStack<E> extends ArrayList<E> {
|
|||||||
final int n = size();
|
final int n = size();
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
throw new EmptyStackException();
|
throw new EmptyStackException();
|
||||||
} else {
|
|
||||||
return get(n - 1);
|
|
||||||
}
|
}
|
||||||
|
return get(n - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,9 +104,8 @@ public class ArrayStack<E> extends ArrayList<E> {
|
|||||||
final int m = (size() - n) - 1;
|
final int m = (size() - n) - 1;
|
||||||
if (m < 0) {
|
if (m < 0) {
|
||||||
throw new EmptyStackException();
|
throw new EmptyStackException();
|
||||||
} else {
|
|
||||||
return get(m);
|
|
||||||
}
|
}
|
||||||
|
return get(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,9 +118,8 @@ public class ArrayStack<E> extends ArrayList<E> {
|
|||||||
final int n = size();
|
final int n = size();
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
throw new EmptyStackException();
|
throw new EmptyStackException();
|
||||||
} else {
|
|
||||||
return remove(n - 1);
|
|
||||||
}
|
}
|
||||||
|
return remove(n - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -368,30 +368,29 @@ public class CollectionUtils {
|
|||||||
public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) {
|
public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) {
|
||||||
if (coll2.isEmpty()) {
|
if (coll2.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
final Iterator<?> it = coll1.iterator();
|
final Iterator<?> it = coll1.iterator();
|
||||||
final Set<Object> elementsAlreadySeen = new HashSet<>();
|
final Set<Object> elementsAlreadySeen = new HashSet<>();
|
||||||
for (final Object nextElement : coll2) {
|
for (final Object nextElement : coll2) {
|
||||||
if (elementsAlreadySeen.contains(nextElement)) {
|
if (elementsAlreadySeen.contains(nextElement)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean foundCurrentElement = false;
|
boolean foundCurrentElement = false;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
final Object p = it.next();
|
final Object p = it.next();
|
||||||
elementsAlreadySeen.add(p);
|
elementsAlreadySeen.add(p);
|
||||||
if (nextElement == null ? p == null : nextElement.equals(p)) {
|
if (nextElement == null ? p == null : nextElement.equals(p)) {
|
||||||
foundCurrentElement = true;
|
foundCurrentElement = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundCurrentElement) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
if (!foundCurrentElement) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1584,21 +1583,20 @@ public class CollectionUtils {
|
|||||||
final Iterator<O> iterator = new CollatingIterator<>(c, a.iterator(), b.iterator());
|
final Iterator<O> iterator = new CollatingIterator<>(c, a.iterator(), b.iterator());
|
||||||
if (includeDuplicates) {
|
if (includeDuplicates) {
|
||||||
return IteratorUtils.toList(iterator, totalSize);
|
return IteratorUtils.toList(iterator, totalSize);
|
||||||
} else {
|
|
||||||
final ArrayList<O> mergedList = new ArrayList<>(totalSize);
|
|
||||||
|
|
||||||
O lastItem = null;
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
final O item = iterator.next();
|
|
||||||
if (lastItem == null || !lastItem.equals(item)) {
|
|
||||||
mergedList.add(item);
|
|
||||||
}
|
|
||||||
lastItem = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
mergedList.trimToSize();
|
|
||||||
return mergedList;
|
|
||||||
}
|
}
|
||||||
|
final ArrayList<O> mergedList = new ArrayList<>(totalSize);
|
||||||
|
|
||||||
|
O lastItem = null;
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
final O item = iterator.next();
|
||||||
|
if (lastItem == null || !lastItem.equals(item)) {
|
||||||
|
mergedList.add(item);
|
||||||
|
}
|
||||||
|
lastItem = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedList.trimToSize();
|
||||||
|
return mergedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -57,9 +57,8 @@ public class EnumerationUtils {
|
|||||||
i--;
|
i--;
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
return e.nextElement();
|
return e.nextElement();
|
||||||
} else {
|
|
||||||
e.nextElement();
|
|
||||||
}
|
}
|
||||||
|
e.nextElement();
|
||||||
}
|
}
|
||||||
throw new IndexOutOfBoundsException("Entry does not exist: " + i);
|
throw new IndexOutOfBoundsException("Entry does not exist: " + i);
|
||||||
}
|
}
|
||||||
|
@ -124,9 +124,8 @@ public class FluentIterable<E> implements Iterable<E> {
|
|||||||
IterableUtils.checkNotNull(iterable);
|
IterableUtils.checkNotNull(iterable);
|
||||||
if (iterable instanceof FluentIterable<?>) {
|
if (iterable instanceof FluentIterable<?>) {
|
||||||
return (FluentIterable<T>) iterable;
|
return (FluentIterable<T>) iterable;
|
||||||
} else {
|
|
||||||
return new FluentIterable<>(iterable);
|
|
||||||
}
|
}
|
||||||
|
return new FluentIterable<>(iterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -175,9 +175,8 @@ public class IterableUtils {
|
|||||||
protected Iterator<? extends E> nextIterator(int count) {
|
protected Iterator<? extends E> nextIterator(int count) {
|
||||||
if (count > iterables.length) {
|
if (count > iterables.length) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
return iterables[count - 1].iterator();
|
|
||||||
}
|
}
|
||||||
|
return iterables[count - 1].iterator();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -328,9 +327,8 @@ public class IterableUtils {
|
|||||||
protected Iterator<? extends E> nextIterator(int count) {
|
protected Iterator<? extends E> nextIterator(int count) {
|
||||||
if (IterableUtils.isEmpty(iterable)) {
|
if (IterableUtils.isEmpty(iterable)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
return iterable.iterator();
|
|
||||||
}
|
}
|
||||||
|
return iterable.iterator();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -690,9 +688,8 @@ public class IterableUtils {
|
|||||||
public static boolean isEmpty(final Iterable<?> iterable) {
|
public static boolean isEmpty(final Iterable<?> iterable) {
|
||||||
if (iterable instanceof Collection<?>) {
|
if (iterable instanceof Collection<?>) {
|
||||||
return ((Collection<?>) iterable).isEmpty();
|
return ((Collection<?>) iterable).isEmpty();
|
||||||
} else {
|
|
||||||
return IteratorUtils.isEmpty(emptyIteratorIfNull(iterable));
|
|
||||||
}
|
}
|
||||||
|
return IteratorUtils.isEmpty(emptyIteratorIfNull(iterable));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -708,9 +705,8 @@ public class IterableUtils {
|
|||||||
public static <E> boolean contains(final Iterable<E> iterable, final Object object) {
|
public static <E> boolean contains(final Iterable<E> iterable, final Object object) {
|
||||||
if (iterable instanceof Collection<?>) {
|
if (iterable instanceof Collection<?>) {
|
||||||
return ((Collection<E>) iterable).contains(object);
|
return ((Collection<E>) iterable).contains(object);
|
||||||
} else {
|
|
||||||
return IteratorUtils.contains(emptyIteratorIfNull(iterable), object);
|
|
||||||
}
|
}
|
||||||
|
return IteratorUtils.contains(emptyIteratorIfNull(iterable), object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -788,9 +784,8 @@ public class IterableUtils {
|
|||||||
public static int size(final Iterable<?> iterable) {
|
public static int size(final Iterable<?> iterable) {
|
||||||
if (iterable instanceof Collection<?>) {
|
if (iterable instanceof Collection<?>) {
|
||||||
return ((Collection<?>) iterable).size();
|
return ((Collection<?>) iterable).size();
|
||||||
} else {
|
|
||||||
return IteratorUtils.size(emptyIteratorIfNull(iterable));
|
|
||||||
}
|
}
|
||||||
|
return IteratorUtils.size(emptyIteratorIfNull(iterable));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,10 +177,9 @@ public final class CollectionBag<E> extends AbstractBagDecorator<E> {
|
|||||||
result = result || changed;
|
result = result || changed;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
|
||||||
// let the decorated bag handle the case of null argument
|
|
||||||
return decorated().removeAll(null);
|
|
||||||
}
|
}
|
||||||
|
// let the decorated bag handle the case of null argument
|
||||||
|
return decorated().removeAll(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,10 +211,9 @@ public final class CollectionBag<E> extends AbstractBagDecorator<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return modified;
|
return modified;
|
||||||
} else {
|
|
||||||
// let the decorated bag handle the case of null argument
|
|
||||||
return decorated().retainAll(null);
|
|
||||||
}
|
}
|
||||||
|
// let the decorated bag handle the case of null argument
|
||||||
|
return decorated().retainAll(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -130,10 +130,9 @@ public final class CollectionSortedBag<E> extends AbstractSortedBagDecorator<E>
|
|||||||
result = result || changed;
|
result = result || changed;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
|
||||||
// let the decorated bag handle the case of null argument
|
|
||||||
return decorated().removeAll(null);
|
|
||||||
}
|
}
|
||||||
|
// let the decorated bag handle the case of null argument
|
||||||
|
return decorated().removeAll(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -148,10 +147,9 @@ public final class CollectionSortedBag<E> extends AbstractSortedBagDecorator<E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return modified;
|
return modified;
|
||||||
} else {
|
|
||||||
// let the decorated bag handle the case of null argument
|
|
||||||
return decorated().retainAll(null);
|
|
||||||
}
|
}
|
||||||
|
// let the decorated bag handle the case of null argument
|
||||||
|
return decorated().retainAll(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -590,9 +590,8 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>>
|
|||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
rval = node;
|
rval = node;
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
node = cmp < 0 ? node.getLeft(dataElement) : node.getRight(dataElement);
|
|
||||||
}
|
}
|
||||||
|
node = cmp < 0 ? node.getLeft(dataElement) : node.getRight(dataElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
|
@ -104,9 +104,8 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
|
|||||||
public boolean evaluate(final T object) {
|
public boolean evaluate(final T object) {
|
||||||
if (equator != null) {
|
if (equator != null) {
|
||||||
return equator.equate(iValue, object);
|
return equator.equate(iValue, object);
|
||||||
} else {
|
|
||||||
return iValue.equals(object);
|
|
||||||
}
|
}
|
||||||
|
return iValue.equals(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,9 +120,8 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
|||||||
public O transform(final I input) {
|
public O transform(final I input) {
|
||||||
if(iPredicate.evaluate(input)){
|
if(iPredicate.evaluate(input)){
|
||||||
return iTrueTransformer.transform(input);
|
return iTrueTransformer.transform(input);
|
||||||
} else {
|
|
||||||
return iFalseTransformer.transform(input);
|
|
||||||
}
|
}
|
||||||
|
return iFalseTransformer.transform(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,10 +116,9 @@ public class ZippingIterator<E> implements Iterator<E> {
|
|||||||
if (childIterator.hasNext()) {
|
if (childIterator.hasNext()) {
|
||||||
nextIterator = childIterator;
|
nextIterator = childIterator;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
// iterator is exhausted, remove it
|
|
||||||
iterators.remove();
|
|
||||||
}
|
}
|
||||||
|
// iterator is exhausted, remove it
|
||||||
|
iterators.remove();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -259,12 +259,10 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
if (coll.add(value)) {
|
if (coll.add(value)) {
|
||||||
map.put(key, coll);
|
map.put(key, coll);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
return false;
|
||||||
return coll.add(value);
|
|
||||||
}
|
}
|
||||||
|
return coll.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,10 +353,9 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
if (values instanceof Collection<?>) {
|
if (values instanceof Collection<?>) {
|
||||||
Collection<? extends V> valueCollection = (Collection<? extends V>) values;
|
Collection<? extends V> valueCollection = (Collection<? extends V>) values;
|
||||||
return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
|
return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
|
||||||
} else {
|
|
||||||
Iterator<? extends V> it = values.iterator();
|
|
||||||
return it.hasNext() && CollectionUtils.addAll(get(key), it);
|
|
||||||
}
|
}
|
||||||
|
Iterator<? extends V> it = values.iterator();
|
||||||
|
return it.hasNext() && CollectionUtils.addAll(get(key), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -568,9 +568,8 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
public boolean equate(final Integer o1, final Integer o2) {
|
public boolean equate(final Integer o1, final Integer o2) {
|
||||||
if (o1.intValue() % 2 == 0 ^ o2.intValue() % 2 == 0) {
|
if (o1.intValue() % 2 == 0 ^ o2.intValue() % 2 == 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,9 +171,8 @@ public class DualTreeBidiMap2Test<K extends Comparable<K>, V extends Comparable<
|
|||||||
preTail + "bulkTestMapValues.testCollectionRemoveAll",
|
preTail + "bulkTestMapValues.testCollectionRemoveAll",
|
||||||
preTail + "bulkTestMapValues.testCollectionRetainAll"
|
preTail + "bulkTestMapValues.testCollectionRetainAll"
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
return new String[] { recursiveTest };
|
|
||||||
}
|
}
|
||||||
|
return new String[] { recursiveTest };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,9 +65,8 @@ public class DualTreeBidiMapTest<K extends Comparable<K>, V extends Comparable<V
|
|||||||
preTail + "bulkTestMapValues.testCollectionRemoveAll",
|
preTail + "bulkTestMapValues.testCollectionRemoveAll",
|
||||||
preTail + "bulkTestMapValues.testCollectionRetainAll"
|
preTail + "bulkTestMapValues.testCollectionRetainAll"
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
return new String[] { recursiveTest };
|
|
||||||
}
|
}
|
||||||
|
return new String[] { recursiveTest };
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testCreate() throws Exception {
|
// public void testCreate() throws Exception {
|
||||||
|
@ -80,13 +80,12 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
|
|||||||
|
|
||||||
if (createIteratorWithStandardConstr) {
|
if (createIteratorWithStandardConstr) {
|
||||||
return new NodeListIterator(emptyNodeList);
|
return new NodeListIterator(emptyNodeList);
|
||||||
} else {
|
|
||||||
final Node parentNode = createMock(Node.class);
|
|
||||||
expect(parentNode.getChildNodes()).andStubReturn(emptyNodeList);
|
|
||||||
replay(parentNode);
|
|
||||||
|
|
||||||
return new NodeListIterator(parentNode);
|
|
||||||
}
|
}
|
||||||
|
final Node parentNode = createMock(Node.class);
|
||||||
|
expect(parentNode.getChildNodes()).andStubReturn(emptyNodeList);
|
||||||
|
replay(parentNode);
|
||||||
|
|
||||||
|
return new NodeListIterator(parentNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1337,9 +1337,8 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
if (t instanceof ConcurrentModificationException) {
|
if (t instanceof ConcurrentModificationException) {
|
||||||
// expected
|
// expected
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
fail(m.getName() + " raised unexpected " + e);
|
|
||||||
}
|
}
|
||||||
|
fail(m.getName() + " raised unexpected " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,9 +447,8 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||||||
protected boolean removeLRU(final LinkEntry<K, V> entry) {
|
protected boolean removeLRU(final LinkEntry<K, V> entry) {
|
||||||
if ("a".equals(entry.getValue())) {
|
if ("a".equals(entry.getValue())) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,12 +310,11 @@ public class ReferenceIdentityMapTest<K, V> extends AbstractIterableMapTest<K, V
|
|||||||
valueReference.get() == null) {
|
valueReference.get() == null) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else {
|
|
||||||
// create garbage:
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
final byte[] b = new byte[bytz];
|
|
||||||
bytz = bytz * 2;
|
|
||||||
}
|
}
|
||||||
|
// create garbage:
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
final byte[] b = new byte[bytz];
|
||||||
|
bytz = bytz * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,12 +241,11 @@ public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
|||||||
if (keyReference.get() == null && valueReference.get() == null) {
|
if (keyReference.get() == null && valueReference.get() == null) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else {
|
|
||||||
// create garbage:
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
final byte[] b = new byte[bytz];
|
|
||||||
bytz = bytz * 2;
|
|
||||||
}
|
}
|
||||||
|
// create garbage:
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
final byte[] b = new byte[bytz];
|
||||||
|
bytz = bytz * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,9 +62,8 @@ public class TransformedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
|
|||||||
preTailMap + "bulkTestMapValues.testCollectionRemoveAll",
|
preTailMap + "bulkTestMapValues.testCollectionRemoveAll",
|
||||||
preTailMap + "bulkTestMapValues.testCollectionRetainAll"
|
preTailMap + "bulkTestMapValues.testCollectionRetainAll"
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user