net.sf.ivmaidns.storage
Class IntStorage

java.lang.Object
  extended by net.sf.ivmaidns.util.ObservedCore
      extended by net.sf.ivmaidns.storage.Storage
          extended by net.sf.ivmaidns.storage.IntStorage
All Implemented Interfaces:
java.lang.Cloneable, MultiObservable, ReallyCloneable, Sortable, TrimToSizeable, Verifiable

public abstract class IntStorage
extends Storage

Abstract class for storage of integers (optimized).

Since:
2.0
Version:
2.0
Author:
Ivan Maidanski

Field Summary
protected  int[] links
          NOTE: links must be !
 
Constructor Summary
IntStorage(int initialLength)
           
 
Method Summary
 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 is not instanceof Integer then 0 is returned.
abstract  int findLessGreaterInt(int value, boolean greater, int prevLocation, boolean forward)
          NOTE: If prevLocation !
 java.lang.Object getAt(int location)
          NOTE: Result !
abstract  int getIntAt(int location)
          NOTE: If location is "empty" then 0 is returned.
 int insertAt(int prevLoc, int emptyLocation, java.lang.Object value)
          NOTE: value must be of Integer and insertion after prevLoc must be possible in this storage (according to the semantics), otherwise ArrayStoreException is thrown.
abstract  int insertIntAt(int prevLoc, int emptyLocation, int value)
          NOTE: If prevLoc !
 void integrityCheck()
          NOTE: Shallow check for integrity of this object.
 int locationOf(java.lang.Object value, int prevLocation, boolean forward)
          NOTE: If value is not instanceof Integer then 0 is returned.
abstract  int locationOfInt(int value, int prevLocation, boolean forward)
          NOTE: If prevLocation !
abstract  int removeIntAt(int location)
          NOTE: If 0 >= location then IllegalArgumentException is thrown.
 java.lang.Object setAt(int location, java.lang.Object value)
          NOTE: If 0 >= location then IllegalArgumentException is thrown.
abstract  int setIntAt(int location, int value)
          NOTE: If 0 >= location then IllegalArgumentException is thrown.
 
Methods inherited from class net.sf.ivmaidns.storage.Storage
add, addAll, addAll, childLocation, clear, contains, containsAll, containsAll, containsCount, equals, greaterThan, hasChildren, hashCode, insertAtAll, insertAtAll, isValidAt, minimizeCapacity, nextLocation, notifyObservers, notifyObservers, parentLocation, remove, removeAll, removeAll, removeAt, siblingLocation, 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

links

protected transient int[] links
NOTE: links must be != null (length > 1), links[1] = emptyLocation() - 1.

Constructor Detail

IntStorage

public IntStorage(int initialLength)
Method Detail

emptyLocation

public final 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 final int insertAt(int prevLoc,
                          int emptyLocation,
                          java.lang.Object value)
                   throws java.lang.IllegalArgumentException,
                          java.lang.ArrayStoreException
NOTE: value must be of Integer and insertion after prevLoc must be possible in this storage (according to the semantics), otherwise ArrayStoreException is thrown. Enough capacity ensured before any changes. Result is the location of the inserted value. Observers notification is performed. Must be synchronized outside.

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

insertIntAt

public abstract int insertIntAt(int prevLoc,
                                int emptyLocation,
                                int value)
                         throws java.lang.IllegalArgumentException,
                                java.lang.ArrayStoreException
NOTE: If prevLoc != 0 and (prevLoc > 0 ? prevLoc : -prevLoc) is an "empty" (including negative) location then IllegalArgumentException is thrown. If 0 > emptyLocation or emptyLocation is not an "empty" location then IllegalArgumentException is thrown. emptyLocation is the location of the inserted value unless emptyLocation == 0 (means any empty location). If insertion is impossible then ArrayStoreException is thrown. Enough capacity is ensured before any changes. New value is inserted as a first child node of -prevLoc (if 0 >= prevLoc) or as a next sibling node of prevLoc (if prevLoc > 0). Result is the location of the inserted value. Alters storage state. The effectiveness is constant (typically). Observers notification is performed. Must be synchronized outside.

Throws:
java.lang.IllegalArgumentException
java.lang.ArrayStoreException

setAt

public final java.lang.Object setAt(int location,
                                    java.lang.Object value)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.ArrayStoreException
NOTE: If 0 >= location then IllegalArgumentException is thrown. value must be either null (always accepted) or of Integer (otherwise ArrayStoreException is thrown), result (oldValue) is either null or of Integer. If operation is impossible (according to the storage semantics) then ArrayStoreException is thrown. Enough capacity ensured before any changes. Alters storage state. Observers notification is performed. Must be synchronized outside.

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

setIntAt

public abstract int setIntAt(int location,
                             int value)
                      throws java.lang.IllegalArgumentException,
                             java.lang.ArrayStoreException
NOTE: If 0 >= location then IllegalArgumentException is thrown. If operation is impossible (according to the storage semantics) then ArrayStoreException is thrown. Enough capacity ensured before any changes. Alters storage state. Result is the previous value at location (or 0 if location was "empty"). The effectiveness is constant (typically) or logarithmic. Observers notification is performed. Must be synchronized outside.

Throws:
java.lang.IllegalArgumentException
java.lang.ArrayStoreException

removeIntAt

public abstract int removeIntAt(int location)
                         throws java.lang.IllegalArgumentException
NOTE: If 0 >= location then IllegalArgumentException is thrown. If location is "empty" then nothing is performed and 0 is returned. Alters storage state. Result is the removed value at location. Observers notification is performed. Must be synchronized outside.

Throws:
java.lang.IllegalArgumentException

getAt

public final java.lang.Object getAt(int location)
NOTE: Result != null if and only if location is not "empty". If location is not "empty" then it is "valid". Storage state is not altered. Requires no synchronization.

Specified by:
getAt in class Storage

getIntAt

public abstract int getIntAt(int location)
NOTE: If location is "empty" then 0 is returned. Storage state is not altered. The effectiveness is constant. Requires no synchronization.


locationOf

public final int locationOf(java.lang.Object value,
                            int prevLocation,
                            boolean forward)
                     throws java.lang.IllegalArgumentException
NOTE: If value is not instanceof Integer then 0 is returned. Must be synchronized outside.

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

locationOfInt

public abstract int locationOfInt(int value,
                                  int prevLocation,
                                  boolean forward)
                           throws java.lang.IllegalArgumentException
NOTE: If prevLocation != 0 and prevLocation is an "empty" location then IllegalArgumentException is thrown. Search is started after/before prevLocation. Result is either 0 (no more values) or a (not "empty") location of the first found element, which is equal to value. If (prevLocation == 0 or prevLocation is "valid") and result != 0 then result is a "valid" location. Storage state is not altered. The effectiveness is linear, logarithmic (typically) or constant. Must be synchronized outside.

Throws:
java.lang.IllegalArgumentException

findLessGreater

public final int findLessGreater(java.lang.Object value,
                                 boolean greater,
                                 int prevLocation,
                                 boolean forward)
                          throws java.lang.IllegalArgumentException
NOTE: If value is not instanceof Integer then 0 is returned. Must be synchronized outside.

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

findLessGreaterInt

public abstract int findLessGreaterInt(int value,
                                       boolean greater,
                                       int prevLocation,
                                       boolean forward)
                                throws java.lang.IllegalArgumentException
NOTE: If prevLocation != 0 and prevLocation is an "empty" location then IllegalArgumentException is thrown. Else search is started after/before prevLocation. Result is either 0 (no more values) or a (not "empty") location of the first/next found element, which is (greater ? 'greater' : 'less') than value. Storage state is not altered. The effectiveness is linear, logarithmic (typically) or constant. Must be synchronized outside.

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