net.sf.ivmaidns.storage
Class StorageEnumerator

java.lang.Object
  extended by net.sf.ivmaidns.util.ObservedCore
      extended by net.sf.ivmaidns.storage.StorageEnumerator
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Enumeration, MultiObservable, ReallyCloneable, TrimToSizeable, Verifiable

public class StorageEnumerator
extends ObservedCore
implements ReallyCloneable, java.io.Serializable, java.util.Enumeration

Storage elements enumerator (observable location wrapper).

Version:
2.0
Author:
Ivan Maidanski
See Also:
Serialized Form

Field Summary
protected  int location
          NOTE: If location !
protected  Storage source
          NOTE: source must be !
 
Constructor Summary
StorageEnumerator(Storage source)
          NOTE: source must be !
 
Method Summary
 java.lang.Object clone()
          NOTE: Must be synchronized outside with source.
 boolean equals(java.lang.Object obj)
          NOTE: Must be synchronized outside with source.
 java.lang.Object get()
          NOTE: Result is value at the current location.
 int hashCode()
          NOTE: source is not hashed.
 boolean hasMoreElements()
           
 void insertAtPrevious(boolean isChild, java.lang.Object value)
          NOTE: If insertion is impossible here then storage remains unchanged and ArrayStoreException is thrown. enumerator itself is not modified.
 void integrityCheck()
          NOTE: Check for integrity of this object. source storage is not checked.
 int location()
          NOTE: Result is the current location (valid or 0).
 java.lang.Object nextElement()
          NOTE: If no more values (elements) then NoSuchElementException is thrown.
protected  void notifyObservers(int oldLocation)
          NOTE: This method must be called internally after any change of location. oldLocation must be >= 0.
 void notifyObservers(MultiObservable observed, java.lang.Object argument)
          NOTE: It is a dummy method which hides the same method in the superclass.
 java.lang.Object setAtPrevious(java.lang.Object value)
          NOTE: value may be == null.
 void setLocation(int location)
          NOTE: If location !
 Storage source()
          NOTE: Result !
 java.lang.String toString()
          NOTE: source is not represented in the result.
protected  void update(int prevLoc, int location)
          NOTE: Called internally only from source observer agent (source !
 
Methods inherited from class net.sf.ivmaidns.util.ObservedCore
addObserver, hasObservers, removeObserver, trimToSize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

source

protected final Storage source
NOTE: source must be != null. enumerator must be synchronized with source.


location

protected int location
NOTE: If location != 0 then location must be valid. If value at this location is removed in source then location is automatically set to the next location in source. If this location is changed then the observers are notified with the argument of its previous value wrapped by Integer.

Constructor Detail

StorageEnumerator

public StorageEnumerator(Storage source)
                  throws java.lang.NullPointerException
NOTE: source must be != null. location is initialized with source childLocation(0, true). Must be synchronized outside with source. When this enumerator is not needed any more, setLocation(0) should be called to stop observing of source.

Throws:
java.lang.NullPointerException
Method Detail

source

public final Storage source()
NOTE: Result != null.


notifyObservers

protected final void notifyObservers(int oldLocation)
NOTE: This method must be called internally after any change of location. oldLocation must be >= 0.


notifyObservers

public final void notifyObservers(MultiObservable observed,
                                  java.lang.Object argument)
NOTE: It is a dummy method which hides the same method in the superclass.

Overrides:
notifyObservers in class ObservedCore
Parameters:
observed - the observed object (may be null, but normally this).
argument - the argument (may be null), describing the occurred event.
See Also:
ObservedCore.addObserver(net.sf.ivmaidns.util.Notifiable)

update

protected void update(int prevLoc,
                      int location)
NOTE: Called internally only from source observer agent (source != null). If value at enumerator location is removed in source then this location is set to the next location in source (and the observers are notified with the argument of wrapped old location). Must be synchronized outside with source.


hasMoreElements

public final boolean hasMoreElements()
Specified by:
hasMoreElements in interface java.util.Enumeration

nextElement

public java.lang.Object nextElement()
                             throws java.util.NoSuchElementException
NOTE: If no more values (elements) then NoSuchElementException is thrown. Else the result (not null) is the current value and location is set to next (the observers are notified with the argument of wrapped old location). Must be synchronized outside with source.

Specified by:
nextElement in interface java.util.Enumeration
Throws:
java.util.NoSuchElementException

setLocation

public void setLocation(int location)
                 throws java.lang.IllegalArgumentException
NOTE: If location != 0 and location is not valid then IllegalArgumentException is thrown. Else location is changed (and the observers are notified with the argument of wrapped old location). Must be synchronized outside with source.

Throws:
java.lang.IllegalArgumentException

location

public final int location()
NOTE: Result is the current location (valid or 0).


get

public final java.lang.Object get()
NOTE: Result is value at the current location. Result != null if and only if location != 0.


insertAtPrevious

public void insertAtPrevious(boolean isChild,
                             java.lang.Object value)
                      throws java.lang.ArrayStoreException
NOTE: If insertion is impossible here then storage remains unchanged and ArrayStoreException is thrown. enumerator itself is not modified. Alters storage state. Must be synchronized outside with source.

Throws:
java.lang.ArrayStoreException

setAtPrevious

public java.lang.Object setAtPrevious(java.lang.Object value)
                               throws java.lang.ArrayStoreException
NOTE: value may be == null. Result is old value (not null). If operation is impossible here then storage remains unchanged and ArrayStoreException is thrown. enumerator itself is not modified. Alters storage state. Must be synchronized outside with source.

Throws:
java.lang.ArrayStoreException

clone

public java.lang.Object clone()
NOTE: Must be synchronized outside with source.

Specified by:
clone in interface ReallyCloneable
Overrides:
clone in class ObservedCore
Returns:
a copy (may be null) of this instance.

hashCode

public int hashCode()
NOTE: source is not hashed.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
NOTE: Must be synchronized outside with source.

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
NOTE: source is not represented in the result.

Overrides:
toString in class java.lang.Object

integrityCheck

public void integrityCheck()
NOTE: Check for integrity of this object. source storage is not checked. Must be synchronized outside with source. For debug purpose only.

Specified by:
integrityCheck in interface Verifiable
Overrides:
integrityCheck in class ObservedCore