nz.ac.waikato.jdsl.core.ref
Class AbstractPositionalContainer

java.lang.Object
  extended by nz.ac.waikato.jdsl.core.ref.AbstractPositionalContainer
All Implemented Interfaces:
Container, InspectableContainer, InspectablePositionalContainer, PositionalContainer
Direct Known Subclasses:
AbstractGraph, ArraySequence, NodeBinaryTree, NodeSequence, NodeTree

public abstract class AbstractPositionalContainer
extends java.lang.Object
implements PositionalContainer

An abstract positional container that others may extend if they do not wish to deal with some of the more mundane aspects of positional containers and/or if they wish to avoid implementing themselves some of the methods of container that aren't terribly pertinent to a PositionalContainer. Feel free to override any of these methods in subclasses, but be certain that they work according to the API in nz.ac.waikato.jdsl.core.api. Also handles isEmpty() from InspectableContainer.

Version:
JDSL 2.1.1
Author:
Andrew Schwerin (schwerin), Benoit Hudson (bh), Ryan Shaun Baker (rsb)
See Also:
PositionalContainer

Constructor Summary
AbstractPositionalContainer()
           
 
Method Summary
 boolean isEmpty()
          Checks if this container is empty.
 void swapElements(Position a, Position b)
          Works on top of PositionalContainer method replaceElement(Position, Object) and InspectableContainer method contains().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectablePositionalContainer
positions
 
Methods inherited from interface nz.ac.waikato.jdsl.core.api.Container
newContainer, replaceElement
 
Methods inherited from interface nz.ac.waikato.jdsl.core.api.InspectableContainer
contains, elements, size
 

Constructor Detail

AbstractPositionalContainer

public AbstractPositionalContainer()
Method Detail

swapElements

public void swapElements(Position a,
                         Position b)
                  throws InvalidAccessorException
Works on top of PositionalContainer method replaceElement(Position, Object) and InspectableContainer method contains().

Specified by:
swapElements in interface PositionalContainer
Parameters:
a - First Position to swap
b - Second Position to swap
Throws:
InvalidAccessorException - if either of a and b is null or does not belong to this positional container

isEmpty

public boolean isEmpty()
Checks if this container is empty. Has the same time complexity as size(). If size() is O(n) and you can write isEmpty() in O(1) time, then override this method.

Specified by:
isEmpty in interface InspectableContainer
Returns:
true if and only if the container is empty (holds no elements)
See Also:
InspectableBinaryTree


Copyright © 2009 ModelJUnit Project. All Rights Reserved.