Use isEmpty().
This commit is contained in:
parent
23730a0fb8
commit
dc01c2583a
|
@ -77,7 +77,7 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
|
|||
*/
|
||||
public static <E> Bag<E> transformedBag(final Bag<E> bag, final Transformer<? super E, ? extends E> transformer) {
|
||||
final TransformedBag<E> decorated = new TransformedBag<>(bag, transformer);
|
||||
if (bag.size() > 0) {
|
||||
if (!bag.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // Bag is of type E
|
||||
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
|
||||
bag.clear();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
|
|||
final Transformer<? super E, ? extends E> transformer) {
|
||||
|
||||
final TransformedSortedBag<E> decorated = new TransformedSortedBag<>(bag, transformer);
|
||||
if (bag.size() > 0) {
|
||||
if (!bag.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // bag is type E
|
||||
final E[] values = (E[]) bag.toArray(); // NOPMD - false positive for generics
|
||||
bag.clear();
|
||||
|
|
|
@ -85,7 +85,7 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
|
|||
|
||||
final TransformedCollection<E> decorated = new TransformedCollection<>(collection, transformer);
|
||||
// null collection & transformer are disallowed by the constructor call above
|
||||
if (collection.size() > 0) {
|
||||
if (!collection.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // collection is of type E
|
||||
final E[] values = (E[]) collection.toArray(); // NOPMD - false positive for generics
|
||||
collection.clear();
|
||||
|
|
|
@ -67,7 +67,7 @@ public class LoopingIterator<E> implements ResettableIterator<E> {
|
|||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return collection.size() > 0;
|
||||
return !collection.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -254,7 +254,7 @@ public class CursorableLinkedList<E> extends AbstractLinkedList<E> implements Se
|
|||
*/
|
||||
@Override
|
||||
protected void removeAllNodes() {
|
||||
if (size() > 0) {
|
||||
if (!isEmpty()) {
|
||||
// superclass implementation would break all the iterators
|
||||
final Iterator<E> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class TransformedList<E> extends TransformedCollection<E> implements List
|
|||
public static <E> TransformedList<E> transformedList(final List<E> list,
|
||||
final Transformer<? super E, ? extends E> transformer) {
|
||||
final TransformedList<E> decorated = new TransformedList<>(list, transformer);
|
||||
if (list.size() > 0) {
|
||||
if (!list.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // list is of type E
|
||||
final E[] values = (E[]) list.toArray(); // NOPMD - false positive for generics
|
||||
list.clear();
|
||||
|
|
|
@ -105,10 +105,10 @@ public class MultiKeyMap<K, V> extends AbstractMapDecorator<MultiKey<? extends K
|
|||
*/
|
||||
public static <K, V> MultiKeyMap<K, V> multiKeyMap(final AbstractHashedMap<MultiKey<? extends K>, V> map) {
|
||||
Objects.requireNonNull(map, "map");
|
||||
if (map.size() > 0) {
|
||||
throw new IllegalArgumentException("Map must be empty");
|
||||
if (map.isEmpty()) {
|
||||
return new MultiKeyMap<>(map);
|
||||
}
|
||||
return new MultiKeyMap<>(map);
|
||||
throw new IllegalArgumentException("Map must be empty");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -269,7 +269,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
if (coll == null) {
|
||||
coll = createCollection(1); // might produce a non-empty collection
|
||||
coll.add((V) value);
|
||||
if (coll.size() > 0) {
|
||||
if (!coll.isEmpty()) {
|
||||
// only add if non-zero size to maintain class state
|
||||
decorated().put(key, coll);
|
||||
result = true; // map definitely changed
|
||||
|
@ -391,7 +391,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
if (coll == null) {
|
||||
coll = createCollection(values.size()); // might produce a non-empty collection
|
||||
coll.addAll(values);
|
||||
if (coll.size() > 0) {
|
||||
if (!coll.isEmpty()) {
|
||||
// only add if non-zero size to maintain class state
|
||||
decorated().put(key, coll);
|
||||
result = true; // map definitely changed
|
||||
|
|
|
@ -511,7 +511,7 @@ public final class StaticBucketMap<K, V> extends AbstractIterableMap<K, V> {
|
|||
private Map.Entry<K, V> last;
|
||||
|
||||
public boolean hasNext() {
|
||||
if (current.size() > 0) {
|
||||
if (!current.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
while (bucket < buckets.length) {
|
||||
|
@ -522,7 +522,7 @@ public final class StaticBucketMap<K, V> extends AbstractIterableMap<K, V> {
|
|||
n = n.next;
|
||||
}
|
||||
bucket++;
|
||||
if (current.size() > 0) {
|
||||
if (!current.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public class TransformedMap<K, V>
|
|||
final Transformer<? super K, ? extends K> keyTransformer,
|
||||
final Transformer<? super V, ? extends V> valueTransformer) {
|
||||
final TransformedMap<K, V> decorated = new TransformedMap<>(map, keyTransformer, valueTransformer);
|
||||
if (map.size() > 0) {
|
||||
if (!map.isEmpty()) {
|
||||
final Map<K, V> transformed = decorated.transformMap(map);
|
||||
decorated.clear();
|
||||
decorated.decorated().putAll(transformed); // avoids double transformation
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TransformedSortedMap<K, V>
|
|||
|
||||
final TransformedSortedMap<K, V> decorated =
|
||||
new TransformedSortedMap<>(map, keyTransformer, valueTransformer);
|
||||
if (map.size() > 0) {
|
||||
if (!map.isEmpty()) {
|
||||
final Map<K, V> transformed = decorated.transformMap(map);
|
||||
decorated.clear();
|
||||
decorated.decorated().putAll(transformed); // avoids double transformation
|
||||
|
|
|
@ -75,7 +75,7 @@ public class TransformedQueue<E> extends TransformedCollection<E> implements Que
|
|||
final Transformer<? super E, ? extends E> transformer) {
|
||||
// throws IAE if queue or transformer is null
|
||||
final TransformedQueue<E> decorated = new TransformedQueue<>(queue, transformer);
|
||||
if (queue.size() > 0) {
|
||||
if (!queue.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // queue is type <E>
|
||||
final E[] values = (E[]) queue.toArray(); // NOPMD - false positive for generics
|
||||
queue.clear();
|
||||
|
|
|
@ -376,13 +376,13 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
|||
if (set != null) {
|
||||
for (final Set<E> existingSet : getSets()) {
|
||||
final Collection<E> intersects = CollectionUtils.intersection(existingSet, set);
|
||||
if (intersects.size() > 0) {
|
||||
if (!intersects.isEmpty()) {
|
||||
if (this.mutator == null) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Collision adding composited set with no SetMutator set");
|
||||
}
|
||||
getMutator().resolveCollision(this, existingSet, set, intersects);
|
||||
if (CollectionUtils.intersection(existingSet, set).size() > 0) {
|
||||
if (!CollectionUtils.intersection(existingSet, set).isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Attempt to add illegal entry unresolved by SetMutator.resolveCollision()");
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class ListOrderedSet<E>
|
|||
public static <E> ListOrderedSet<E> listOrderedSet(final Set<E> set, final List<E> list) {
|
||||
Objects.requireNonNull(set, "set");
|
||||
Objects.requireNonNull(list, "list");
|
||||
if (set.size() > 0 || list.size() > 0) {
|
||||
if (!set.isEmpty() || !list.isEmpty()) {
|
||||
throw new IllegalArgumentException("Set and List must be empty");
|
||||
}
|
||||
return new ListOrderedSet<>(set, list);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TransformedNavigableSet<E> extends TransformedSortedSet<E> implemen
|
|||
final Transformer<? super E, ? extends E> transformer) {
|
||||
|
||||
final TransformedNavigableSet<E> decorated = new TransformedNavigableSet<>(set, transformer);
|
||||
if (set.size() > 0) {
|
||||
if (!set.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // set is type E
|
||||
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
||||
set.clear();
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TransformedSet<E> extends TransformedCollection<E> implements Set<E
|
|||
*/
|
||||
public static <E> Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer) {
|
||||
final TransformedSet<E> decorated = new TransformedSet<>(set, transformer);
|
||||
if (set.size() > 0) {
|
||||
if (!set.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // set is type E
|
||||
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
||||
set.clear();
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TransformedSortedSet<E> extends TransformedSet<E> implements Sorted
|
|||
final Transformer<? super E, ? extends E> transformer) {
|
||||
|
||||
final TransformedSortedSet<E> decorated = new TransformedSortedSet<>(set, transformer);
|
||||
if (set.size() > 0) {
|
||||
if (!set.isEmpty()) {
|
||||
@SuppressWarnings("unchecked") // set is type E
|
||||
final E[] values = (E[]) set.toArray(); // NOPMD - false positive for generics
|
||||
set.clear();
|
||||
|
|
|
@ -57,7 +57,7 @@ public abstract class AbstractSortedBagTest<T> extends AbstractBagTest<T> {
|
|||
}
|
||||
assertEquals("Element appears to be out of order.", last, confiter.next());
|
||||
}
|
||||
if (getCollection().size() > 0) {
|
||||
if (!getCollection().isEmpty()) {
|
||||
assertEquals("Incorrect element returned by first().", first,
|
||||
getCollection().first());
|
||||
assertEquals("Incorrect element returned by last().", last,
|
||||
|
|
|
@ -1050,7 +1050,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||
assertEquals("Size of new Collection is 0.", 0, getCollection().size());
|
||||
|
||||
resetFull();
|
||||
assertTrue("Size of full collection should be greater than zero", getCollection().size() > 0);
|
||||
assertFalse("Size of full collection should be greater than zero", getCollection().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1033,8 +1033,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
// clear values, reflected in map
|
||||
resetFull();
|
||||
Collection<V> values = getMap().values();
|
||||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(values.size() > 0);
|
||||
assertFalse(getMap().isEmpty());
|
||||
assertFalse(values.isEmpty());
|
||||
values.clear();
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(values.isEmpty());
|
||||
|
@ -1042,8 +1042,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
// clear map, reflected in values
|
||||
resetFull();
|
||||
values = getMap().values();
|
||||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(values.size() > 0);
|
||||
assertFalse(getMap().isEmpty());
|
||||
assertFalse(values.isEmpty());
|
||||
getMap().clear();
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(values.isEmpty());
|
||||
|
@ -1061,8 +1061,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
// clear values, reflected in map
|
||||
resetFull();
|
||||
Set<K> keySet = getMap().keySet();
|
||||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(keySet.size() > 0);
|
||||
assertFalse(getMap().isEmpty());
|
||||
assertFalse(keySet.isEmpty());
|
||||
keySet.clear();
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(keySet.isEmpty());
|
||||
|
@ -1070,8 +1070,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
// clear map, reflected in values
|
||||
resetFull();
|
||||
keySet = getMap().keySet();
|
||||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(keySet.size() > 0);
|
||||
assertFalse(getMap().isEmpty());
|
||||
assertFalse(keySet.isEmpty());
|
||||
getMap().clear();
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(keySet.isEmpty());
|
||||
|
@ -1089,8 +1089,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
// clear values, reflected in map
|
||||
resetFull();
|
||||
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
||||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(entrySet.size() > 0);
|
||||
assertFalse(getMap().isEmpty());
|
||||
assertFalse(entrySet.isEmpty());
|
||||
entrySet.clear();
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(entrySet.isEmpty());
|
||||
|
@ -1098,8 +1098,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
// clear map, reflected in values
|
||||
resetFull();
|
||||
entrySet = getMap().entrySet();
|
||||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(entrySet.size() > 0);
|
||||
assertFalse(getMap().isEmpty());
|
||||
assertFalse(entrySet.isEmpty());
|
||||
getMap().clear();
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(entrySet.isEmpty());
|
||||
|
|
|
@ -43,7 +43,6 @@ public abstract class AbstractSortedSetTest<E> extends AbstractSetTest<E> {
|
|||
super(name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Verification extension, will check the order of elements,
|
||||
* the sets should already be verified equal.
|
||||
|
@ -67,7 +66,7 @@ public abstract class AbstractSortedSetTest<E> extends AbstractSetTest<E> {
|
|||
}
|
||||
assertEquals("Element appears to be out of order.", last, confiter.next());
|
||||
}
|
||||
if (getCollection().size() > 0) {
|
||||
if (!getCollection().isEmpty()) {
|
||||
assertEquals("Incorrect element returned by first().", first,
|
||||
getCollection().first());
|
||||
assertEquals("Incorrect element returned by last().", last,
|
||||
|
@ -75,7 +74,6 @@ public abstract class AbstractSortedSetTest<E> extends AbstractSetTest<E> {
|
|||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Overridden because SortedSets don't allow null elements (normally).
|
||||
* @return false
|
||||
|
@ -99,7 +97,6 @@ public abstract class AbstractSortedSetTest<E> extends AbstractSetTest<E> {
|
|||
return (SortedSet<E>) super.makeFullCollection();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Returns an empty {@link TreeSet} for use in modification testing.
|
||||
*
|
||||
|
@ -110,9 +107,6 @@ public abstract class AbstractSortedSetTest<E> extends AbstractSetTest<E> {
|
|||
return new TreeSet<>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Override to return comparable objects.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue