net.walend.lyophil.soft
Class SoftMemSet

java.lang.Object
  |
  +--net.walend.lyophil.memory.MemSet
        |
        +--net.walend.lyophil.soft.SoftMemSet
All Implemented Interfaces:
Collection, CollectionOfFreezables, HasState, MutableCollection, MutableCollectionOfFreezables, MutableSet, MutableSetOfFreezables, Set, SetOfFreezables

public class SoftMemSet
extends MemSet

This class implements MutableSetOfFreezables on top of a SoftHashMap.

Since:
20010830
Author:
David Walend

Field Summary
 
Fields inherited from class net.walend.lyophil.memory.MemSet
 
Fields inherited from interface net.walend.lyophil.collection.SetOfFreezables
EMPTY
 
Constructor Summary
SoftMemSet()
          Creates a new Set with a capacity of 7.
SoftMemSet(CollectionOfFreezables c)
          Creates a new Set that is a copy of c
SoftMemSet(int size)
          Creates a new Set with capacity of size.
 
Method Summary
 boolean add(java.lang.Object object)
          Adds a Object to the MutableCollection.
 boolean addAll(Collection c)
          Adds all the Objects in c to this MutableCollection by using the add() method.
 boolean addAllIdentifiedBy(Collection c)
          Adds all the Freezables identified by c to this MutableCollection using the addIdentifiedBy method.
 boolean addIdentifiedBy(java.io.Serializable id)
          Adds a Freezable to the MutableCollection.
 void clear()
          Removes all of the Objects in this collection.
 boolean contains(java.lang.Object ob)
          Returns true if this collection contains the specified Object.
 boolean containsAll(Collection c)
          Returns true if this collection contains all of the Objects in the specified collection.
 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.
protected  MutableMap createIdentifierMap(int size)
          This method is called by the constructor.
 FreezableIterator freezableIterator()
          Returns an iterator over the Freezables in this collection.
protected  Freezable getFreezable(java.io.Serializable identifier)
           
 java.lang.Object getGuard()
          Returns the synch guard for this object
 Collection getIdentifiers()
          Returns a Collection of all the identifiers in this collection.
 java.util.Collection getJavaCollection()
          Return a java.util.Collection of these Objects.
 java.util.Set getJavaSet()
          Return a java.util.Collection of these Objects.
 java.util.Iterator identifierIterator()
          Returns an iterator over the identifiers in this collection.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the Objects in this collection.
 boolean remove(java.lang.Object object)
          Removes a Object from the MutableCollection.
 boolean removeAll(Collection c)
          Removes all the Objects in c from this MutableCollection by using the remove() method.
 boolean removeAllIdentifiedBy(Collection c)
          Removes all the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method.
 boolean removeIdentifiedBy(java.io.Serializable id)
          Removes a Freezable from the MutableCollection, based on that Freezable's identifier.
 boolean retainAll(Collection c)
          Retains only the Objects in this collection that are contained in c by using the contains() and remove() methods.
 boolean retainAllIdentifiedBy(Collection c)
          Removes all but the Freezables identified by c from this MutableCollection using the removeIdentifiedBy method.
 boolean sameContentsAs(Collection c)
          Returns true if this Collection's contents are equal to c's.
 boolean sameStateAs(HasState victem)
          If two HasStates have the same internal state, return true.
 int size()
          Returns the number of elements in this collection.
 java.lang.String toString()
           
 
Methods inherited from class net.walend.lyophil.memory.MemSet
checkFreezable, getIdentitor, getIDsToFreezables, getPrincipleInterface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SoftMemSet

public SoftMemSet()
Creates a new Set with a capacity of 7.


SoftMemSet

public SoftMemSet(int size)
Creates a new Set with capacity of size.


SoftMemSet

public SoftMemSet(CollectionOfFreezables c)
Creates a new Set that is a copy of c

Method Detail

createIdentifierMap

protected MutableMap createIdentifierMap(int size)
This method is called by the constructor. It provides a SoftHashMap.

Overrides:
createIdentifierMap in class MemSet

getGuard

public java.lang.Object getGuard()
Returns the synch guard for this object


getFreezable

protected Freezable getFreezable(java.io.Serializable identifier)
Overrides:
getFreezable in class MemSet

size

public int size()
Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface Collection
Overrides:
size in class MemSet

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.

Specified by:
isEmpty in interface Collection
Overrides:
isEmpty in class MemSet

contains

public boolean contains(java.lang.Object ob)
Returns true if this collection contains the specified Object.

Specified by:
contains in interface Collection
Overrides:
contains in class MemSet

iterator

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

Specified by:
iterator in interface Collection
Overrides:
iterator in class MemSet

containsAll

public boolean containsAll(Collection c)
Returns true if this collection contains all of the Objects in the specified collection. This method uses the contains() method.

Specified by:
containsAll in interface Collection
Overrides:
containsAll in class MemSet

sameContentsAs

public boolean sameContentsAs(Collection c)
Returns true if this Collection's contents are equal to c's.

Specified by:
sameContentsAs in interface Collection
Overrides:
sameContentsAs in class MemSet

getJavaCollection

public java.util.Collection getJavaCollection()
Return a java.util.Collection of these Objects.

Specified by:
getJavaCollection in interface Collection
Overrides:
getJavaCollection in class MemSet

add

public boolean add(java.lang.Object object)
Adds a Object to the MutableCollection. Sets will only add it to the Set if it's not already there.

Specified by:
add in interface MutableCollection
Overrides:
add in class MemSet
Returns:
true if the MutableCollection changes, false if not.

remove

public boolean remove(java.lang.Object object)
Removes a Object from the MutableCollection.

Specified by:
remove in interface MutableCollection
Overrides:
remove in class MemSet
Returns:
true if the MutableCollection changes, false if not.

addAll

public boolean addAll(Collection c)
Adds all the Objects in c to this MutableCollection by using the add() method. Returns true if this MutableCollection changes.

Specified by:
addAll in interface MutableCollection
Overrides:
addAll in class MemSet

removeAll

public boolean removeAll(Collection c)
Removes all the Objects in c from this MutableCollection by using the remove() method. Returns true if this Colleciton changes.

Specified by:
removeAll in interface MutableCollection
Overrides:
removeAll in class MemSet

retainAll

public boolean retainAll(Collection c)
Retains only the Objects in this collection that are contained in c by using the contains() and remove() methods. Returns true if this Colleciton changes.

Specified by:
retainAll in interface MutableCollection
Overrides:
retainAll in class MemSet

clear

public void clear()
Removes all of the Objects in this collection.

Specified by:
clear in interface MutableCollection
Overrides:
clear in class MemSet

getJavaSet

public java.util.Set getJavaSet()
Return a java.util.Collection of these Objects.

Specified by:
getJavaSet in interface Set
Overrides:
getJavaSet in class MemSet

containsIdentifiedBy

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

Specified by:
containsIdentifiedBy in interface CollectionOfFreezables
Overrides:
containsIdentifiedBy in class MemSet

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
Overrides:
containsAllIdentifiedBy in class MemSet

freezableIterator

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

Specified by:
freezableIterator in interface CollectionOfFreezables
Overrides:
freezableIterator in class MemSet

identifierIterator

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

Specified by:
identifierIterator in interface CollectionOfFreezables
Overrides:
identifierIterator in class MemSet

getIdentifiers

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

Specified by:
getIdentifiers in interface CollectionOfFreezables
Overrides:
getIdentifiers in class MemSet

addIdentifiedBy

public 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.

Specified by:
addIdentifiedBy in interface MutableCollectionOfFreezables
Overrides:
addIdentifiedBy in class MemSet
Returns:
true if the MutableCollection changes, false if not.
Throws:
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

public 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.

Specified by:
removeIdentifiedBy in interface MutableCollectionOfFreezables
Overrides:
removeIdentifiedBy in class MemSet
Returns:
true if the MutableCollection changes, false if not.

addAllIdentifiedBy

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

Specified by:
addAllIdentifiedBy in interface MutableCollectionOfFreezables
Overrides:
addAllIdentifiedBy in class MemSet
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.

removeAllIdentifiedBy

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

Specified by:
removeAllIdentifiedBy in interface MutableCollectionOfFreezables
Overrides:
removeAllIdentifiedBy in class MemSet
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

public 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.

Specified by:
retainAllIdentifiedBy in interface MutableCollectionOfFreezables
Overrides:
retainAllIdentifiedBy in class MemSet
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.

sameStateAs

public boolean sameStateAs(HasState victem)
Description copied from interface: HasState
If two HasStates have the same internal state, return true.

For objects with subobjects, Generally this method should only return true if the internal objects are equal. Implement a contentsHaveSameState() method to determine if the contents have the same state.

Specified by:
sameStateAs in interface HasState
Overrides:
sameStateAs in class MemSet

toString

public java.lang.String toString()
Overrides:
toString in class MemSet


Copyright (c) 2000, 2001, David Walend