wt.eff
Class EffSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended bywt.eff.EffSet
All Implemented Interfaces:
Cloneable, Collection, Serializable, Set

class EffSet
extends AbstractSet
implements Cloneable, Serializable

This class is a modifiable implementation of the java.util.Set interface for storing compatible Eff objects. Two Eff objects, eff1 and eff2 are compatible if and only if:

Note: this collection does not assert the mutual compatibility of its members; this is the responsibility of the application.

The member Eff objects are not stored directly, but via instances of the EffSet.Element wrapper, the only type of element accepted by this set.

Note: this class makes no distinction between Eff objects based on their relative persistence status (i.e. persistent versus non- persistent); this is the responsibility of the application if it is relevant.

This collection does not permit the null element.


Nested Class Summary
static class EffSet.Element
           
 
Field Summary
private static HashMap effFactories
           
private  HashSet hashSet
           
 
Constructor Summary
EffSet()
          Constructs a new, empty EffSet.
EffSet(EffGroup group)
          Constructs a new EffSet containing new (non-persistent) Eff objects representing the argument EffGroup object.
EffSet(EffSet s1, EffSet s2)
          Constructs a new EffSet containing the merge of the argument EffSet objects.
 
Method Summary
 boolean add(Object obj)
          Adds the EffSet.Element object argument to this set if and only if it is not already present.
 void clear()
          Removes all of the elements from this set.
 Object clone()
          Returns a shallow copy of this EffSet: the elements themselves are not cloned.
 boolean contains(Object obj)
          Returns true if this set contains the specified element.
private  EffRange duplicate(EffRange range)
          Creates a deep copy of the argument EffRange object.
 Iterator iterator()
          Returns an iterator over the elements in this set.
private  Eff newEff(Class type, VersionReference target, ObjectReference context, EffRange range)
          Creates a new Eff object of the specified type, referencing the specified target and context, and having the specified range.
 boolean remove(Object obj)
          Removes the argument object from this set if it is present.
 int size()
          Returns the number of elements in this set (its cardinality).
 String toString()
          Returns a String representation of this set, listing each element per its own toString method.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, retainAll, toArray, toArray
 

Field Detail

effFactories

private static HashMap effFactories

hashSet

private HashSet hashSet
Constructor Detail

EffSet

public EffSet()
Constructs a new, empty EffSet.


EffSet

public EffSet(EffGroup group)
Constructs a new EffSet containing new (non-persistent) Eff objects representing the argument EffGroup object. These are mutually compatible by definition.

Throws:
NullPointerException - if the argument is null

EffSet

public EffSet(EffSet s1,
              EffSet s2)
Constructs a new EffSet containing the merge of the argument EffSet objects. The merge is constructed as follows:
  1. A set of merged Eff objects is computed that combines Eff objects from the arguments having overlapping or adjacent ranges, and eliminates duplicates. The new EffSet contains:
    • all objects in the first argument that are elements of the merged set
    • all objects in the second argument that are not elements of the first argument and that are elements of the merged set
    • new (non-persistent) Eff objects that are elements of the merged set and that are not elements of either argument

Throws:
NullPointerException - if either argument is null wt.util.WTRuntimeException if the merged set cannot be computed because its elements are not compatible; note:/b> a failure to throw a wt.util.WTRuntimeException does not imply that all elements are mutually compatible
Method Detail

clone

public Object clone()
Returns a shallow copy of this EffSet: the elements themselves are not cloned.


iterator

public Iterator iterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order. The iterator supports remove operations.

Specified by:
iterator in interface Set

size

public int size()
Returns the number of elements in this set (its cardinality).

Specified by:
size in interface Set

add

public boolean add(Object obj)
Adds the EffSet.Element object argument to this set if and only if it is not already present. Obeys the general contract of java.util.Set.add.

Specified by:
add in interface Set
Throws:
NullPointerException - if the argument is null ClassCastException if the argument is an object of a type other than EffSet.Element

clear

public void clear()
Removes all of the elements from this set.

Specified by:
clear in interface Set

contains

public boolean contains(Object obj)
Returns true if this set contains the specified element.

Specified by:
contains in interface Set

remove

public boolean remove(Object obj)
Removes the argument object from this set if it is present. Obeys the general contract of java.util.Set.remove.

Specified by:
remove in interface Set

toString

public String toString()
Returns a String representation of this set, listing each element per its own toString method. Obeys the general contract of java.util.AbstractSet.toString.

Throws:
a - wt.util.WTRuntimeException wrapping any wt.util.WTPropertyVetoException, which is unexpected

newEff

private Eff newEff(Class type,
                   VersionReference target,
                   ObjectReference context,
                   EffRange range)
            throws WTPropertyVetoException
Creates a new Eff object of the specified type, referencing the specified target and context, and having the specified range.

Throws:
a - wt.util.WTRuntimeException wrapping any reflection exceptions, which are unexpected
WTPropertyVetoException

duplicate

private EffRange duplicate(EffRange range)
Creates a deep copy of the argument EffRange object.

Throws:
a - wt.util.WTRuntimeException wrapping any I/O exceptions, which are unexpected