[COLLECTIONS-710] Calling CompositeCollection.size() will cash if the
list contains null element.
This commit is contained in:
parent
b97da105fb
commit
036bbf34d2
|
@ -252,6 +252,9 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAll(final Collection<?> coll) {
|
public boolean containsAll(final Collection<?> coll) {
|
||||||
|
if (coll == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (final Object item : coll) {
|
for (final Object item : coll) {
|
||||||
if (contains(item) == false) {
|
if (contains(item) == false) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -291,7 +294,7 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean removeAll(final Collection<?> coll) {
|
public boolean removeAll(final Collection<?> coll) {
|
||||||
if (coll.size() == 0) {
|
if (CollectionUtils.isEmpty(coll)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
@ -354,21 +357,23 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
||||||
* @see SetMutator
|
* @see SetMutator
|
||||||
*/
|
*/
|
||||||
public synchronized void addComposited(final Set<E> set) {
|
public synchronized void addComposited(final Set<E> set) {
|
||||||
for (final Set<E> existingSet : getSets()) {
|
if (set != null) {
|
||||||
final Collection<E> intersects = CollectionUtils.intersection(existingSet, set);
|
for (final Set<E> existingSet : getSets()) {
|
||||||
if (intersects.size() > 0) {
|
final Collection<E> intersects = CollectionUtils.intersection(existingSet, set);
|
||||||
if (this.mutator == null) {
|
if (intersects.size() > 0) {
|
||||||
throw new UnsupportedOperationException(
|
if (this.mutator == null) {
|
||||||
"Collision adding composited set with no SetMutator set");
|
throw new UnsupportedOperationException(
|
||||||
}
|
"Collision adding composited set with no SetMutator set");
|
||||||
getMutator().resolveCollision(this, existingSet, set, intersects);
|
}
|
||||||
if (CollectionUtils.intersection(existingSet, set).size() > 0) {
|
getMutator().resolveCollision(this, existingSet, set, intersects);
|
||||||
throw new IllegalArgumentException(
|
if (CollectionUtils.intersection(existingSet, set).size() > 0) {
|
||||||
"Attempt to add illegal entry unresolved by SetMutator.resolveCollision()");
|
throw new IllegalArgumentException(
|
||||||
|
"Attempt to add illegal entry unresolved by SetMutator.resolveCollision()");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
all.add(set);
|
||||||
}
|
}
|
||||||
all.add(set);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -388,8 +393,10 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
||||||
* @param sets the Sets to be appended to the composite
|
* @param sets the Sets to be appended to the composite
|
||||||
*/
|
*/
|
||||||
public void addComposited(final Set<E>... sets) {
|
public void addComposited(final Set<E>... sets) {
|
||||||
for (final Set<E> set : sets) {
|
if (sets != null) {
|
||||||
addComposited(set);
|
for (final Set<E> set : sets) {
|
||||||
|
addComposited(set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,18 @@ public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
||||||
assertTrue(set.contains("1"));
|
assertTrue(set.contains("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testContainsAll() {
|
||||||
|
final CompositeSet<E> set = new CompositeSet<>(new Set[]{ buildOne(), buildTwo() });
|
||||||
|
assertFalse(set.containsAll(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testRemoveAll() {
|
||||||
|
final CompositeSet<E> set = new CompositeSet<>(new Set[]{ buildOne(), buildTwo() });
|
||||||
|
assertFalse(set.removeAll(null));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testRemoveUnderlying() {
|
public void testRemoveUnderlying() {
|
||||||
final Set<E> one = buildOne();
|
final Set<E> one = buildOne();
|
||||||
|
@ -132,6 +144,10 @@ public class CompositeSetTest<E> extends AbstractSetTest<E> {
|
||||||
final Set<E> two = buildTwo();
|
final Set<E> two = buildTwo();
|
||||||
final CompositeSet<E> set = new CompositeSet<>();
|
final CompositeSet<E> set = new CompositeSet<>();
|
||||||
set.addComposited(one, two);
|
set.addComposited(one, two);
|
||||||
|
set.addComposited((Set<E>) null);
|
||||||
|
set.addComposited((Set<E>[]) null);
|
||||||
|
set.addComposited(null, null);
|
||||||
|
set.addComposited(null, null, null);
|
||||||
final CompositeSet<E> set2 = new CompositeSet<>(buildOne());
|
final CompositeSet<E> set2 = new CompositeSet<>(buildOne());
|
||||||
set2.addComposited(buildTwo());
|
set2.addComposited(buildTwo());
|
||||||
assertTrue(set.equals(set2));
|
assertTrue(set.equals(set2));
|
||||||
|
|
Loading…
Reference in New Issue