Top Description Fields Constructors Methods
org.eclipse.collections.impl.bag.mutable

public Class HashBag<T>

extends AbstractHashBag<T>
implements Externalizable
Class Inheritance
All Implemented Interfaces
java.io.Externalizable, java.io.Serializable
Imports
java.io.Externalizable, .IOException, .ObjectInput, .ObjectOutput, java.util.Arrays, org.eclipse.collections.api.bag.Bag, .MutableBag, org.eclipse.collections.api.block.predicate.primitive.IntPredicate, org.eclipse.collections.api.map.primitive.MutableObjectIntMap, org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap, org.eclipse.collections.impl.utility.ArrayIterate, .Iterate

A HashBag is a MutableBag which uses a Map as its underlying data store. Each key in the Map represents some item, and the value in the map represents the current number of occurrences of that item.
Since
1.0

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.eclipse.collections.impl.bag.mutable.AbstractHashBag:
itemssize

Constructor Summary

AccessConstructor and Description
public
public
HashBag(int size)

private

Method Summary

Modifier and TypeMethod and Description
protected int
public static <E> HashBag<E>
public static <E> HashBag<E>
newBag(int size)

public static <E> HashBag<E>
newBag(Bag<? extends E> source)

public static <E> HashBag<E>
newBag(Iterable<? extends E> source)

public static <E> HashBag<E>
newBagWith(E... elements)

public MutableBag<T>
public void
readExternal(ObjectInput in)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

public MutableBag<T>
public void
trimToSize()

Rehashes every element in the set into a new backing table of the smallest possible size and eliminating removed sentinels.

public HashBag<T>
with(T element)

Overrides default org.eclipse.collections.api.bag.MutableBag.with, org.eclipse.collections.api.bag.MutableBagIterable.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public HashBag<T>
with(T... elements)

Overrides default org.eclipse.collections.api.bag.MutableBag.with, org.eclipse.collections.api.bag.MutableBagIterable.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public HashBag<T>
with(T element1, T element2)

public HashBag<T>
with(T element1, T element2, T element3)

public HashBag<T>
withAll(Iterable<? extends T> iterable)

Overrides default org.eclipse.collections.api.bag.MutableBag.withAll, org.eclipse.collections.api.bag.MutableBagIterable.withAll.

This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.

public HashBag<T>
without(T element)

Overrides default org.eclipse.collections.api.bag.MutableBag.without, org.eclipse.collections.api.bag.MutableBagIterable.without.

This method allows mutable and fixed size collections the ability to remove elements from their existing elements.

public HashBag<T>
withoutAll(Iterable<? extends T> iterable)

Overrides default org.eclipse.collections.api.bag.MutableBag.withoutAll, org.eclipse.collections.api.bag.MutableBagIterable.withoutAll.

This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.

public void
writeExternal(ObjectOutput out)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from org.eclipse.collections.impl.bag.mutable.AbstractHashBag:
addaddOccurrencesallSatisfyWithOccurrencesanySatisfyWithOccurrencesclearcontainsdetectWithOccurrencesdistinctVieweachequalsforEachWithforEachWithIndexforEachWithOccurrencesgetKeysViewgroupBygroupByEachhashCodeisEmptyiteratornoneSatisfyWithOccurrencesoccurrencesOfremoveremoveAllIterableremoveIfremoveIfWithremoveOccurrencessetOccurrencessizesizeDistincttoMapOfItemToCount

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

HashBagback to summary
public HashBag()
HashBagback to summary
public HashBag(int size)
HashBagback to summary
private HashBag(MutableObjectIntMap<T> map)

Method Detail

computeHashCodeback to summary
protected int computeHashCode(T item)

Implements abstract org.eclipse.collections.impl.bag.mutable.AbstractHashBag.computeHashCode.

Annotations
@Override
newBagback to summary
public static <E> HashBag<E> newBag()
newBagback to summary
public static <E> HashBag<E> newBag(int size)
newBagback to summary
public static <E> HashBag<E> newBag(Bag<? extends E> source)
newBagback to summary
public static <E> HashBag<E> newBag(Iterable<? extends E> source)
newBagWithback to summary
public static <E> HashBag<E> newBagWith(E... elements)
newEmptyback to summary
public MutableBag<T> newEmpty()

Implements org.eclipse.collections.api.bag.MutableBag.newEmpty, org.eclipse.collections.api.collection.MutableCollection.newEmpty.

Doc from org.eclipse.collections.api.collection.MutableCollection.newEmpty.

Creates a new empty mutable version of the same collection type. For example, if this instance is a FastList, this method will return a new empty FastList. If the class of this instance is immutable or fixed size (i.e. SingletonList) then a mutable alternative to the class will be provided.

Annotations
@Override
readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Annotations
@Override
Exceptions
IOException:
if I/O errors occur
ClassNotFoundException:
If the class for an object being restored cannot be found.
selectByOccurrencesback to summary
public MutableBag<T> selectByOccurrences(IntPredicate predicate)

Implements org.eclipse.collections.api.bag.MutableBag.selectByOccurrences, org.eclipse.collections.api.bag.MutableBagIterable.selectByOccurrences, org.eclipse.collections.api.bag.Bag.selectByOccurrences.

Doc from org.eclipse.collections.api.bag.Bag.selectByOccurrences.

Returns all elements of the bag that have a number of occurrences that satisfy the predicate.

Annotations
@Override
trimToSizeback to summary
public void trimToSize()

Rehashes every element in the set into a new backing table of the smallest possible size and eliminating removed sentinels.

Since
12.0
withback to summary
public HashBag<T> with(T element)

Overrides default org.eclipse.collections.api.bag.MutableBag.with, org.eclipse.collections.api.bag.MutableBagIterable.with.

Doc from org.eclipse.collections.api.collection.MutableCollection.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.with("1");
list = list.with("2");
return list;
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.
Annotations
@Override
withback to summary
public HashBag<T> with(T... elements)

Overrides default org.eclipse.collections.api.bag.MutableBag.with, org.eclipse.collections.api.bag.MutableBagIterable.with.

Doc from org.eclipse.collections.api.collection.MutableCollection.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.with("1");
list = list.with("2");
return list;
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.
withback to summary
public HashBag<T> with(T element1, T element2)
withback to summary
public HashBag<T> with(T element1, T element2, T element3)
withAllback to summary
public HashBag<T> withAll(Iterable<? extends T> iterable)

Overrides default org.eclipse.collections.api.bag.MutableBag.withAll, org.eclipse.collections.api.bag.MutableBagIterable.withAll.

Doc from org.eclipse.collections.api.collection.MutableCollection.withAll.

This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new elements to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.withAll(FastList.newListWith("1", "2"));
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by withAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling addAll on itself.
Annotations
@Override
withoutback to summary
public HashBag<T> without(T element)

Overrides default org.eclipse.collections.api.bag.MutableBag.without, org.eclipse.collections.api.bag.MutableBagIterable.without.

Doc from org.eclipse.collections.api.collection.MutableCollection.without.

This method allows mutable and fixed size collections the ability to remove elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling remove. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.without("1");
list = list.without("2");
return list;
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by without, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling remove on itself.
Annotations
@Override
withoutAllback to summary
public HashBag<T> withoutAll(Iterable<? extends T> iterable)

Overrides default org.eclipse.collections.api.bag.MutableBag.withoutAll, org.eclipse.collections.api.bag.MutableBagIterable.withoutAll.

Doc from org.eclipse.collections.api.collection.MutableCollection.withoutAll.

This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling removeAll. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.withoutAll(FastList.newListWith("1", "2"));
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by withoutAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling removeAll on itself.
Annotations
@Override
writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Annotations
@Override
Exceptions
IOException:
Includes any I/O exceptions that may occur