ikrs.util
Class ListPathAdapter<T>

java.lang.Object
  extended by ikrs.util.ListPathAdapter<T>
All Implemented Interfaces:
Path<T>

public class ListPathAdapter<T>
extends java.lang.Object
implements Path<T>

The ListPathAdapter class is a generalized java.util.List based path implementation. Note that this implementation operates on the passed list in-place! Concurrent modifications to the list may cause unexpected bevahior.


Constructor Summary
ListPathAdapter(java.util.List<T> pathList)
          Create a new ListPathAdaper with the given path list (and frontOffset 0).
ListPathAdapter(java.util.List<T> pathList, int frontOffset)
          Create a new ListPathAdaper with the given path list and frontOffset.
 
Method Summary
 T getFirstElement()
          Get the first element of this path.
 int getLength()
          Get the length of this path.
 Path<T> getTrailingPath()
          Get the trailing path from this path.
static void main(java.lang.String[] argv)
          This is for testing only.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListPathAdapter

public ListPathAdapter(java.util.List<T> pathList)
                throws java.lang.NullPointerException
Create a new ListPathAdaper with the given path list (and frontOffset 0).

Parameters:
pathList - The underlying path list (must not be null).
Throws:
java.lang.NullPointerException - If pathList is null.

ListPathAdapter

public ListPathAdapter(java.util.List<T> pathList,
                       int frontOffset)
                throws java.lang.NullPointerException
Create a new ListPathAdaper with the given path list and frontOffset.

Parameters:
pathList - The underlying path list (must not be null).
frontOffset - The front offset to use. The front offset must be in bounds: 0 <= frontOffset <= pathList.size().
Throws:
java.lang.NullPointerException - If pathList is null.
java.lang.IllegalArgumentException - If frontOffset is out of bounds: frontOffset < 0 or frontOffset > pathList.size().
Method Detail

getLength

public int getLength()
Get the length of this path. The length of a path is the exact number of items. An empty path has the size 0.

Specified by:
getLength in interface Path<T>
Returns:
The length of this path which is the number of path elements.

getFirstElement

public T getFirstElement()
Get the first element of this path. If the path is empty the method must return null.

Specified by:
getFirstElement in interface Path<T>
Returns:
The first path element or null if the path is empty.

getTrailingPath

public Path<T> getTrailingPath()
Get the trailing path from this path. The trailing path is this path without the first element. Retrieving the trailing path is equivalent to going down one level inside the tree structure. If this path is empty the returned trailing path is null.

Specified by:
getTrailingPath in interface Path<T>
Returns:
The trailing path or null if this path is empty.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] argv)
This is for testing only.