org.apache.jdo.impl.sco
Class TreeSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byjava.util.TreeSet
              extended byorg.apache.jdo.impl.sco.TreeSet
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, SCO, SCOCollection, java.io.Serializable, java.util.Set, java.util.SortedSet

public class TreeSet
extends java.util.TreeSet
implements SCOCollection

A mutable 2nd class object that represents TreeSet.

Version:
1.0.1
Author:
Marina Vatkina
See Also:
TreeSet, Serialized Form

Field Summary
private static java.lang.String _TreeSet
           
private  java.util.HashSet added
           
private  boolean allowNulls
           
private  java.lang.Class elementType
           
private  int fieldNumber
           
private  java.lang.Object[] frozenElements
           
private static I18NHelper msg
          I18N message handler
private  StateManagerInternal owner
           
private  java.util.HashSet removed
           
 
Fields inherited from class java.util.TreeSet
 
Constructor Summary
TreeSet(java.lang.Class elementType, boolean allowNulls)
          Creates a new empty TreeSet object.
TreeSet(java.lang.Class elementType, boolean allowNulls, java.util.Comparator c)
          Creates a new empty TreeSet object that has the specified comparator.
 
Method Summary
 boolean add(java.lang.Object o)
          Adds the specified element to this set if it is not already present.
 boolean addAll(java.util.Collection c)
          Adds all of the elements in the specified collection to this collection
 void addAllInternal(java.util.Collection c)
          Adds objects of the given Collection to this Collection without recording the event.
 void addInternal(java.lang.Object o)
          Adds object to the Collection without recording the event.
 boolean allowNulls()
          Returns whether nulls are permitted as elements.
 void clear()
          Removes all of the elements from this set.
 void clearInternal()
          Clears Collection without recording the event.
 java.lang.Object clone()
          Creates and returns a copy of this object.
 java.util.Comparator comparator()
           
 boolean contains(java.lang.Object o)
          These methods need to thaw the map before performing the operation.
 boolean containsAll(java.util.Collection c)
           
 java.util.Iterator eitherIterator()
          Create an iterator regardless whether the collection is frozen.
 boolean equals(java.lang.Object o)
           
 java.lang.Object first()
           
 java.util.Iterator frozenIterator()
          Create a new iterator over the frozen elements without thawing.
 java.util.Collection getAdded()
          Returns the Collection of added elements
 java.lang.Class getElementType()
          Returns the element type assignment compatible with all added elements of this collection.
 java.lang.String getFieldName()
          Returns the field name
private  java.lang.Object[] getFrozen()
          Returns the frozen contents of this Collection, if this Collection is implicitly user-orderable.
 java.lang.Object getOwner()
          Returns the owner object of the SCO instance
 java.util.Collection getRemoved()
          Returns the Collection of removed elements
 int hashCode()
           
 java.util.SortedSet headSet(java.lang.Object toElement)
           
 boolean isEmpty()
           
private  boolean isFrozen()
          Returns the frozen state of this set.
 java.util.Iterator iterator()
           
 java.lang.Object last()
           
private  void makeDirty()
          Notify StateManager to mark field as dirty.
 boolean remove(java.lang.Object o)
          Removes the given element from this set if it is present.
 boolean removeAll(java.util.Collection c)
          Removes from this collection all of its elements that are contained in the specified collection (optional operation).
 void removeInternal(java.lang.Object o)
          Removes element from the Collection without recording the event.
 void reset()
          Resets removed and added lists after flush
 boolean retainAll(java.util.Collection c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 void setFrozen(java.lang.Object[] elements)
          Set the contents of this Collection from the frozen elements, if this Collection is implicitly user-orderable.
 void setOwner(java.lang.Object owner, int fieldNumber)
          Sets the owner and field number.
 int size()
           
 java.util.SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
           
 java.util.SortedSet tailSet(java.lang.Object fromElement)
           
private  void thaw()
          Thaw the frozen elements of this collection.
 java.lang.String toString()
           
private  void trackUpdates(boolean modified)
          Notify StateManager to process the changes.
 void unsetOwner(java.lang.Object owner, int fieldNumber)
          Nullifies references to the owner Object iff the passed in owner and fieldNumber match.
 
Methods inherited from class java.util.TreeSet
 
Methods inherited from class java.util.AbstractCollection
toArray, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
toArray, toArray
 
Methods inherited from interface java.util.Set
toArray, toArray
 

Field Detail

owner

private transient StateManagerInternal owner

fieldNumber

private transient int fieldNumber

elementType

private transient java.lang.Class elementType

allowNulls

private transient boolean allowNulls

added

private transient java.util.HashSet added

removed

private transient java.util.HashSet removed

frozenElements

private transient java.lang.Object[] frozenElements

msg

private static final I18NHelper msg
I18N message handler


_TreeSet

private static final java.lang.String _TreeSet
See Also:
Constant Field Values
Constructor Detail

TreeSet

public TreeSet(java.lang.Class elementType,
               boolean allowNulls)
Creates a new empty TreeSet object.

Parameters:
elementType - the element types allowed
allowNulls - true if nulls are allowed
See Also:
TreeSet

TreeSet

public TreeSet(java.lang.Class elementType,
               boolean allowNulls,
               java.util.Comparator c)
Creates a new empty TreeSet object that has the specified comparator.

Parameters:
elementType - the element types allowed
allowNulls - true if nulls are allowed
c - the comparator that will be used to sort this set. A null value indicates that the elements' natural ordering should be used.
See Also:
TreeSet
Method Detail

add

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

Specified by:
add in interface java.util.Collection
Parameters:
o - element to be added to this set.
Returns:
true if the set did not already contain the specified element.
See Also:
TreeSet

addAll

public boolean addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this collection

Specified by:
addAll in interface java.util.Collection
Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the addAll method is not supported by this collection.
See Also:
AbstractCollection, TreeSet

remove

public boolean remove(java.lang.Object o)
Removes the given element from this set if it is present.

Specified by:
remove in interface java.util.Collection
Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.
See Also:
TreeSet

removeAll

public boolean removeAll(java.util.Collection c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).

Processes each element remove internally not to have call backs into #remove(Object).

Specified by:
removeAll in interface java.util.Collection
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - removeAll is not supported by this collection.
See Also:
TreeSet, AbstractCollection

retainAll

public boolean retainAll(java.util.Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).

Specified by:
retainAll in interface java.util.Collection
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the retainAll method is not supported by this collection.
See Also:
TreeSet, AbstractCollection

clear

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

Specified by:
clear in interface java.util.Collection
See Also:
TreeSet

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Mutable Second Class Objects are required to provide a public clone method in order to allow for copying PersistenceCapable objects. In contrast to Object.clone(), this method must not throw a CloneNotSupportedException.

Specified by:
clone in interface SCO

reset

public void reset()
Description copied from interface: SCOCollection
Resets removed and added lists after flush

Specified by:
reset in interface SCOCollection
See Also:
SCOCollection.reset()

addInternal

public void addInternal(java.lang.Object o)
Description copied from interface: SCOCollection
Adds object to the Collection without recording the event. Used internaly to initially populate the Collection

Specified by:
addInternal in interface SCOCollection
See Also:
SCOCollection.addInternal(Object o)

addAllInternal

public void addAllInternal(java.util.Collection c)
Description copied from interface: SCOCollection
Adds objects of the given Collection to this Collection without recording the event. Used internaly to initially populate the Collection

Specified by:
addAllInternal in interface SCOCollection
See Also:
SCOCollection.addAllInternal(Collection c)

getAdded

public java.util.Collection getAdded()
Description copied from interface: SCOCollection
Returns the Collection of added elements

Specified by:
getAdded in interface SCOCollection
Returns:
Collection of the added elements as java.util.Collection
See Also:
SCOCollection.getAdded()

getRemoved

public java.util.Collection getRemoved()
Description copied from interface: SCOCollection
Returns the Collection of removed elements

Specified by:
getRemoved in interface SCOCollection
Returns:
Collection of the removed elements as java.util.Collection
See Also:
SCOCollection.getRemoved()

clearInternal

public void clearInternal()
Description copied from interface: SCOCollection
Clears Collection without recording the event. Used internaly to clear the Collection

Specified by:
clearInternal in interface SCOCollection
See Also:
SCOCollection.clearInternal()

removeInternal

public void removeInternal(java.lang.Object o)
Description copied from interface: SCOCollection
Removes element from the Collection without recording the event. Used internaly to update the Collection

Specified by:
removeInternal in interface SCOCollection
See Also:
SCOCollection.removeInternal(Object o)

unsetOwner

public void unsetOwner(java.lang.Object owner,
                       int fieldNumber)
Description copied from interface: SCO
Nullifies references to the owner Object iff the passed in owner and fieldNumber match.

Specified by:
unsetOwner in interface SCO
Parameters:
owner - the existing owner object.
fieldNumber - the existing number of the field.
See Also:
SCO.unsetOwner(Object owner, int fieldNumber)

setOwner

public void setOwner(java.lang.Object owner,
                     int fieldNumber)
Description copied from interface: SCO
Sets the owner and field number. Called by StateManager upon assignment to a managed instance.

Specified by:
setOwner in interface SCO
Parameters:
owner - the owner object.
fieldNumber - the number of the field associated with this instance.
See Also:
(Object owner, int fieldNumber)

getOwner

public java.lang.Object getOwner()
Description copied from interface: SCO
Returns the owner object of the SCO instance

Specified by:
getOwner in interface SCO
Returns:
owner object
See Also:
SCO.getOwner()

getFieldName

public java.lang.String getFieldName()
Description copied from interface: SCO
Returns the field name

Specified by:
getFieldName in interface SCO
Returns:
field name as java.lang.String
See Also:
SCO.getFieldName()

makeDirty

private void makeDirty()
Notify StateManager to mark field as dirty.


trackUpdates

private void trackUpdates(boolean modified)
Notify StateManager to process the changes.


getElementType

public java.lang.Class getElementType()
Description copied from interface: SCOCollection
Returns the element type assignment compatible with all added elements of this collection.

Specified by:
getElementType in interface SCOCollection
Returns:
the element type assignment compatible with all added elements.
See Also:
{

allowNulls

public boolean allowNulls()
Description copied from interface: SCOCollection
Returns whether nulls are permitted as elements.

Specified by:
allowNulls in interface SCOCollection
Returns:
true if nulls are permitted as elements.
See Also:
{

contains

public boolean contains(java.lang.Object o)
These methods need to thaw the map before performing the operation.

Specified by:
contains in interface java.util.Collection

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.util.Collection

size

public int size()
Specified by:
size in interface java.util.Collection

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection

toString

public java.lang.String toString()

subSet

public java.util.SortedSet subSet(java.lang.Object fromElement,
                                  java.lang.Object toElement)
Specified by:
subSet in interface java.util.SortedSet

headSet

public java.util.SortedSet headSet(java.lang.Object toElement)
Specified by:
headSet in interface java.util.SortedSet

tailSet

public java.util.SortedSet tailSet(java.lang.Object fromElement)
Specified by:
tailSet in interface java.util.SortedSet

comparator

public java.util.Comparator comparator()
Specified by:
comparator in interface java.util.SortedSet

first

public java.lang.Object first()
                       throws java.util.NoSuchElementException
Specified by:
first in interface java.util.SortedSet
Throws:
java.util.NoSuchElementException

last

public java.lang.Object last()
                      throws java.util.NoSuchElementException
Specified by:
last in interface java.util.SortedSet
Throws:
java.util.NoSuchElementException

isFrozen

private boolean isFrozen()
Returns the frozen state of this set.

Returns:
true if this set is frozen.
Since:
1.0.1

getFrozen

private java.lang.Object[] getFrozen()
Returns the frozen contents of this Collection, if this Collection is implicitly user-orderable. If the collection is not frozen already, freeze it first.

Returns:
the frozen elements of this collection.
Since:
1.0.1

setFrozen

public void setFrozen(java.lang.Object[] elements)
Set the contents of this Collection from the frozen elements, if this Collection is implicitly user-orderable.

Specified by:
setFrozen in interface SCOCollection
Parameters:
elements - the frozen elements of this set.
Since:
1.0.1

thaw

private void thaw()
Thaw the frozen elements of this collection. If the elements are frozen, retrieve them from the datastore and internally add them. Then reset the frozen state since they're not frozen any more.

Since:
1.0.1

frozenIterator

public java.util.Iterator frozenIterator()
Create a new iterator over the frozen elements without thawing.

Specified by:
frozenIterator in interface SCOCollection
Returns:
the frozen iterator.
Since:
1.0.1

eitherIterator

public java.util.Iterator eitherIterator()
Create an iterator regardless whether the collection is frozen. If frozen, don't thaw the collection, but get a frozen iterator. If thawed, get a regular iterator.

Specified by:
eitherIterator in interface SCOCollection
Returns:
the iterator.
Since:
1.0.1