Class TransformedMultiSet<E>
- Type Parameters:
E- The type held in the multiset
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,MultiSet<E>
- Direct Known Subclasses:
TransformedSortedMultiSet
MultiSet to transform objects that are added.
The add and setCount methods are affected by this class. Thus objects must be removed or searched for using their transformed form. For example, if the transformation converts Strings to Integers, you must use the Integer form to remove objects.
- Since:
- 4.6.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSet
MultiSet.Entry<E> -
Field Summary
Fields inherited from class org.apache.commons.collections4.collection.TransformedCollection
transformer -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTransformedMultiSet(MultiSet<E> multiset, Transformer<? super E, ? extends E> transformer) Constructor that wraps (not copies). -
Method Summary
Modifier and TypeMethodDescriptionintAdds a number of occurrences of the specified object to the MultiSet.entrySet()Returns aSetof all entries contained in the MultiSet.booleanCompares this MultiSet to another object.intGets the number of occurrences of the given object currently in the MultiSet.Gets the decorated multiset.inthashCode()Gets a hash code for the MultiSet compatible with the definition of equals.intRemoves a number of occurrences of the specified object from the MultiSet.intSets the number of occurrences of the specified object in the MultiSet to the given count.static <E> TransformedMultiSet<E> transformedMultiSet(MultiSet<E> multiset, Transformer<? super E, ? extends E> transformer) Factory method to create a transforming multiset that will transform existing contents of the specified multiset.static <E> TransformedMultiSet<E> transformingMultiSet(MultiSet<E> multiset, Transformer<? super E, ? extends E> transformer) Factory method to create a transforming multiset.Returns aSetof unique elements in the MultiSet.Methods inherited from class org.apache.commons.collections4.collection.TransformedCollection
add, addAll, transform, transform, transformedCollection, transformingCollectionMethods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator
clear, contains, containsAll, decorated, isEmpty, iterator, remove, removeAll, removeIf, retainAll, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, clear, contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
-
Constructor Details
-
TransformedMultiSet
Constructor that wraps (not copies).If there are any elements already in the multiset being decorated, they are NOT transformed.
- Parameters:
multiset- The multiset to decorate, must not be null.transformer- The transformer to use for conversion, must not be null.- Throws:
NullPointerException- if multiset or transformer is null.
-
-
Method Details
-
transformedMultiSet
public static <E> TransformedMultiSet<E> transformedMultiSet(MultiSet<E> multiset, Transformer<? super E, ? extends E> transformer) Factory method to create a transforming multiset that will transform existing contents of the specified multiset.If there are any elements already in the multiset being decorated, they will be transformed by this method. Contrast this with
transformingMultiSet(MultiSet, Transformer).- Type Parameters:
E- The type of the elements in the multiset.- Parameters:
multiset- The multiset to decorate, must not be null.transformer- The transformer to use for conversion, must not be null.- Returns:
- A new transformed MultiSet.
- Throws:
NullPointerException- if multiset or transformer is null.
-
transformingMultiSet
public static <E> TransformedMultiSet<E> transformingMultiSet(MultiSet<E> multiset, Transformer<? super E, ? extends E> transformer) Factory method to create a transforming multiset.If there are any elements already in the multiset being decorated, they are NOT transformed. Contrast this with
transformedMultiSet(MultiSet, Transformer).- Type Parameters:
E- The type of the elements in the multiset.- Parameters:
multiset- The multiset to decorate, must not be null.transformer- The transformer to use for conversion, must not be null.- Returns:
- A new transformed MultiSet.
- Throws:
NullPointerException- if multiset or transformer is null.
-
add
Description copied from interface:MultiSetAdds a number of occurrences of the specified object to the MultiSet.If the object is already in the
MultiSet.uniqueSet()then increment its count as reported byMultiSet.getCount(Object). Otherwise, add it to theMultiSet.uniqueSet()and report its count asoccurrences. -
entrySet
Description copied from interface:MultiSetReturns aSetof all entries contained in the MultiSet.The returned set is backed by this multiset, so any change to either is immediately reflected in the other.
-
equals
Description copied from interface:MultiSetCompares this MultiSet to another object.This MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements.
-
getCount
Description copied from interface:MultiSetGets the number of occurrences of the given object currently in the MultiSet. If the object does not exist in the multiset, return 0. -
getMultiSet
Gets the decorated multiset.- Returns:
- The decorated multiset.
-
hashCode
Description copied from interface:MultiSetGets a hash code for the MultiSet compatible with the definition of equals. The hash code is defined as the sum total of a hash code for each element. The per element hash code is defined as(e==null ? 0 : e.hashCode()) ^ noOccurrences). -
remove
Description copied from interface:MultiSetRemoves a number of occurrences of the specified object from the MultiSet.If the number of occurrences to remove is greater than the actual number of occurrences in the multiset, the object will be removed from the multiset.
- Specified by:
removein interfaceMultiSet<E>- Parameters:
object- The object to remove.occurrences- The number of occurrences to remove, may be zero, in which case no change is made to the multiset.- Returns:
- The number of occurrences of the object in the multiset before the operation; possibly zero.
-
setCount
Description copied from interface:MultiSetSets the number of occurrences of the specified object in the MultiSet to the given count.If the provided count is zero, the object will be removed from the
MultiSet.uniqueSet(). -
uniqueSet
Description copied from interface:MultiSetReturns aSetof unique elements in the MultiSet.Uniqueness constraints are the same as those in
Set.The returned set is backed by this multiset, so any change to either is immediately reflected in the other. Only removal operations are supported, in which case all occurrences of the element are removed from the backing multiset.
-