Class AbstractMapBag
java.lang.Object
org.apache.commons.collections.bag.AbstractMapBag
- All Implemented Interfaces:
Iterable,Collection,Bag
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
Abstract implementation of the
Bag interface to simplify the creation
of subclass implementations.
Subclasses specify a Map implementation to use as the internal storage. The map will be used to map bag elements to a number; the number represents the number of occurrences of that element in the bag.
- Since:
- Commons Collections 3.0 (previously DefaultMapBag v2.0)
-
Method Summary
Modifier and TypeMethodDescriptionbooleanDeprecated.Adds a new element to the bag, incrementing its count in the underlying map.booleanDeprecated.Adds a new element to the bag, incrementing its count in the map.booleanaddAll(Collection coll) Deprecated.Invokesadd(Object)for each element in the given collection.voidclear()Deprecated.Clears the bag by clearing the underlying map.booleanDeprecated.Determines if the bag contains the given element by checking if the underlying map contains the element as a key.booleancontainsAll(Collection coll) Deprecated.Determines if the bag contains the given elements.booleanDeprecated.Compares this Bag to another.intDeprecated.Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map.inthashCode()Deprecated.Gets a hash code for the Bag compatible with the definition of equals.booleanisEmpty()Deprecated.Returns true if the underlying map is empty.iterator()Deprecated.Gets an iterator over the bag elements.booleanDeprecated.Removes all copies of the specified object from the bag.booleanDeprecated.Removes a specified number of copies of an object from the bag.booleanremoveAll(Collection coll) Deprecated.Removes objects from the bag according to their count in the specified collection.booleanretainAll(Collection coll) Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.intsize()Deprecated.Returns the number of elements in this bag.Object[]toArray()Deprecated.Returns an array of all of this bag's elements.Object[]Deprecated.Returns an array of all of this bag's elements.toString()Deprecated.Implement a toString() method suitable for debugging.Deprecated.Returns an unmodifiable view of the underlying map's key set.Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Method Details
-
size
public int size()Deprecated.Returns the number of elements in this bag.- Specified by:
sizein interfaceBag- Specified by:
sizein interfaceCollection- Returns:
- current size of the bag
-
isEmpty
public boolean isEmpty()Deprecated.Returns true if the underlying map is empty.- Specified by:
isEmptyin interfaceCollection- Returns:
- true if bag is empty
-
getCount
Deprecated.Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map. -
contains
Deprecated.Determines if the bag contains the given element by checking if the underlying map contains the element as a key.- Specified by:
containsin interfaceCollection- Parameters:
object- the object to search for- Returns:
- true if the bag contains the given element
-
containsAll
Deprecated.Determines if the bag contains the given elements.- Specified by:
containsAllin interfaceBag- Specified by:
containsAllin interfaceCollection- Parameters:
coll- the collection to check against- Returns:
trueif the Bag contains all the collection
-
iterator
Deprecated.Gets an iterator over the bag elements. Elements present in the Bag more than once will be returned repeatedly. -
add
Deprecated.Adds a new element to the bag, incrementing its count in the underlying map.- Specified by:
addin interfaceBag- Specified by:
addin interfaceCollection- Parameters:
object- the object to add- Returns:
trueif the object was not already in theuniqueSet
-
add
Deprecated.Adds a new element to the bag, incrementing its count in the map. -
addAll
Deprecated.Invokesadd(Object)for each element in the given collection.- Specified by:
addAllin interfaceCollection- Parameters:
coll- the collection to add- Returns:
trueif this call changed the bag
-
clear
public void clear()Deprecated.Clears the bag by clearing the underlying map.- Specified by:
clearin interfaceCollection
-
remove
Deprecated.Removes all copies of the specified object from the bag.- Specified by:
removein interfaceBag- Specified by:
removein interfaceCollection- Parameters:
object- the object to remove- Returns:
- true if the bag changed
-
remove
Deprecated.Removes a specified number of copies of an object from the bag. -
removeAll
Deprecated.Removes objects from the bag according to their count in the specified collection.- Specified by:
removeAllin interfaceBag- Specified by:
removeAllin interfaceCollection- Parameters:
coll- the collection to use- Returns:
- true if the bag changed
-
retainAll
Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.- Specified by:
retainAllin interfaceBag- Specified by:
retainAllin interfaceCollection- Parameters:
coll- the collection to retain- Returns:
- true if this call changed the collection
-
toArray
Deprecated.Returns an array of all of this bag's elements.- Specified by:
toArrayin interfaceCollection- Returns:
- an array of all of this bag's elements
-
toArray
Deprecated.Returns an array of all of this bag's elements.- Specified by:
toArrayin interfaceCollection- Parameters:
array- the array to populate- Returns:
- an array of all of this bag's elements
-
uniqueSet
Deprecated.Returns an unmodifiable view of the underlying map's key set. -
equals
Deprecated.Compares this Bag to another. This Bag equals another Bag if it contains the same number of occurrences of the same elements.- Specified by:
equalsin interfaceCollection- Overrides:
equalsin classObject- Parameters:
object- the Bag to compare to- Returns:
- true if equal
-
hashCode
public int hashCode()Deprecated.Gets a hash code for the Bag 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()) ^ noOccurances). This hash code is compatible with the Set interface.- Specified by:
hashCodein interfaceCollection- Overrides:
hashCodein classObject- Returns:
- the hash code of the Bag
-
toString
Deprecated.Implement a toString() method suitable for debugging.
-