net.sf.ivmaidns.storage
Class ObjectStorage

java.lang.Object
  extended by net.sf.ivmaidns.util.ObservedCore
      extended by net.sf.ivmaidns.storage.Storage
          extended by net.sf.ivmaidns.storage.ObjectStorage
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, MultiObservable, ReallyCloneable, Sortable, TrimToSizeable, Verifiable
Direct Known Subclasses:
HashedStorage, ListStorage, SortedStorage, TreeStorage

public class ObjectStorage
extends Storage
implements java.io.Serializable

Class for simple array-like storage.

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

Field Summary
protected  java.lang.Object[] elements
          NOTE: elements must be !
 
Constructor Summary
ObjectStorage()
           
 
Method Summary
 int childLocation(int parentLocation, boolean forward)
          NOTE: If parentLocation !
 java.lang.Object clone()
          NOTE: Must be synchronized outside.
 int emptyLocation()
          NOTE: Result is an empty location (result > 0).
 int findLessGreater(java.lang.Object value, boolean greater, int prevLocation, boolean forward)
          NOTE: If value == null then 0 is returned.
 java.lang.Object getAt(int location)
          NOTE: All non-empty locations are valid.
 int insertAt(int prevLoc, int emptyLocation, java.lang.Object value)
          NOTE: prevLoc must be >= 0 and insertion after prevLoc must be possible in this storage (according to the semantics of array), otherwise ArrayStoreException is thrown.
 void integrityCheck()
          NOTE: Shallow check for integrity of this object.
 boolean isValidAt(int location)
          NOTE: Result is true if and only if location is "valid" (only not "empty" locations may be "valid").
 int locationOf(java.lang.Object value, int prevLocation, boolean forward)
          NOTE: If value == null then 0 is returned. value is tested for equality against elements.
protected  void minimizeCapacity()
          NOTE: The effectiveness is linear.
 int parentLocation(int location)
          NOTE: If location is "empty" then IllegalArgumentException is thrown.
 java.lang.Object setAt(int location, java.lang.Object value)
          NOTE: The effectiveness is constant.
 int siblingLocation(int location, boolean forward)
          NOTE: If location is "empty" then IllegalArgumentException is thrown.
 
Methods inherited from class net.sf.ivmaidns.storage.Storage
add, addAll, addAll, clear, contains, containsAll, containsAll, containsCount, equals, greaterThan, hasChildren, hashCode, insertAtAll, insertAtAll, nextLocation, notifyObservers, notifyObservers, remove, removeAll, removeAll, removeAt, toArray, toInlineString, toOutlineString, toString, trimToSize
 
Methods inherited from class net.sf.ivmaidns.util.ObservedCore
addObserver, hasObservers, removeObserver
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

elements

protected transient java.lang.Object[] elements
NOTE: elements must be != null. This field is cloned (shallow) and manually serialized (by elements). elements length is not serialized. Initially, elements length == 0.

Constructor Detail

ObjectStorage

public ObjectStorage()
Method Detail

minimizeCapacity

protected void minimizeCapacity()
NOTE: The effectiveness is linear. Locations are not re-ordered. If OutOfMemoryError is thrown then storage remains unchanged. Must be synchronized outside. Should be overridden in subclasses.

Specified by:
minimizeCapacity in class Storage

emptyLocation

public int emptyLocation()
Description copied from class: Storage
NOTE: Result is an empty location (result > 0). Storage state is not altered. The effectiveness is constant (typically). The order of empty locations is undefined. Requires no synchronization.

Specified by:
emptyLocation in class Storage

insertAt

public int insertAt(int prevLoc,
                    int emptyLocation,
                    java.lang.Object value)
             throws java.lang.IllegalArgumentException,
                    java.lang.ArrayStoreException
NOTE: prevLoc must be >= 0 and insertion after prevLoc must be possible in this storage (according to the semantics of array), otherwise ArrayStoreException is thrown. Insertion (storage state altering) here is entirely performed through setAt operation. The effectiveness is nearly constant. Observers notification is performed. Must be synchronized outside.

Specified by:
insertAt in class Storage
Throws:
java.lang.IllegalArgumentException
java.lang.ArrayStoreException

setAt

public java.lang.Object setAt(int location,
                              java.lang.Object value)
                       throws java.lang.IllegalArgumentException
NOTE: The effectiveness is constant. Observers notification is performed. Must be synchronized outside.

Specified by:
setAt in class Storage
Throws:
java.lang.IllegalArgumentException

getAt

public final java.lang.Object getAt(int location)
NOTE: All non-empty locations are valid.

Specified by:
getAt in class Storage

isValidAt

public final boolean isValidAt(int location)
Description copied from class: Storage
NOTE: Result is true if and only if location is "valid" (only not "empty" locations may be "valid"). Storage state is not altered. The effectiveness is constant. Must be synchronized outside.

Specified by:
isValidAt in class Storage

childLocation

public int childLocation(int parentLocation,
                         boolean forward)
                  throws java.lang.IllegalArgumentException
Description copied from class: Storage
NOTE: If parentLocation != 0 and parentLocation is "empty" then IllegalArgumentException is thrown. Result is either 0 (not found) or a found (not "empty") location. If (parentLocation == 0 or is "valid") and result != 0 then result is a "valid" location. Storage state is not altered. The effectiveness is constant. Must be synchronized outside.

Specified by:
childLocation in class Storage
Throws:
java.lang.IllegalArgumentException

siblingLocation

public int siblingLocation(int location,
                           boolean forward)
                    throws java.lang.IllegalArgumentException
Description copied from class: Storage
NOTE: If location is "empty" then IllegalArgumentException is thrown. Result is either 0 (not found) or a found (not "empty") location. If location is "valid" and result != 0 then result is a "valid" location. Storage state is not altered. The effectiveness is constant (typically). Must be synchronized outside.

Specified by:
siblingLocation in class Storage
Throws:
java.lang.IllegalArgumentException

parentLocation

public int parentLocation(int location)
                   throws java.lang.IllegalArgumentException
Description copied from class: Storage
NOTE: If location is "empty" then IllegalArgumentException is thrown. Result is either 0 (not found) or a found (not "empty") location. If location is "valid" and result != 0 then result is a "valid" location. Storage state is not altered. The effectiveness is constant. Must be synchronized outside.

Specified by:
parentLocation in class Storage
Throws:
java.lang.IllegalArgumentException

locationOf

public int locationOf(java.lang.Object value,
                      int prevLocation,
                      boolean forward)
               throws java.lang.IllegalArgumentException
NOTE: If value == null then 0 is returned. value is tested for equality against elements. The effectiveness is linear. Must be synchronized outside.

Specified by:
locationOf in class Storage
Throws:
java.lang.IllegalArgumentException

findLessGreater

public int findLessGreater(java.lang.Object value,
                           boolean greater,
                           int prevLocation,
                           boolean forward)
                    throws java.lang.IllegalArgumentException
NOTE: If value == null then 0 is returned. If greater then elements are compared against value else value is compared against elements. Here, the comparison is performed through GComparator INSTANCE. The effectiveness is linear. Must be synchronized outside.

Specified by:
findLessGreater in class Storage
Throws:
java.lang.IllegalArgumentException

clone

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

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

integrityCheck

public void integrityCheck()
NOTE: Shallow check for integrity of this object. Must be synchronized outside. For debug purpose only.

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