net.sf.ivmaidns.storage
Class ListStorage

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

public class ListStorage
extends ObjectStorage

Class for list storage.

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

Field Summary
protected  int[] links
          NOTE: links must be !
 
Fields inherited from class net.sf.ivmaidns.storage.ObjectStorage
elements
 
Constructor Summary
ListStorage()
           
 
Method Summary
 int childLocation(int parentLocation, boolean forward)
          NOTE: Must be synchronized outside.
 java.lang.Object clone()
          NOTE: Must be synchronized outside.
 int emptyLocation()
          NOTE: Result is an empty location (result > 0).
 int insertAt(int prevLoc, int emptyLocation, java.lang.Object value)
          NOTE: prevLoc must be >= 0 (according to the semantics of list), otherwise ArrayStoreException is thrown.
 void integrityCheck()
          NOTE: Shallow check for integrity of this object.
protected  void minimizeCapacity()
          NOTE: Must be synchronized outside.
 java.lang.Object setAt(int location, java.lang.Object value)
          NOTE: If value is added then it is placed to the end of list.
 int siblingLocation(int location, boolean forward)
          NOTE: Must be synchronized outside.
 
Methods inherited from class net.sf.ivmaidns.storage.ObjectStorage
findLessGreater, getAt, isValidAt, locationOf, parentLocation
 
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

links

protected transient int[] links
NOTE: links must be != null, links length == 2 + elements length * 2, links[0] = nextLocation(0, true), links[1] = emptyLocation() - 1, links[loc * 2] = elements[loc - 1] == null ? -nextEmptyLocation(loc) : nextLocation(loc != links[links[0] * 2 + 1] ? loc : 0, true), links[loc * 2 + 1] = elements[loc - 1] == null ? -prevEmptyLocation(loc) : nextLocation(loc != links[loc] ? loc : 0, false). The order of empty locations is not serialized.

Constructor Detail

ListStorage

public ListStorage()
Method Detail

minimizeCapacity

protected void minimizeCapacity()
NOTE: Must be synchronized outside.

Overrides:
minimizeCapacity in class ObjectStorage

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.

Overrides:
emptyLocation in class ObjectStorage

insertAt

public int insertAt(int prevLoc,
                    int emptyLocation,
                    java.lang.Object value)
             throws java.lang.IllegalArgumentException,
                    java.lang.ArrayStoreException
NOTE: prevLoc must be >= 0 (according to the semantics of list), otherwise ArrayStoreException is thrown. The effectiveness is constant. Observers notification is performed. Must be synchronized outside.

Overrides:
insertAt in class ObjectStorage
Throws:
java.lang.IllegalArgumentException
java.lang.ArrayStoreException

setAt

public java.lang.Object setAt(int location,
                              java.lang.Object value)
                       throws java.lang.IllegalArgumentException
NOTE: If value is added then it is placed to the end of list. The effectiveness is constant. Observers notification is performed. Must be synchronized outside.

Overrides:
setAt in class ObjectStorage
Throws:
java.lang.IllegalArgumentException

childLocation

public int childLocation(int parentLocation,
                         boolean forward)
                  throws java.lang.IllegalArgumentException
NOTE: Must be synchronized outside.

Overrides:
childLocation in class ObjectStorage
Throws:
java.lang.IllegalArgumentException

siblingLocation

public int siblingLocation(int location,
                           boolean forward)
                    throws java.lang.IllegalArgumentException
NOTE: Must be synchronized outside.

Overrides:
siblingLocation in class ObjectStorage
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 ObjectStorage
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 ObjectStorage