cz.cuni.amis.pogamut.sposh.elements
Class LapPath

Package class diagram package LapPath
java.lang.Object
  extended by cz.cuni.amis.pogamut.sposh.elements.LapPath
All Implemented Interfaces:
Iterable<LapPath.Link>

public final class LapPath
extends Object
implements Iterable<LapPath.Link>

LapPath is used to describe path from the root of PoshPlan to some subnode of the plan. The path consists from several links, each link describes which cild of current node should be used to change into new current node. There are three major features we require: 1. Parse path from string 2. traverse plan according to the path and return the node. 3. serialize path to the string Examples of serialized path: /P:0/DC:0 - default plan, drive collection 0 /P:0/DC:0/S:1 - Drive collection 0, goal sense 1 /P:0/DC:0/DE:4 - fifth drive in the DC /P:0/DC:0/DE:4/S:0 - first trigger sense of fifth drive in the DC /P:0/DC:0/DE:4/A:0/AP:4 - reference to AP node.

Author:
Honza

Nested Class Summary
static class LapPath.Link
          One link of the path, immutable.
 
Field Summary
static LapPath DRIVE_COLLECTION_PATH
          Path to the LapType.DRIVE_COLLECTION.
static LapPath EMPTY
          Empty path with no links.
static LapPath PLAN_PATH
          Path to the root of the plan, equivalent of /P:0
 
Constructor Summary
LapPath()
           
 
Method Summary
 LapPath concat(LapPath.Link appendedLink)
           
 LapPath concat(LapPath appendPath)
          Create new path consisting from this path and @appendPath
 LapPath concat(LapType type, int id)
          Create and return new LapPath by appending new link to all links of current path.
 boolean equals(Object obj)
           
 LapPath.Link getLink(int linkId)
           
static LapPath getLinkPath(PoshElement endElement)
          Construct path from the @endElement to its very first branch node(DC, AD, AP, C) upward in the tree.
 int hashCode()
           
 Iterator<LapPath.Link> iterator()
           
 int length()
           
static LapPath parse(String serializedPath)
          Parse @serializedPath to
 LapPath subpath(int beginIndex, int endIndex)
          Return subpath of this path.
 String toString()
           
<T extends PoshElement>
T
traversePath(PoshPlan plan)
          Methods with name traverseXYZ mean traverse from XYZ below xyzLink means gor from xyz below according to type and id.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final LapPath EMPTY
Empty path with no links.


PLAN_PATH

public static LapPath PLAN_PATH
Path to the root of the plan, equivalent of /P:0


DRIVE_COLLECTION_PATH

public static LapPath DRIVE_COLLECTION_PATH
Path to the LapType.DRIVE_COLLECTION. Equivalent of /P:0/DC:0

Constructor Detail

LapPath

public LapPath()
Method Detail

traversePath

public <T extends PoshElement> T traversePath(PoshPlan plan)
Methods with name traverseXYZ mean traverse from XYZ below xyzLink means gor from xyz below according to type and id.

Parameters:
plan -
Returns:
Found node
Throws:
IllegalStateException - If path does not play nice with tree, e.g. when paths wants sense subnode in AP, but there is none according to syntax
IndexOutOfBoundsException - If some id on the path references to nonexistent node.

getLinkPath

public static LapPath getLinkPath(PoshElement endElement)
Construct path from the @endElement to its very first branch node(DC, AD, AP, C) upward in the tree. E.g. if @endElement is third trigger LapType.SENSE in the second CompetenceElement of fourth Competence, the path will be something like /C:4/CE:2/S:3, since the Competence is a branch node.

Parameters:
endElement - Element whose ancestor we use to create path.
Returns:
Path from closest ancestor branch node of element to @endElement

parse

public static LapPath parse(String serializedPath)
                     throws ParseException
Parse @serializedPath to

Parameters:
serializedPath - LapPath in serialized form, e.g. /P:0/DC:0/DE:1/S:1
Returns:
Path object created according to @serializedPath
Throws:
ParseException

concat

public LapPath concat(LapType type,
                      int id)
Create and return new LapPath by appending new link to all links of current path. This method does not change this path (LapPath is immutable)/


toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

concat

public LapPath concat(LapPath appendPath)
Create new path consisting from this path and @appendPath

Parameters:
appendPath - Path that will be appended to this and returned.

concat

public LapPath concat(LapPath.Link appendedLink)
Returns:
new path from all links of this this path + appendedLink.

subpath

public LapPath subpath(int beginIndex,
                       int endIndex)
Return subpath of this path.

Parameters:
beginIndex - The beginning link index, inclusive.
endIndex - The ending link index, exclusive.
Returns:
subpath.
Throws:
IndexOutOfBoundsException - If beginIndex < 0 or endIndex > length of path or beginIndex > endIndex.

length

public int length()
Returns:
Number of links in the path.

iterator

public Iterator<LapPath.Link> iterator()
Specified by:
iterator in interface Iterable<LapPath.Link>

getLink

public LapPath.Link getLink(int linkId)


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.