org.umber.catalan.process.queue
Class NodeSelection

java.lang.Object
  extended byorg.umber.catalan.process.queue.NodeSelection

public class NodeSelection
extends java.lang.Object

Selection criteria for nodes within a IQueue. Might be a range of nodes, or a list of node indices, or even more complex selections that rely on the contents or Java class of each node. Used to select nodes for operations in QueueManager. By default, no nodes are selected. Indexes and ranges are evaluated first, then filters are applied to the remaining nodes.

Author:
jsheets
See Also:
QueueManager

Constructor Summary
NodeSelection()
          Creates a new instance of NodeSelection.
 
Method Summary
 void addClassFilter(java.lang.Class filter)
          Adds a constraint to select nodes of the given class or interface, or any derived classes.
 void addConstraint(java.lang.String constraint)
          Adds the given selection constraint spec.
 void addIndex(int index)
          Adds a constraint to select a single node by its zero-based index.
 void addRange(int startIndex, int endIndex)
          Adds a constraint for a contiguous span of its zero-based indexes to select.
 void addRegexpFilter(java.lang.String regexp)
          Adds a constraint to select nodes that match the given regular expression.
 void clearSelection()
          Removes all current selection constraints.
 void selectAll()
          Adds a constraint to select all nodes.
 void selectEvens()
          Adds a constraint to select all even nodes.
 int[] selectIndexes(java.util.List nodes)
          Runs the selection constraints against the given nodes.
 void selectOdds()
          Adds a constraint to select all odd nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeSelection

public NodeSelection()
Creates a new instance of NodeSelection.

Method Detail

clearSelection

public void clearSelection()
Removes all current selection constraints. No nodes will be selected unless constraints are added. This is the default state.


selectAll

public void selectAll()
Adds a constraint to select all nodes.


selectEvens

public void selectEvens()
Adds a constraint to select all even nodes.


selectOdds

public void selectOdds()
Adds a constraint to select all odd nodes.


addIndex

public void addIndex(int index)
Adds a constraint to select a single node by its zero-based index.

Parameters:
index - index of the node to select

addRange

public void addRange(int startIndex,
                     int endIndex)
Adds a constraint for a contiguous span of its zero-based indexes to select. All indexes between and including the start and end indexes will be selected.

Parameters:
startIndex - index of low node to select
endIndex - index of high node to select

addClassFilter

public void addClassFilter(java.lang.Class filter)
Adds a constraint to select nodes of the given class or interface, or any derived classes. Class filters are cumulative, so if more than one is added, the selection will include nodes that match any of the class filters.

Parameters:
filter - Java Class to allow in the selection

addRegexpFilter

public void addRegexpFilter(java.lang.String regexp)
Adds a constraint to select nodes that match the given regular expression. Each node is converted to String form with the toString method, then compared to the regular expression.

Parameters:
regexp - regular expression to allow in the selection

addConstraint

public void addConstraint(java.lang.String constraint)
Adds the given selection constraint spec. Can be a single index (e.g., "3"), a range of indexes (e.g., "2..5"), a comma-separated list of indexes (e.g., "1,3..6,12"), or the keywords "even" or "odd" to select all even or all odd nodes, respectively.

Parameters:
constraint - selection constraint

selectIndexes

public int[] selectIndexes(java.util.List nodes)
Runs the selection constraints against the given nodes. Returns an array of all indexes into the node List that satisfy all the constraints.

Parameters:
nodes - node List to run the constraints against
Returns:
array of node indexes that satisfy the constraints