/** * Adds an object to the collection, throwing UnsupportedOperationException * unless a SetMutator strategy is specified. * * @param obj the object to add * @return {@code true} if the collection was modified * @throws UnsupportedOperationException if SetMutator hasn't been set or add is unsupported * @throws ClassCastException if the object cannot be added due to its type * @throws NullPointerException if the object cannot be added because its null * @throws IllegalArgumentException if the object cannot be added */ @Override public boolean add(final E obj) { if (mutator == null) { throw new UnsupportedOperationException( "add() is not supported on CompositeSet without a SetMutator strategy"); } return mutator.add(this, all, obj); }
/** * Adds a collection of elements to this composite, throwing * UnsupportedOperationException unless a SetMutator strategy is specified. * * @param coll the collection to add * @return true if the composite was modified * @throws UnsupportedOperationException if SetMutator hasn't been set or add is unsupported * @throws ClassCastException if the object cannot be added due to its type * @throws NullPointerException if the object cannot be added because its null * @throws IllegalArgumentException if the object cannot be added */ @Override public boolean addAll(final Collection<? extends E> coll) { if (mutator == null) { throw new UnsupportedOperationException( "addAll() is not supported on CompositeSet without a SetMutator strategy"); } return mutator.addAll(this, all, coll); }
/** * Add a Set to this composite. * * @param set the set to add * @throws IllegalArgumentException if a SetMutator is set, but fails to resolve a collision * @throws UnsupportedOperationException if there is no SetMutator set * @throws NullPointerException if {@code set} is null * @see SetMutator */ public synchronized void addComposited(final Set<E> set) { for (final Set<E> existingSet : getSets()) { final Collection<E> intersects = CollectionUtils.intersection(existingSet, set); if (intersects.size() > 0) { 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) { throw new IllegalArgumentException( "Attempt to add illegal entry unresolved by SetMutator.resolveCollision()"); } } } all.add(set); }