net.walend.lyophil.collection
Class AbstractHashSetOfFreezables

java.lang.Object
  |
  +--net.walend.collection.AbstractHashSet
        |
        +--net.walend.lyophil.collection.AbstractHashSetOfFreezables
All Implemented Interfaces:
java.lang.Cloneable, Collection, CollectionOfFreezables, HasState, java.io.Serializable, Set, SetOfFreezables
Direct Known Subclasses:
HashSetOfFreezables, MutableHashSetOfFreezables

public abstract class AbstractHashSetOfFreezables
extends AbstractHashSet
implements SetOfFreezables

An abstract HashSet that includes special methods for handling Freezables. It holds everything in memory, and never returns to the Freezer to thaw an instance. By default it uses the FreezableIdentitor.

Since:
20010726
Author:
David Walend

Nested Class Summary
private  class AbstractHashSetOfFreezables.IdentifierIterator
           
 
Field Summary
 
Fields inherited from class net.walend.collection.AbstractHashSet
 
Fields inherited from interface net.walend.lyophil.collection.SetOfFreezables
EMPTY
 
Constructor Summary
protected AbstractHashSetOfFreezables()
          Constructs a new, empty set; the backing MutableHashMap instance has default capacity and load factor, which is 0.75, and uses the FreezableIdentitor.
protected AbstractHashSetOfFreezables(Collection c)
          Constructs a new set containing the elements in the specified collection.
protected AbstractHashSetOfFreezables(java.util.Collection c)
          Constructs a new set containing the elements in the specified java.util.Collection.
protected AbstractHashSetOfFreezables(Identitor identitor)
          Constructs a new, empty set; the backing MutableHashMap instance has default capacity and load factor, which is 0.75.
protected AbstractHashSetOfFreezables(Identitor identitor, int initialCapacity)
          Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and default load factor, which is 0.75.
protected AbstractHashSetOfFreezables(Identitor identitor, int initialCapacity, float loadFactor)
          Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and the specified load factor.
protected AbstractHashSetOfFreezables(int initialCapacity)
          Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and default load factor, which is 0.75.
protected AbstractHashSetOfFreezables(int initialCapacity, float loadFactor)
          Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and the specified load factor.
 
Method Summary
protected  boolean add(java.lang.Object o)
          Adds the specified element to this set if it is not already present.
protected  boolean addAllIdentifiedBy(Collection c)
          Adds all the Freezables identified by c to this MutableCollection using the addIdentifier method.
protected  boolean addIdentifiedBy(java.io.Serializable id)
          Adds a Freezable to the MutableCollection.
 boolean containsAllIdentifiedBy(Collection ids)
          Returns true if this collection contains the specified Freezables.
 boolean containsIdentifiedBy(java.io.Serializable id)
          Returns true if this collection contains the specified Freezable.
 FreezableIterator freezableIterator()
          Returns an iterator over the Freezables in this collection.
protected  Freezable getFreezableForID(java.io.Serializable id)
           
protected  Freezer getFreezer()
           
 Collection getIdentifiers()
          Returns a Collection of all the identifiers in this collection.
 java.util.Iterator identifierIterator()
          Returns an iterator over the identifiers in this collection.
protected  boolean removeAllIdentifiedBy(Collection c)
          Removes all the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method.
protected  boolean removeIdentifiedBy(java.io.Serializable id)
          Removes a Freezable from the MutableCollection, based on that Freezable's identifier.
protected  boolean retainAllIdentifiedBy(Collection c)
          Removes all but the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method.
 
Methods inherited from class net.walend.collection.AbstractHashSet
addAll, clear, clone, contains, containsAll, getIdentitor, getJavaCollection, getJavaSet, getPrincipleInterface, isEmpty, iterator, remove, removeAll, retainAll, sameContentsAs, sameStateAs, size, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.walend.collection.Collection
contains, containsAll, getIdentitor, getJavaCollection, isEmpty, iterator, sameContentsAs, size
 
Methods inherited from interface net.walend.collection.HasState
getPrincipleInterface, sameStateAs
 
Methods inherited from interface net.walend.collection.Set
getJavaSet
 

Constructor Detail

AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables()
Constructs a new, empty set; the backing MutableHashMap instance has default capacity and load factor, which is 0.75, and uses the FreezableIdentitor.


AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(Collection c)
Constructs a new set containing the elements in the specified collection. The capacity of the backing MutableHashMap instance is twice the size of the specified collection or eleven (whichever is greater), the default load factor (which is 0.75) is used. It uses the same Identitor as c.

Parameters:
c - the collection whose elements are to be placed into this set.

AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(java.util.Collection c)
Constructs a new set containing the elements in the specified java.util.Collection. The capacity of the backing MutableHashMap instance is twice the size of the specified collection or eleven (whichever is greater), and the default load factor (which is 0.75) is used. It uses the DefaultIdentitor.

Parameters:
c - the collection whose elements are to be placed into this set.

AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(int initialCapacity,
                                      float loadFactor)
Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and the specified load factor. It uses the FreezableIdentitor.

Parameters:
initialCapacity - the initial capacity of the hash map.
loadFactor - the load factor of the hash map.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(int initialCapacity)
Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and default load factor, which is 0.75. It uses the FreezableIdentitor.

Parameters:
initialCapacity - the initial capacity of the hash table.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero.

AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(Identitor identitor)
Constructs a new, empty set; the backing MutableHashMap instance has default capacity and load factor, which is 0.75. It uses the specified identitor.


AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(Identitor identitor,
                                      int initialCapacity,
                                      float loadFactor)
Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and the specified load factor. It uses the specified identitor.

Parameters:
identitor -
initialCapacity - the initial capacity of the hash map.
loadFactor - the load factor of the hash map.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

AbstractHashSetOfFreezables

protected AbstractHashSetOfFreezables(Identitor identitor,
                                      int initialCapacity)
Constructs a new, empty set; the backing MutableHashMap instance has the specified initial capacity and default load factor, which is 0.75. It uses the specified identitor.

Parameters:
identitor -
initialCapacity - the initial capacity of the hash table.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero.
Method Detail

add

protected boolean add(java.lang.Object o)
Adds the specified element to this set if it is not already present.

Overrides:
add in class AbstractHashSet
Parameters:
o - element to be added to this set.
Returns:
true if the set did not already contain the specified element.

getFreezer

protected Freezer getFreezer()

getFreezableForID

protected Freezable getFreezableForID(java.io.Serializable id)

addIdentifiedBy

protected boolean addIdentifiedBy(java.io.Serializable id)
Adds a Freezable to the MutableCollection. Sets will only add it to the Set if it's not already there, based on the getIdentifier() and sameIdentifierAs() methods. Lists will tack it on the end of a list.

Returns:
true if the MutableCollection changes, false if not.
Throws:
java.lang.UnsupportedOperationException - add is not supported by this collection.
java.lang.ClassCastException - class of the specified element prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of this element prevents it from being added to this collection.
ZombieIdentifierException - if f is not in the Freezer and this implementation checks on add.

removeIdentifiedBy

protected boolean removeIdentifiedBy(java.io.Serializable id)
Removes a Freezable from the MutableCollection, based on that Freezable's identifier. This method uses the getIdentifier() and sameIdentifierAs() methods of the Freezables to find the right one.

The AbstractHashSet implementation has to scan the freezables in the Set to find the right one.

Returns:
true if the MutableCollection changes, false if not.
Throws:
java.lang.UnsupportedOperationException - remove is not supported by this collection.

addAllIdentifiedBy

protected boolean addAllIdentifiedBy(Collection c)
Adds all the Freezables identified by c to this MutableCollection using the addIdentifier method. Returns true if this MutableCollection changes.

Throws:
java.lang.UnsupportedOperationException - if this collection does not support the addAll method.
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.

removeAllIdentifiedBy

protected boolean removeAllIdentifiedBy(Collection c)
Removes all the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method. Returns true if this MutableCollection changes.

Throws:
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.

retainAllIdentifiedBy

protected boolean retainAllIdentifiedBy(Collection c)
Removes all but the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method. Returns true if this MutableCollection changes.

Throws:
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
java.lang.IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.

containsIdentifiedBy

public boolean containsIdentifiedBy(java.io.Serializable id)
Returns true if this collection contains the specified Freezable. This method uses Serializable's equals() method.

This implementation has to scan the Set.

Specified by:
containsIdentifiedBy in interface CollectionOfFreezables

containsAllIdentifiedBy

public boolean containsAllIdentifiedBy(Collection ids)
Returns true if this collection contains the specified Freezables. This method uses Serializable's equals() method.

Specified by:
containsAllIdentifiedBy in interface CollectionOfFreezables

freezableIterator

public FreezableIterator freezableIterator()
Returns an iterator over the Freezables in this collection.

Specified by:
freezableIterator in interface CollectionOfFreezables

identifierIterator

public java.util.Iterator identifierIterator()
Returns an iterator over the identifiers in this collection.

Specified by:
identifierIterator in interface CollectionOfFreezables

getIdentifiers

public Collection getIdentifiers()
Returns a Collection of all the identifiers in this collection.

Specified by:
getIdentifiers in interface CollectionOfFreezables


Copyright (c) 2000, 2001, David Walend