org.shapelogic.logic
Class BaseTask<T>

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.shapelogic.logic.BaseTask<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<com.google.inject.Module>, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode, org.apache.commons.jexl.JexlContext, Calc0<T>, CalcInvoke<T>, CalcValue<T>, LazyCalc<T>, Task<T>
Direct Known Subclasses:
AndTask, BooleanTask, CalcAndSetTask, ExistTask, RootTask, SimpleTask, XOrTask

public class BaseTask<T>
extends javax.swing.tree.DefaultMutableTreeNode
implements Task<T>

Base class for Task, very fundamental all other tasks are subclassed from this The majority of task functionalety are placed here.

Author:
Sami Badawi I might take the TreeNode part out of this later, then I will need a pointer to the self node.
See Also:
Serialized Form

Field Summary
protected  long _endTime
           
protected  int _failedSubTasksCount
           
protected  com.google.inject.Injector _injector
           
protected  float _interest
           
protected  LogicState _lastSubTaskState
           
protected  org.apache.commons.jexl.context.HashMapContext _localContext
           
protected  com.google.inject.Module _localModule
           
protected  long _pathWork
           
protected  float _score
           
protected  long _selfWork
           
protected  long _selfWorkEstimate
           
protected  long _startTime
           
protected  LogicState _state
           
protected  int _succededSubTasksCount
           
protected  T _value
           
static java.lang.String CONTEXT_CALCULATION_MAP
           
static float DEFAULT_INTEREST
           
static float DEFAULT_SCORE
           
static java.lang.String NAMED_TASKS
           
static long WORK_NOT_KNOWN
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
BaseTask(BaseTask parent)
           
BaseTask(BaseTask parent, boolean createLocalContext)
           
 
Method Summary
 java.lang.Object calcNextSubTask()
          calculate the next sub task If it succeed it will return true and pop the last sub task.
 void doPrintOnFail()
           
 java.lang.String errorOnFail()
           
 java.lang.Object findEnumValue(java.lang.String name)
          If a named value cannot be found for a String key, instead see if the first part of the string is the name of a class set in the context if it is the name of a class that is an emum then try to see if rest is an legal value
 java.lang.Object findNamedValue(java.lang.String name)
           
 java.lang.Object findNamedValueUsingSubTasks(java.lang.String name)
           
 org.apache.commons.jexl.JexlContext getContext()
          Deprecated. 
 ContextCalculation getContextCalculation(java.lang.String name)
           
 java.util.Map<java.lang.String,ContextCalculation> getContextCalculationMap()
           
 com.google.inject.Injector getInjector()
           
 float getInterest()
           
 LogicState getLastSubTaskState()
           
 org.apache.commons.jexl.JexlContext getLocalContext()
           
 com.google.inject.Module getLocalModule()
           
 org.apache.commons.jexl.JexlContext getLowestContext()
           
 java.lang.String getName()
           
 Task getNamedTask(java.lang.String name)
           
 java.lang.Object getNamedValue(java.lang.String name)
           
 Task getParentTask()
           
 long getPathWork()
          measured in milliseconds
 float getScore()
           
 javax.swing.tree.TreeNode getSelfTreeNode()
          Needed if TreeNode gets taken out of this interface
 long getSelfWork()
          measured in milliseconds
 long getSelfWorkEstimate()
           
 LogicState getState()
           
 T getValue()
          Starts a lazy calculation.
 java.util.Map getVars()
          Get map with everything over and including current
 T invoke()
           
 boolean isDirty()
          might change into a realy dirty flag
 boolean isPrintOnFail()
           
 java.util.Iterator<com.google.inject.Module> iterator()
           
 T mainCalc()
           
 boolean match()
          match() should be seen like a unify that can also try to set fields So this can be overridden
 void postCalc()
           
 void preCalc()
           
 void setClassInContext(java.lang.Class klass)
           
 void setClassInContext(java.lang.Class[] classes)
           
 void setClassInContext(java.util.Collection<java.lang.Class> classes)
           
 void setContextCalculation(java.lang.String name, ContextCalculation contextCalculation)
           
 void setInterest(float interest)
           
 void setName(java.lang.String name)
           
 void setNamedTask(java.lang.String name, Task task)
           
 void setNamedValue(java.lang.String name, java.lang.Object value)
           
 void setPrintOnFail(boolean printOnFail)
           
 void setState(LogicState state)
           
 void setup()
          Currently not super well define used for 2 purposes: Reset: called from the outside if you want to reuse it init: Called from the inside when calculation start to have everything setup maybe the semantic could work for both? TODO: This should be separated better.
 void setVars(java.util.Map vars)
           
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.tree.TreeNode
children, getAllowsChildren, getChildAt, getChildCount, getIndex, getParent, isLeaf
 

Field Detail

NAMED_TASKS

public static final java.lang.String NAMED_TASKS
See Also:
Constant Field Values

CONTEXT_CALCULATION_MAP

public static final java.lang.String CONTEXT_CALCULATION_MAP
See Also:
Constant Field Values

WORK_NOT_KNOWN

public static long WORK_NOT_KNOWN

DEFAULT_INTEREST

public static float DEFAULT_INTEREST

DEFAULT_SCORE

public static float DEFAULT_SCORE

_state

protected LogicState _state

_pathWork

protected long _pathWork

_selfWork

protected long _selfWork

_selfWorkEstimate

protected long _selfWorkEstimate

_startTime

protected long _startTime

_endTime

protected long _endTime

_interest

protected float _interest

_score

protected float _score

_localContext

protected org.apache.commons.jexl.context.HashMapContext _localContext

_localModule

protected com.google.inject.Module _localModule

_injector

protected com.google.inject.Injector _injector

_value

protected T _value

_lastSubTaskState

protected LogicState _lastSubTaskState

_succededSubTasksCount

protected int _succededSubTasksCount

_failedSubTasksCount

protected int _failedSubTasksCount
Constructor Detail

BaseTask

public BaseTask(BaseTask parent,
                boolean createLocalContext)

BaseTask

public BaseTask(BaseTask parent)
Method Detail

isDirty

public boolean isDirty()
might change into a realy dirty flag

Specified by:
isDirty in interface LazyCalc<T>

getInterest

public float getInterest()
Specified by:
getInterest in interface Task<T>

getPathWork

public long getPathWork()
Description copied from interface: Task
measured in milliseconds

Specified by:
getPathWork in interface Task<T>

getScore

public float getScore()
Specified by:
getScore in interface Task<T>

getSelfWork

public long getSelfWork()
Description copied from interface: Task
measured in milliseconds

Specified by:
getSelfWork in interface Task<T>

getSelfWorkEstimate

public long getSelfWorkEstimate()
Specified by:
getSelfWorkEstimate in interface Task<T>

getState

public LogicState getState()
Specified by:
getState in interface Task<T>

setInterest

public void setInterest(float interest)
Specified by:
setInterest in interface Task<T>

setState

public void setState(LogicState state)
Specified by:
setState in interface Task<T>

getContext

@Deprecated
public org.apache.commons.jexl.JexlContext getContext()
Deprecated. 

In case I take the context out of the node

Specified by:
getContext in interface Task<T>

getLowestContext

public org.apache.commons.jexl.JexlContext getLowestContext()
Specified by:
getLowestContext in interface Task<T>

getLocalContext

public org.apache.commons.jexl.JexlContext getLocalContext()
Specified by:
getLocalContext in interface Task<T>

getVars

public java.util.Map getVars()
Get map with everything over and including current

Specified by:
getVars in interface org.apache.commons.jexl.JexlContext

setVars

public void setVars(java.util.Map vars)
Specified by:
setVars in interface org.apache.commons.jexl.JexlContext

preCalc

public void preCalc()
Specified by:
preCalc in interface Task<T>

postCalc

public void postCalc()
Specified by:
postCalc in interface Task<T>

invoke

public T invoke()
Specified by:
invoke in interface Calc0<T>

getParentTask

public Task getParentTask()
Specified by:
getParentTask in interface Task<T>

getSelfTreeNode

public javax.swing.tree.TreeNode getSelfTreeNode()
Description copied from interface: Task
Needed if TreeNode gets taken out of this interface

Specified by:
getSelfTreeNode in interface Task<T>

mainCalc

public T mainCalc()
Specified by:
mainCalc in interface Task<T>

match

public boolean match()
              throws java.lang.Exception
match() should be seen like a unify that can also try to set fields So this can be overridden

Specified by:
match in interface Task<T>
Throws:
java.lang.Exception

setup

public void setup()
Description copied from interface: LazyCalc
Currently not super well define used for 2 purposes: Reset: called from the outside if you want to reuse it init: Called from the inside when calculation start to have everything setup maybe the semantic could work for both? TODO: This should be separated better.

Specified by:
setup in interface LazyCalc<T>

getLocalModule

public com.google.inject.Module getLocalModule()
Specified by:
getLocalModule in interface Task<T>

iterator

public java.util.Iterator<com.google.inject.Module> iterator()
Specified by:
iterator in interface java.lang.Iterable<com.google.inject.Module>
Specified by:
iterator in interface Task<T>

getInjector

public com.google.inject.Injector getInjector()
Specified by:
getInjector in interface Task<T>

getContextCalculation

public ContextCalculation getContextCalculation(java.lang.String name)
Specified by:
getContextCalculation in interface Task<T>

setContextCalculation

public void setContextCalculation(java.lang.String name,
                                  ContextCalculation contextCalculation)
Specified by:
setContextCalculation in interface Task<T>

findNamedValue

public java.lang.Object findNamedValue(java.lang.String name)
Specified by:
findNamedValue in interface Task<T>

findEnumValue

public java.lang.Object findEnumValue(java.lang.String name)
If a named value cannot be found for a String key, instead see if the first part of the string is the name of a class set in the context if it is the name of a class that is an emum then try to see if rest is an legal value

Parameters:
name - input that should be an enum value with the class at first e.g. PointType.T_JUNCTION
Returns:
null if not an enum value

findNamedValueUsingSubTasks

public java.lang.Object findNamedValueUsingSubTasks(java.lang.String name)
Specified by:
findNamedValueUsingSubTasks in interface Task<T>

getNamedValue

public java.lang.Object getNamedValue(java.lang.String name)
Specified by:
getNamedValue in interface Task<T>

getContextCalculationMap

public java.util.Map<java.lang.String,ContextCalculation> getContextCalculationMap()
Specified by:
getContextCalculationMap in interface Task<T>

calcNextSubTask

public java.lang.Object calcNextSubTask()
calculate the next sub task If it succeed it will return true and pop the last sub task.

Specified by:
calcNextSubTask in interface Task<T>

getNamedTask

public Task getNamedTask(java.lang.String name)
Specified by:
getNamedTask in interface Task<T>

setNamedTask

public void setNamedTask(java.lang.String name,
                         Task task)
Specified by:
setNamedTask in interface Task<T>

getValue

public T getValue()
Description copied from interface: CalcValue
Starts a lazy calculation. If dirty do calc() else return cached value. This should maybe be moved up in the hierarchy

Specified by:
getValue in interface CalcValue<T>
Specified by:
getValue in interface Task<T>

getName

public java.lang.String getName()
Specified by:
getName in interface Task<T>

setName

public void setName(java.lang.String name)
Specified by:
setName in interface Task<T>

getLastSubTaskState

public LogicState getLastSubTaskState()
Specified by:
getLastSubTaskState in interface Task<T>

setNamedValue

public void setNamedValue(java.lang.String name,
                          java.lang.Object value)
Specified by:
setNamedValue in interface Task<T>

setClassInContext

public void setClassInContext(java.lang.Class klass)
Specified by:
setClassInContext in interface Task<T>

setClassInContext

public void setClassInContext(java.util.Collection<java.lang.Class> classes)
Specified by:
setClassInContext in interface Task<T>

setClassInContext

public void setClassInContext(java.lang.Class[] classes)
Specified by:
setClassInContext in interface Task<T>

errorOnFail

public java.lang.String errorOnFail()
Specified by:
errorOnFail in interface Task<T>

doPrintOnFail

public void doPrintOnFail()
Specified by:
doPrintOnFail in interface Task<T>

isPrintOnFail

public boolean isPrintOnFail()
Specified by:
isPrintOnFail in interface Task<T>

setPrintOnFail

public void setPrintOnFail(boolean printOnFail)
Specified by:
setPrintOnFail in interface Task<T>


Copyright © 2009. All Rights Reserved.