xxl.collections
Class AbstractBag

java.lang.Object
  |
  +--xxl.collections.AbstractBag
Direct Known Subclasses:
ListBag

public abstract class AbstractBag
extends java.lang.Object
implements Bag

This abstract class provides a skeleton implementation for bags. One has to implement methods cursor, insert and size in order to obtain an instantiable class.


Field Summary
static Function FACTORY_METHOD
          A factory method to create a default Bag.
 
Constructor Summary
AbstractBag()
           
 
Method Summary
 void clear()
          Removes all elements from the bag such that size will be zero thereafter.
 void close()
          Releases any resources needed so far.
abstract  Cursor cursor()
          Creates a cursor to iterate over the elements of the bag.
abstract  void insert(java.lang.Object object)
          Insert an element into the bag.
 void insertAll(java.util.Iterator objects)
          Insert a bunch of elements into the bag.
abstract  int size()
          Returns the number of elements stored in this bag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY_METHOD

public static final Function FACTORY_METHOD
A factory method to create a default Bag. (see contract for FACTORY_METHOD in interface Bag) This field is set to Bag.FACTORY_METHOD.
Constructor Detail

AbstractBag

public AbstractBag()
Method Detail

cursor

public abstract Cursor cursor()
Creates a cursor to iterate over the elements of the bag.
Specified by:
cursor in interface Bag

insert

public abstract void insert(java.lang.Object object)
Insert an element into the bag. This method does not perform any kind of duplicate detection.
Specified by:
insert in interface Bag
Parameters:
object - the element to be inserted.

size

public abstract int size()
Returns the number of elements stored in this bag.
Specified by:
size in interface Bag

clear

public void clear()
Removes all elements from the bag such that size will be zero thereafter. The implementation creates a cursor and removes all its elements consecutively.
Specified by:
clear in interface Bag

close

public void close()
Releases any resources needed so far. The bag is reopened implicitely by consecutive calls to its methods, if needed. The implementation is given by an empty body.
Specified by:
close in interface Bag

insertAll

public void insertAll(java.util.Iterator objects)
Insert a bunch of elements into the bag. This method does not perform any kind of duplicate detection. The implementation inserts all elements one by one.
Specified by:
insertAll in interface Bag
Parameters:
objects - the iterator providing the elements to be inserted.