Package org.mozilla.zest.core.v1
Class ZestLoop<T>
- java.lang.Object
-
- org.mozilla.zest.core.v1.ZestElement
-
- org.mozilla.zest.core.v1.ZestStatement
-
- org.mozilla.zest.core.v1.ZestLoop<T>
-
- Type Parameters:
T- the generic type
- All Implemented Interfaces:
Enumeration<ZestStatement>,ZestContainer
- Direct Known Subclasses:
ZestLoopClientElements,ZestLoopFile,ZestLoopInteger,ZestLoopRegex,ZestLoopString
public abstract class ZestLoop<T> extends ZestStatement implements ZestContainer, Enumeration<ZestStatement>
The Class ZestLoop.
-
-
Field Summary
-
Fields inherited from class org.mozilla.zest.core.v1.ZestElement
JSON_ELEMENT_TYPE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(int index, ZestStatement stmt)Adds the statement in the specified index in the script.voidaddStatement(ZestStatement stmt)adds a new statement inside the loop.List<ZestStatement>copyStatements()Copy statements.abstract ZestLoop<T>deepCopy()Deep copy.protected voidendLoop(ZestLoopTokenSet<T> set)ends the loop and set the state to the final value.ZestStatementgetChildBefore(ZestStatement child)Gets the child before.List<ZestStatement>getChildren()Returns all of the containers immediate childrenintgetCurrentIndex()returns the current index (related to the current token) of the loopZestLoopState<T>getCurrentState()returns the current state of the loop.intgetCurrentStatementIndex()returns the current statement indexTgetCurrentToken()return the current token considered inside the loop.intgetIndex(ZestStatement child)Gets the index.ZestStatementgetLast()Gets the last.protected ZestRuntimegetRuntime()abstract ZestLoopTokenSet<T>getSet()returns the set of the tokens in this loop.ZestStatementgetStatement(int index)Gets the statement.List<ZestStatement>getStatements()Gets the statements.StringgetVariableName()Returns the variable name.Set<String>getVariableNames()Returns all of the variable names defined by this staement and its children.booleanhasMoreElements()protected abstract voidincrease()increase the loop indexesprotected voidinit(ZestLoopTokenSet<T> set, List<ZestStatement> statements)Inits the Loop.voidinit(ZestRuntime runtime)inits the loop refreshing the current state to the first considered stateabstract booleanisLastState()checks if the loop is on its last statebooleanisPassive()Checks if is passive.booleanisSameSubclass(ZestElement ze)Checks if is same subclass.protected booleanloop(ZestLoopTokenSet<T> set)increase the current state (ignoring all the statements which are still to be computed for this loop: a new one starts).voidmove(int index, ZestStatement stmt)Move.ZestStatementnextElement()voidonControlBreak()act as a BREAKvoidonControlNext()act as a NEXTprotected voidsetCurrentState(ZestLoopState<T> newState)Sets the current state.voidsetPrefix(String oldPrefix, String newPrefix)protected ZestStatementsetPrev(ZestStatement prev)protected voidsetSet(ZestLoopTokenSet<T> newSet)sets the current state to the new one (for subclasses).List<ZestStatement>setStatements(List<ZestStatement> stmts)Sets the statements list.voidsetVariableName(String name)Sets the variable name.abstract voidtoLastState()ends the loop taking its current state to the last state-
Methods inherited from class org.mozilla.zest.core.v1.ZestStatement
getIndex, getNext, getPrevious, init, insertAfter, insertBefore, isEnabled, remove, setEnabled, setNext
-
Methods inherited from class org.mozilla.zest.core.v1.ZestElement
getElementType, setElementType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Enumeration
asIterator
-
-
-
-
Constructor Detail
-
ZestLoop
protected ZestLoop()
Instantiates a new zest loop.
-
ZestLoop
protected ZestLoop(int index)
-
ZestLoop
public ZestLoop(String variableName)
-
-
Method Detail
-
init
protected void init(ZestLoopTokenSet<T> set, List<ZestStatement> statements)
Inits the Loop.- Parameters:
set- the initialization token setstatements- the list of statements inside the loop
-
init
public void init(ZestRuntime runtime)
inits the loop refreshing the current state to the first considered state- Parameters:
runtime- the Zest runtime.
-
setSet
protected void setSet(ZestLoopTokenSet<T> newSet)
sets the current state to the new one (for subclasses).- Parameters:
newSet- the new sets the
-
setStatements
public List<ZestStatement> setStatements(List<ZestStatement> stmts)
Sets the statements list.- Parameters:
stmts- the stmts list- Returns:
- the previous statement list
-
getStatements
public List<ZestStatement> getStatements()
Gets the statements.- Returns:
- the statements list
-
getChildren
public List<ZestStatement> getChildren()
Description copied from interface:ZestContainerReturns all of the containers immediate children- Specified by:
getChildrenin interfaceZestContainer- Returns:
- the children
-
loop
protected boolean loop(ZestLoopTokenSet<T> set)
increase the current state (ignoring all the statements which are still to be computed for this loop: a new one starts).- Parameters:
set- the set of tokens to continue the loop.- Returns:
- the new state (of the following loop)
-
endLoop
protected void endLoop(ZestLoopTokenSet<T> set)
ends the loop and set the state to the final value.- Parameters:
set- the set of tokens to end the loop.
-
addStatement
public void addStatement(ZestStatement stmt)
adds a new statement inside the loop.- Parameters:
stmt- the new statement to add
-
add
public void add(int index, ZestStatement stmt)Adds the statement in the specified index in the script.- Parameters:
index- the index at which the statement will be addedstmt- the statement to add
-
getCurrentState
public ZestLoopState<T> getCurrentState()
returns the current state of the loop.- Returns:
- the current state
-
setCurrentState
protected void setCurrentState(ZestLoopState<T> newState)
Sets the current state.- Parameters:
newState- the new current state
-
getCurrentToken
public T getCurrentToken()
return the current token considered inside the loop.- Returns:
- the current token considered inside the loop
-
getCurrentIndex
public int getCurrentIndex()
returns the current index (related to the current token) of the loop- Returns:
- the current index (related to the current token)
-
getCurrentStatementIndex
public int getCurrentStatementIndex()
returns the current statement index- Returns:
- the index of the statement currently considered
-
getSet
public abstract ZestLoopTokenSet<T> getSet()
returns the set of the tokens in this loop.- Returns:
- the set of the tokens in this loop
-
getLast
public ZestStatement getLast()
Description copied from interface:ZestContainerGets the last.- Specified by:
getLastin interfaceZestContainer- Returns:
- the last
-
getStatement
public ZestStatement getStatement(int index)
Description copied from interface:ZestContainerGets the statement.- Specified by:
getStatementin interfaceZestContainer- Parameters:
index- the index- Returns:
- the statement
-
getIndex
public int getIndex(ZestStatement child)
Description copied from interface:ZestContainerGets the index.- Specified by:
getIndexin interfaceZestContainer- Parameters:
child- the child- Returns:
- the index
-
move
public void move(int index, ZestStatement stmt)Description copied from interface:ZestContainerMove.- Specified by:
movein interfaceZestContainer- Parameters:
index- the indexstmt- the stmt
-
isSameSubclass
public boolean isSameSubclass(ZestElement ze)
Description copied from class:ZestElementChecks if is same subclass.- Overrides:
isSameSubclassin classZestStatement- Parameters:
ze- the ze- Returns:
- true, if is same subclass
-
getChildBefore
public ZestStatement getChildBefore(ZestStatement child)
Description copied from interface:ZestContainerGets the child before.- Specified by:
getChildBeforein interfaceZestContainer- Parameters:
child- the child- Returns:
- the child before
-
getVariableNames
public Set<String> getVariableNames()
Description copied from interface:ZestContainerReturns all of the variable names defined by this staement and its children.- Specified by:
getVariableNamesin interfaceZestContainer- Returns:
- the tokens
-
setPrefix
public void setPrefix(String oldPrefix, String newPrefix) throws MalformedURLException
- Throws:
MalformedURLException
-
deepCopy
public abstract ZestLoop<T> deepCopy()
Description copied from class:ZestElementDeep copy.- Specified by:
deepCopyin classZestStatement- Returns:
- the zest element
-
hasMoreElements
public boolean hasMoreElements()
- Specified by:
hasMoreElementsin interfaceEnumeration<T>
-
isLastState
public abstract boolean isLastState()
checks if the loop is on its last state- Returns:
- true if the loop is over
-
increase
protected abstract void increase()
increase the loop indexes
-
toLastState
public abstract void toLastState()
ends the loop taking its current state to the last state
-
nextElement
public ZestStatement nextElement()
- Specified by:
nextElementin interfaceEnumeration<T>
-
onControlBreak
public void onControlBreak()
act as a BREAK
-
onControlNext
public void onControlNext()
act as a NEXT
-
copyStatements
public List<ZestStatement> copyStatements()
Copy statements.- Returns:
- the list of copied statements
-
getVariableName
public String getVariableName()
Returns the variable name.- Returns:
- the variable name
-
setVariableName
public void setVariableName(String name)
Sets the variable name.- Parameters:
name- the new variable name
-
isPassive
public boolean isPassive()
Description copied from class:ZestStatementChecks if is passive.- Specified by:
isPassivein classZestStatement- Returns:
- true, if is passive
-
setPrev
protected ZestStatement setPrev(ZestStatement prev)
- Overrides:
setPrevin classZestStatement
-
getRuntime
protected ZestRuntime getRuntime()
-
-