Top Description Fields Constructors Methods
org.apache.commons.collections4.bag

public Class HashBag<E>

extends AbstractMapBag<E>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Type Parameters
<E>
the type of elements in this bag
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.Collection, .HashMap

Implements Bag, using a HashMap to provide the data storage. This is the standard implementation of a bag.

A Bag stores each object in the collection together with a count of occurrences. Extra methods on the interface allow multiple copies of an object to be added or removed at once. It is important to read the interface javadoc carefully as several methods violate the Collection interface specification.

Since
3.0 (previously in main package v2.0)

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serial version lock

Constructor Summary

AccessConstructor and Description
public
HashBag()

Constructs an empty HashBag.

public
HashBag(final Collection<? extends E>
a collection to copy into this bag
coll
)

Constructs a bag containing all the members of the given collection.

Method Summary

Modifier and TypeMethod and Description
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the bag in using a custom routine.

private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the bag out using a custom routine.

Inherited from org.apache.commons.collections4.bag.AbstractMapBag:
addaddaddAllclearcontainscontainsAllcontainsAlldoReadObjectdoWriteObjectequalsgetCountgetMaphashCodeisEmptyiteratorremoveremoveremoveAllretainAllretainAllsizetoArraytoArraytoStringuniqueSet

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serial version lock

Constructor Detail

HashBagback to summary
public HashBag()

Constructs an empty HashBag.

HashBagback to summary
public HashBag(final Collection<? extends E> coll)

Constructs a bag containing all the members of the given collection.

Parameters
coll:Collection<? extends E>

a collection to copy into this bag

Method Detail

readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the bag in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the bag out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream