No need to nest in an else clause.

This commit is contained in:
Gary Gregory 2017-12-28 13:17:33 -07:00
parent 92c5e6f1e1
commit 8b66a577f4
21 changed files with 78 additions and 110 deletions

View File

@ -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);
}
/**

View File

@ -368,7 +368,7 @@ 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) {
@ -392,7 +392,6 @@ public class CollectionUtils {
}
return true;
}
}
/**
* Returns <code>true</code> iff at least one element is in both collections.
@ -1584,7 +1583,7 @@ 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;
@ -1599,7 +1598,6 @@ public class CollectionUtils {
mergedList.trimToSize();
return mergedList;
}
}
//-----------------------------------------------------------------------

View File

@ -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);
}

View File

@ -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

View File

@ -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));
}
/**

View File

@ -177,11 +177,10 @@ 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);
}
}
/**
* <i>(Change)</i>
@ -212,11 +211,10 @@ 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);
}
}
//-----------------------------------------------------------------------
// Bag interface

View File

@ -130,11 +130,10 @@ 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);
}
}
@Override
public boolean retainAll(final Collection<?> coll) {
@ -148,11 +147,10 @@ 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);
}
}
//-----------------------------------------------------------------------
// Bag interface

View File

@ -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;

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -116,11 +116,10 @@ public class ZippingIterator<E> implements Iterator<E> {
if (childIterator.hasNext()) {
nextIterator = childIterator;
return true;
} else {
}
// iterator is exhausted, remove it
iterators.remove();
}
}
return false;
}

View File

@ -259,13 +259,11 @@ 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);
}
}
/**
* Copies all of the mappings from the specified map to this map. The effect
@ -355,11 +353,10 @@ 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);
}
}
@Override
public MapIterator<K, V> mapIterator() {

View File

@ -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

View File

@ -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 };
}

View File

@ -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 {

View File

@ -80,14 +80,13 @@ 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);
}
}
@Override
public Iterator<Node> makeObject() {

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -310,14 +310,13 @@ 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;
}
}
}
@SuppressWarnings("unused")
private static void gc() {

View File

@ -241,14 +241,13 @@ 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;
}
}
}
@SuppressWarnings("unused")
private static void gc() {

View File

@ -62,9 +62,8 @@ public class TransformedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
preTailMap + "bulkTestMapValues.testCollectionRemoveAll",
preTailMap + "bulkTestMapValues.testCollectionRetainAll"
};
} else {
return null;
}
return null;
}
//-----------------------------------------------------------------------