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();
|
||||
if (n <= 0) {
|
||||
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;
|
||||
if (m < 0) {
|
||||
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();
|
||||
if (n <= 0) {
|
||||
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) {
|
||||
if (coll2.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
final Iterator<?> it = coll1.iterator();
|
||||
final Set<Object> elementsAlreadySeen = new HashSet<>();
|
||||
for (final Object nextElement : coll2) {
|
||||
if (elementsAlreadySeen.contains(nextElement)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
final Iterator<?> it = coll1.iterator();
|
||||
final Set<Object> elementsAlreadySeen = new HashSet<>();
|
||||
for (final Object nextElement : coll2) {
|
||||
if (elementsAlreadySeen.contains(nextElement)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean foundCurrentElement = false;
|
||||
while (it.hasNext()) {
|
||||
final Object p = it.next();
|
||||
elementsAlreadySeen.add(p);
|
||||
if (nextElement == null ? p == null : nextElement.equals(p)) {
|
||||
foundCurrentElement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundCurrentElement) {
|
||||
return false;
|
||||
boolean foundCurrentElement = false;
|
||||
while (it.hasNext()) {
|
||||
final Object p = it.next();
|
||||
elementsAlreadySeen.add(p);
|
||||
if (nextElement == null ? p == null : nextElement.equals(p)) {
|
||||
foundCurrentElement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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());
|
||||
if (includeDuplicates) {
|
||||
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--;
|
||||
if (i == -1) {
|
||||
return e.nextElement();
|
||||
} else {
|
||||
e.nextElement();
|
||||
}
|
||||
e.nextElement();
|
||||
}
|
||||
throw new IndexOutOfBoundsException("Entry does not exist: " + i);
|
||||
}
|
||||
|
|
|
@ -124,9 +124,8 @@ public class FluentIterable<E> implements Iterable<E> {
|
|||
IterableUtils.checkNotNull(iterable);
|
||||
if (iterable instanceof FluentIterable<?>) {
|
||||
return (FluentIterable<T>) iterable;
|
||||
} else {
|
||||
return new FluentIterable<>(iterable);
|
||||
}
|
||||
return new FluentIterable<>(iterable);
|
||||
}
|
||||
|
||||
// Constructor
|
||||
|
|
|
@ -175,9 +175,8 @@ public class IterableUtils {
|
|||
protected Iterator<? extends E> nextIterator(int count) {
|
||||
if (count > iterables.length) {
|
||||
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) {
|
||||
if (IterableUtils.isEmpty(iterable)) {
|
||||
return null;
|
||||
} else {
|
||||
return iterable.iterator();
|
||||
}
|
||||
return iterable.iterator();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -690,9 +688,8 @@ public class IterableUtils {
|
|||
public static boolean isEmpty(final Iterable<?> iterable) {
|
||||
if (iterable instanceof Collection<?>) {
|
||||
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) {
|
||||
if (iterable instanceof Collection<?>) {
|
||||
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) {
|
||||
if (iterable instanceof Collection<?>) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
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
|
||||
|
@ -148,10 +147,9 @@ public final class CollectionSortedBag<E> extends AbstractSortedBagDecorator<E>
|
|||
}
|
||||
}
|
||||
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) {
|
||||
rval = node;
|
||||
break;
|
||||
} else {
|
||||
node = cmp < 0 ? node.getLeft(dataElement) : node.getRight(dataElement);
|
||||
}
|
||||
node = cmp < 0 ? node.getLeft(dataElement) : node.getRight(dataElement);
|
||||
}
|
||||
|
||||
return rval;
|
||||
|
|
|
@ -104,9 +104,8 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
|
|||
public boolean evaluate(final T object) {
|
||||
if (equator != null) {
|
||||
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) {
|
||||
if(iPredicate.evaluate(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()) {
|
||||
nextIterator = childIterator;
|
||||
return true;
|
||||
} else {
|
||||
// iterator is exhausted, remove it
|
||||
iterators.remove();
|
||||
}
|
||||
// iterator is exhausted, remove it
|
||||
iterators.remove();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -259,12 +259,10 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||
if (coll.add(value)) {
|
||||
map.put(key, coll);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return coll.add(value);
|
||||
return false;
|
||||
}
|
||||
return coll.add(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -355,10 +353,9 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||
if (values instanceof Collection<?>) {
|
||||
Collection<? extends V> valueCollection = (Collection<? extends V>) values;
|
||||
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
|
||||
|
|
|
@ -568,9 +568,8 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||
public boolean equate(final Integer o1, final Integer o2) {
|
||||
if (o1.intValue() % 2 == 0 ^ o2.intValue() % 2 == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -171,9 +171,8 @@ public class DualTreeBidiMap2Test<K extends Comparable<K>, V extends Comparable<
|
|||
preTail + "bulkTestMapValues.testCollectionRemoveAll",
|
||||
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.testCollectionRetainAll"
|
||||
};
|
||||
} else {
|
||||
return new String[] { recursiveTest };
|
||||
}
|
||||
return new String[] { recursiveTest };
|
||||
}
|
||||
|
||||
// public void testCreate() throws Exception {
|
||||
|
|
|
@ -80,13 +80,12 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
|
|||
|
||||
if (createIteratorWithStandardConstr) {
|
||||
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
|
||||
|
|
|
@ -1337,9 +1337,8 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||
if (t instanceof ConcurrentModificationException) {
|
||||
// expected
|
||||
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) {
|
||||
if ("a".equals(entry.getValue())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -310,12 +310,11 @@ public class ReferenceIdentityMapTest<K, V> extends AbstractIterableMapTest<K, V
|
|||
valueReference.get() == null) {
|
||||
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) {
|
||||
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.testCollectionRetainAll"
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue