Use isEmpty().
This commit is contained in:
parent
6b0d7c4898
commit
2b23b7add8
|
@ -599,7 +599,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return "[]";
|
||||
}
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
|
|
|
@ -96,7 +96,7 @@ public class HasherBloomFilter extends AbstractBloomFilter {
|
|||
|
||||
@Override
|
||||
public long[] getBits() {
|
||||
if (hasher.size() == 0) {
|
||||
if (hasher.isEmpty()) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,15 @@ public final class StaticHasher implements Hasher {
|
|||
return shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests emptiness (size == 0).
|
||||
*
|
||||
* @return Whether or not this is empty.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an iterator of integers that are the bits to enable in the Bloom
|
||||
* filter based on the shape. The iterator will not return the same value multiple
|
||||
|
|
|
@ -251,7 +251,7 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
|
|||
* @throws UnsupportedOperationException if the {@link ComparatorChain} is empty
|
||||
*/
|
||||
private void checkChainIntegrity() {
|
||||
if (comparatorChain.size() == 0) {
|
||||
if (comparatorChain.isEmpty()) {
|
||||
throw new UnsupportedOperationException("ComparatorChains must contain at least one Comparator");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
|
|||
@SuppressWarnings("unchecked")
|
||||
public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures) {
|
||||
Objects.requireNonNull(closures, "closures");
|
||||
if (closures.size() == 0) {
|
||||
if (closures.isEmpty()) {
|
||||
return NOPClosure.<E>nopClosure();
|
||||
}
|
||||
// convert to array like this to guarantee iterator() ordering
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
|
|||
public static <T> Transformer<T, T> chainedTransformer(
|
||||
final Collection<? extends Transformer<? super T, ? extends T>> transformers) {
|
||||
Objects.requireNonNull(transformers, "transformers");
|
||||
if (transformers.size() == 0) {
|
||||
if (transformers.isEmpty()) {
|
||||
return NOPTransformer.<T>nopTransformer();
|
||||
}
|
||||
// convert to array like this to guarantee iterator() ordering
|
||||
|
|
|
@ -94,7 +94,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
|||
final Map<? extends Predicate<? super I>, ? extends Transformer<? super I, ? extends O>> map) {
|
||||
|
||||
Objects.requireNonNull(map, "map");
|
||||
if (map.size() == 0) {
|
||||
if (map.isEmpty()) {
|
||||
return ConstantTransformer.<I, O>nullTransformer();
|
||||
}
|
||||
// convert to array like this to guarantee iterator() ordering
|
||||
|
|
|
@ -81,7 +81,7 @@ public class LoopingIterator<E> implements ResettableIterator<E> {
|
|||
*/
|
||||
@Override
|
||||
public E next() {
|
||||
if (collection.size() == 0) {
|
||||
if (collection.isEmpty()) {
|
||||
throw new NoSuchElementException("There are no elements for this iterator to loop on");
|
||||
}
|
||||
if (iterator.hasNext() == false) {
|
||||
|
|
|
@ -402,7 +402,7 @@ public abstract class AbstractLinkedList<E> implements List<E> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return "[]";
|
||||
}
|
||||
final StringBuilder buf = new StringBuilder(16 * size());
|
||||
|
|
|
@ -276,7 +276,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
|||
if (result == false) {
|
||||
return false;
|
||||
}
|
||||
if (set.size() == 0) {
|
||||
if (set.isEmpty()) {
|
||||
super.clear();
|
||||
} else {
|
||||
// use the set as parameter for the call to retainAll to improve performance
|
||||
|
|
|
@ -826,7 +826,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
* @return the entrySet iterator
|
||||
*/
|
||||
protected Iterator<Map.Entry<K, V>> createEntrySetIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyIterator.<Map.Entry<K, V>>emptyIterator();
|
||||
}
|
||||
return new EntrySetIterator<>(this);
|
||||
|
@ -926,7 +926,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
* @return the keySet iterator
|
||||
*/
|
||||
protected Iterator<K> createKeySetIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyIterator.<K>emptyIterator();
|
||||
}
|
||||
return new KeySetIterator<>(this);
|
||||
|
@ -1014,7 +1014,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
* @return the values iterator
|
||||
*/
|
||||
protected Iterator<V> createValuesIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyIterator.<V>emptyIterator();
|
||||
}
|
||||
return new ValuesIterator<>(this);
|
||||
|
@ -1387,7 +1387,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return "{}";
|
||||
}
|
||||
final StringBuilder buf = new StringBuilder(32 * size());
|
||||
|
|
|
@ -410,7 +410,7 @@ public abstract class AbstractLinkedMap<K, V> extends AbstractHashedMap<K, V> im
|
|||
*/
|
||||
@Override
|
||||
protected Iterator<Map.Entry<K, V>> createEntrySetIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyOrderedIterator.<Map.Entry<K, V>>emptyOrderedIterator();
|
||||
}
|
||||
return new EntrySetIterator<>(this);
|
||||
|
@ -446,7 +446,7 @@ public abstract class AbstractLinkedMap<K, V> extends AbstractHashedMap<K, V> im
|
|||
*/
|
||||
@Override
|
||||
protected Iterator<K> createKeySetIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyOrderedIterator.<K>emptyOrderedIterator();
|
||||
}
|
||||
return new KeySetIterator<>(this);
|
||||
|
@ -483,7 +483,7 @@ public abstract class AbstractLinkedMap<K, V> extends AbstractHashedMap<K, V> im
|
|||
*/
|
||||
@Override
|
||||
protected Iterator<V> createValuesIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyOrderedIterator.<V>emptyOrderedIterator();
|
||||
}
|
||||
return new ValuesIterator<>(this);
|
||||
|
|
|
@ -793,7 +793,7 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
|
|||
if (parent.delegateMap != null) {
|
||||
return parent.delegateMap.entrySet().iterator();
|
||||
}
|
||||
if (parent.size() == 0) {
|
||||
if (parent.isEmpty()) {
|
||||
return EmptyIterator.<Map.Entry<K, V>>emptyIterator();
|
||||
}
|
||||
return new EntrySetIterator<>(parent);
|
||||
|
@ -1016,7 +1016,7 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
|
|||
if (parent.delegateMap != null) {
|
||||
return parent.delegateMap.keySet().iterator();
|
||||
}
|
||||
if (parent.size() == 0) {
|
||||
if (parent.isEmpty()) {
|
||||
return EmptyIterator.<K>emptyIterator();
|
||||
}
|
||||
return new KeySetIterator<>(parent);
|
||||
|
@ -1084,7 +1084,7 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
|
|||
if (parent.delegateMap != null) {
|
||||
return parent.delegateMap.values().iterator();
|
||||
}
|
||||
if (parent.size() == 0) {
|
||||
if (parent.isEmpty()) {
|
||||
return EmptyIterator.<V>emptyIterator();
|
||||
}
|
||||
return new ValuesIterator<>(parent);
|
||||
|
|
|
@ -171,7 +171,7 @@ public class ListOrderedMap<K, V>
|
|||
*/
|
||||
@Override
|
||||
public K firstKey() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
throw new NoSuchElementException("Map is empty");
|
||||
}
|
||||
return insertOrder.get(0);
|
||||
|
@ -185,7 +185,7 @@ public class ListOrderedMap<K, V>
|
|||
*/
|
||||
@Override
|
||||
public K lastKey() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
throw new NoSuchElementException("Map is empty");
|
||||
}
|
||||
return insertOrder.get(size() - 1);
|
||||
|
|
|
@ -383,7 +383,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
* @return true if this map changed
|
||||
*/
|
||||
public boolean putAll(final K key, final Collection<V> values) {
|
||||
if (values == null || values.size() == 0) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
boolean result = false;
|
||||
|
|
|
@ -192,7 +192,7 @@ public final class StaticBucketMap<K, V> extends AbstractIterableMap<K, V> {
|
|||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return (size() == 0);
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -354,7 +354,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||
|
||||
@Override
|
||||
public MapIterator<K, V> mapIterator() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
return EmptyMapIterator.emptyMapIterator();
|
||||
}
|
||||
return new MultiValuedMapIterator();
|
||||
|
|
|
@ -772,7 +772,7 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
|
|||
|
||||
@Override
|
||||
public K firstKey() {
|
||||
if (size() == 0) {
|
||||
if (isEmpty()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return firstEntry().getKey();
|
||||
|
|
|
@ -332,7 +332,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||
assertTrue(collection.size() == collectionA.size());
|
||||
assertTrue(collection.contains(2L) && !collection.contains(1));
|
||||
collection = CollectionUtils.collect((Iterator<Integer>) null, (Transformer<Integer, Number>) null);
|
||||
assertTrue(collection.size() == 0);
|
||||
assertTrue(collection.isEmpty());
|
||||
|
||||
final int size = collectionA.size();
|
||||
collectionB = CollectionUtils.collect((Collection<Integer>) null, transformer, collectionB);
|
||||
|
|
|
@ -134,9 +134,9 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
|
|||
}
|
||||
}
|
||||
|
||||
assertTrue("List is empty", list1.size() == 0);
|
||||
assertTrue("List is empty", list1.isEmpty());
|
||||
assertTrue("List is empty", list2.size() == 1);
|
||||
assertTrue("List is empty", list3.size() == 0);
|
||||
assertTrue("List is empty", list3.isEmpty());
|
||||
}
|
||||
|
||||
public void testFirstIteratorIsEmptyBug() {
|
||||
|
|
|
@ -148,9 +148,9 @@ public class LazyIteratorChainTest extends AbstractIteratorTest<String> {
|
|||
}
|
||||
}
|
||||
|
||||
assertTrue("List is empty", list1.size() == 0);
|
||||
assertTrue("List is empty", list1.isEmpty());
|
||||
assertTrue("List is empty", list2.size() == 1);
|
||||
assertTrue("List is empty", list3.size() == 0);
|
||||
assertTrue("List is empty", list3.isEmpty());
|
||||
}
|
||||
|
||||
public void testFirstIteratorIsEmptyBug() {
|
||||
|
|
|
@ -1036,8 +1036,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(values.size() > 0);
|
||||
values.clear();
|
||||
assertTrue(getMap().size() == 0);
|
||||
assertTrue(values.size() == 0);
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(values.isEmpty());
|
||||
|
||||
// clear map, reflected in values
|
||||
resetFull();
|
||||
|
@ -1045,8 +1045,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(values.size() > 0);
|
||||
getMap().clear();
|
||||
assertTrue(getMap().size() == 0);
|
||||
assertTrue(values.size() == 0);
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(values.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1064,8 +1064,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(keySet.size() > 0);
|
||||
keySet.clear();
|
||||
assertTrue(getMap().size() == 0);
|
||||
assertTrue(keySet.size() == 0);
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(keySet.isEmpty());
|
||||
|
||||
// clear map, reflected in values
|
||||
resetFull();
|
||||
|
@ -1073,8 +1073,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(keySet.size() > 0);
|
||||
getMap().clear();
|
||||
assertTrue(getMap().size() == 0);
|
||||
assertTrue(keySet.size() == 0);
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(keySet.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1092,8 +1092,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(entrySet.size() > 0);
|
||||
entrySet.clear();
|
||||
assertTrue(getMap().size() == 0);
|
||||
assertTrue(entrySet.size() == 0);
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(entrySet.isEmpty());
|
||||
|
||||
// clear map, reflected in values
|
||||
resetFull();
|
||||
|
@ -1101,8 +1101,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
assertTrue(getMap().size() > 0);
|
||||
assertTrue(entrySet.size() > 0);
|
||||
getMap().clear();
|
||||
assertTrue(getMap().size() == 0);
|
||||
assertTrue(entrySet.size() == 0);
|
||||
assertTrue(getMap().isEmpty());
|
||||
assertTrue(entrySet.isEmpty());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -696,7 +696,7 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
|
|||
final MultiSet<T> multiset = makeObject();
|
||||
if (multiset instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
|
||||
final MultiSet<?> multiset2 = (MultiSet<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(multiset));
|
||||
assertTrue("MultiSet is empty", multiset2.size() == 0);
|
||||
assertTrue("MultiSet is empty", multiset2.isEmpty());
|
||||
assertEquals(multiset, multiset2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class TransformedSplitMapTest extends BulkTest {
|
|||
in.close();
|
||||
|
||||
final TransformedSplitMap<?, ?, ?, ?> readMap = (TransformedSplitMap<?, ?, ?, ?>) readObject;
|
||||
assertTrue( "Map should be empty", readMap.size() == 0 );
|
||||
assertTrue( "Map should be empty", readMap.isEmpty() );
|
||||
assertEquals( map.entrySet(), readMap.entrySet() );
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class TransformedSplitMapTest extends BulkTest {
|
|||
in.close();
|
||||
|
||||
final TransformedSplitMap<?, ?, ?, ?> readMap = (TransformedSplitMap<?, ?, ?, ?>) readObject;
|
||||
assertFalse( "Map should not be empty", readMap.size() == 0 );
|
||||
assertFalse( "Map should not be empty", readMap.isEmpty() );
|
||||
assertEquals( map.entrySet(), readMap.entrySet() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue