|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.model.project.scan.ScanLoopElement edu.nrao.sss.model.project.scan.ScanLoop
public class ScanLoop
A loop of scans and scan loops.
This class is used primarily by the
SchedulingBlock
.
It allows an observer to create a scan sequence that allows
multiple nesting of repeated loops of scans.
This loop consists of an iteration count and zero or more
ScanLoopElement
s. Each element is executed once
per iteration in the order in which they appear in this
loop's list of elements. Note that some of the elements
may themselves be loops, allowing the construction of
arbritrarily deep nesting of loops.
Version Info:
$Revision: 2277 $ |
$Date: 2009-04-29 11:19:38 -0600 (Wed, 29 Apr 2009) $ |
$Author: dharland $ |
Field Summary |
---|
Fields inherited from interface edu.nrao.sss.util.Identifiable |
---|
UNIDENTIFIED |
Fields inherited from interface edu.nrao.sss.model.UserAccountable |
---|
NULL_USER_ID |
Constructor Summary | |
---|---|
ScanLoop()
Creates a new loop with no elements and with an iteration count of one. |
Method Summary | |
---|---|
void |
add(int index,
Scan scan)
Adds the given scan to this loop at the given position. |
void |
add(Scan scan)
Adds the given scan to this loop. |
ScanLoop |
addCopyOf(int index,
ScanLoop loop)
Adds a copy of the given loop to this loop at the given position. |
ScanLoop |
addCopyOf(ScanLoop loop)
Adds a copy of the given loop to this loop. |
void |
clearId()
Resets this loop's id to UNIDENTIFIED and calls all of it's chilren's clearId() methods. |
ScanLoop |
clone()
Returns a scan loop that is a deep copy of this one. |
boolean |
contains(ScanLoopElement element,
EqualityMethod equalityMethod)
Returns true if element is held either directly, or
indirectly, by this loop. |
boolean |
containsDirectly(ScanLoopElement element,
EqualityMethod equalityMethod)
Returns true if element is held directly by this loop. |
boolean |
decrementIndexOf(ScanLoopElement element)
Moves element to an index one lower than its current position in
this loop. |
boolean |
decrementIndexOfElementAt(int index)
Moves the element at index to an index of index -minus-one. |
boolean |
equals(Object o)
Returns true if o is equal to this scan loop. |
static ScanLoop |
fromXml(Reader reader)
Creates a new scan loop based on the XML data read from reader . |
static ScanLoop |
fromXml(String xmlFile)
Creates a new scan loop from the XML data in the given file. |
boolean |
getBracketed()
Returns whether or not this loop is a "bracketed" loop. |
ScanLoopElement |
getElement(int index)
Returns the element at index. |
List<ScanLoopElement> |
getElements()
Returns a list of the elements of this loop. |
int |
getIterationCount()
Returns the number of times that this loop should be executed. |
TimeDuration |
getMaximumDuration()
Returns the maximum amount of time that may be spent in this loop. |
int |
hashCode()
Returns a hash code value for this scan loop element. |
boolean |
incrementIndexOf(ScanLoopElement element)
Moves element to an index one higher than its current position in
this loop. |
boolean |
incrementIndexOfElementAt(int index)
Moves the element at index to an index of index -plus-one. |
ScanLoopElement |
remove(int index)
Removes the element at index. |
void |
remove(ScanLoopElement element,
EqualityMethod equalityMethod)
Removes all occurrences the given element from this loop. |
void |
removeAll()
Removes all elements from this loop. |
ScanLoopElement |
removeElement(int index)
Deprecated. |
void |
removeRecursively(ScanLoopElement element,
EqualityMethod equalityMethod)
Removes element from this loop and all nested loops. |
void |
replaceEqualScansRecursivelyWith(Scan replacmentScan)
Recursively replaces all scans in this loop that are equal to replacmentScan with replacmentScan . |
void |
replaceEqualScansWith(Scan replacmentScan)
Replaces all scans in this loop that are equal to replacmentScan
with replacmentScan . |
void |
reset()
Resets this loop so that it has no elements and an iteration count of one. |
void |
setBracketed(boolean b)
Sets whether or not this loop is a "bracketed" loop. |
void |
setIterationCount(int count)
Sets the number of times that this loop should be executed. |
void |
setMaximumDuration(TimeDuration maxTime)
Sets the maximum amount of time that may be spent in this loop. |
void |
setSchedulingBlock(SchedulingBlock newSchedBlock)
Sets the scheduling block to which this scan loop belongs. |
int |
size()
Returns the number of elements in this loop. |
boolean |
swapElements(int index1,
int index2)
Swaps the elements at the given positions. |
void |
testScansForResourceFromJaxb()
Meant for use by containers of scan loops; most clients should not use this method. |
List<Scan> |
toScanList()
Returns a list of scans that represents the expansion of this loop and all of its contained loops. |
Set<Scan> |
toScanSet()
Returns the set of scans held by this loop and recursively down through all inner loops. |
String |
toSummaryString()
Returns a short textual description of this scan loop element. |
Methods inherited from class edu.nrao.sss.model.project.scan.ScanLoopElement |
---|
appendComments, getComments, getCreatedBy, getCreatedOn, getId, getLastUpdatedBy, getLastUpdatedOn, getName, getProgramBlock, getProject, getSchedulingBlock, hasSchedulingBlock, setComments, setCreatedBy, setCreatedOn, setId, setLastUpdatedBy, setLastUpdatedOn, setName, toString, toXml, writeAsXmlTo |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ScanLoop()
Method Detail |
---|
public void reset()
reset
in class ScanLoopElement
public void setIterationCount(int count)
count
- public int getIterationCount()
public void setBracketed(boolean b)
In other words, if a loop contains Scans A
and B
, with
an interation count of 3, a regular loop will unroll to: A B A B A B
whereas a bracketed loop would unroll to A B A B A B A
.
Default is true.
public boolean getBracketed()
In other words, if a loop contains Scans A
and B
, with
an interation count of 3, a regular loop will unroll to: A B A B A B
whereas a bracketed loop would unroll to A B A B A B A
.
Default is true.
public void setMaximumDuration(TimeDuration maxTime)
maxTime
is null, the maximum duration will be
set to an arbitrarily large number.
maxTime
- the maximum amount of time that may be spent in this loop.public TimeDuration getMaximumDuration()
public int size()
Scan
or a ScanLoop
.
public void setSchedulingBlock(SchedulingBlock newSchedBlock)
This method does not communicate back to
newSchedBlock
about its new loop. This is because the scheduling block does not
hold loops scans directly, other than its main loop.
This means that the model is not enforcing integrity in the
container / contained relationship that exists between
SchedulingBlock
and ScanLoop
.
If this loop is currently the main loop of a scheduling block, this method will not allow a change of scheduling block.
Passing this method a schedulingBlock
of null has the
effect of disconnecting this loop from any scheduling block.
setSchedulingBlock
in class ScanLoopElement
newSchedBlock
- the scheduling block to which this scan belongs.public List<ScanLoopElement> getElements()
The returned list is not held internally by this loop. This means that any changes made to the list after the call will not be reflected in this object. The elements in the list, however, are the actual elements of this loop, so changes made to them will be reflected in this object.
public ScanLoopElement getElement(int index)
index
- see List.get(int)
for a discussion of this
parameter.
public boolean contains(ScanLoopElement element, EqualityMethod equalityMethod)
element
is held either directly, or
indirectly, by this loop.
If this loop has no element equal to element
, but contains a
nested loop that does contain element
, this method will return
true because it does contain element
, albeit indirectly.
Containment is determined by the equalityMethod
provided.
If this parameter is null, EqualityMethod.VALUE
will
be used.
element
- the element to test for containment.equalityMethod
- determines whether containment is based on reference
or value equality. A value of null will be
interpreted as a signal to use value equality.
element
is held directly or indirectly
by this loop.containsDirectly(ScanLoopElement, EqualityMethod)
public boolean containsDirectly(ScanLoopElement element, EqualityMethod equalityMethod)
element
is held directly by this loop.
If this loop has no element equal to element
, but contains a
nested loop that does contain element
, this method still returns
false because it does not directly hold element
.
Containment is determined by the equalityMethod
provided.
If this parameter is null, EqualityMethod.VALUE
will
be used.
element
- the element to test for containment.equalityMethod
- determines whether containment is based on reference
or value equality. A value of null will be
interpreted as a signal to use value equality.
element
is held directly by this loop.contains(ScanLoopElement, EqualityMethod)
public void add(Scan scan)
scan
- the scan to be added to this loop.
IllegalArgumentException
- if scan
is null.public void add(int index, Scan scan)
index
- the position at which to add the new scan.
See the add(int, E)
method of List
for a discussion of the insertion.scan
- the scan to be added to this loop.
IllegalArgumentException
- if scan
is null.public ScanLoop addCopyOf(ScanLoop loop)
loop
- the loop to be added to this loop.
IllegalArgumentException
- if loop
is null or is
this loop.addCopyOf(int, ScanLoop)
public ScanLoop addCopyOf(int index, ScanLoop loop)
The reason for adding a copy, instead of loop
itself, is to
ensure that the model could never be put into a state where loops
swallow their own tails. That is, we seek to prevent a situation where
loop A holds loop B which holds loop A which holds...
loop
- the loop to be added to this loop.index
- the position at which to add the new loop.
See the add(int, E)
method of List
for a discussion of the insertion.
IllegalArgumentException
- if loop
is null or is
this loop.public boolean incrementIndexOf(ScanLoopElement element)
element
to an index one higher than its current position in
this loop. The element will not be moved if it is not in this loop, or if
it is already in the highest position.
If element
is in this loop in multiple positions, the instance
with the lowest index will be moved.
element
- the element to be moved.
public boolean decrementIndexOf(ScanLoopElement element)
element
to an index one lower than its current position in
this loop. The element will not be moved if it is not in this loop, or if
it is already in the lowest position.
If element
is in this loop in multiple positions, the instance
with the highest index will be moved.
element
- the element to be moved.
public boolean incrementIndexOfElementAt(int index)
index
to an index of index
-plus-one.
No move will occur if index
is out of bounds, or if it is already
the highest index of this loop.
index
- the index of the element to be moved.
public boolean decrementIndexOfElementAt(int index)
index
to an index of index
-minus-one.
No move will occur if index
is out of bounds, or if it is already
the lowest index of this loop.
index
- the index of the element to be moved.
public boolean swapElements(int index1, int index2)
If the indices are equal, no action is taken.
If one or both of the indices are not in the range
[0,size()), the underlying List
will throw
an exception.
index1
- the position of the one of the elements.index2
- the position of another of the elements.
public void replaceEqualScansWith(Scan replacmentScan)
replacmentScan
with replacmentScan
. This is when you want the loop to hold
multiple references to the exact same scan.
Note that this method operates only on scans held directly by this loop,
not on those of inner loops contained within this one. To replace all
scans in this loop and all contained loops, use
replaceEqualScansRecursivelyWith(Scan)
.
replacmentScan
- a scan used to replace all scans in this loop that
are equal to it.public void replaceEqualScansRecursivelyWith(Scan replacmentScan)
replacmentScan
with replacmentScan
.
replacmentScan
- a scan used to replace all scans in this loop that
are equal to it.replaceEqualScansWith(Scan)
@Deprecated public ScanLoopElement removeElement(int index)
public ScanLoopElement remove(int index)
index
- see List.remove(int)
for a discussion of this
parameter.
public void removeRecursively(ScanLoopElement element, EqualityMethod equalityMethod)
element
from this loop and all nested loops.
In order for element
to be removed from this loop, it must
be contained by this loop.
Containment is determined by the equalityMethod
provided.
If this parameter is null, EqualityMethod.VALUE
will
be used.
To remove element
from this loop while leaving nested loops
untouched, call remove(ScanLoopElement, EqualityMethod)
.
element
- the element to be removed from this loop and all
nested loops.equalityMethod
- determines whether containment is based on reference
or value equality. A value of null will be
interpreted as a signal to use value equality.public void remove(ScanLoopElement element, EqualityMethod equalityMethod)
In order for element
to be removed from this loop, it must
be contained by this loop.
Containment is determined by the equalityMethod
provided.
If this parameter is null, EqualityMethod.VALUE
will
be used.
element
- the element to be removed from this loop.equalityMethod
- determines whether containment is based on reference
or value equality. A value of null will be
interpreted as a signal to use value equality.public void removeAll()
public List<Scan> toScanList()
toScanSet()
public Set<Scan> toScanSet()
toScanList()
public String toSummaryString()
ScanLoopElement
toSummaryString
in class ScanLoopElement
public static ScanLoop fromXml(String xmlFile) throws JAXBException, XMLStreamException, FileNotFoundException
xmlFile
- the name of an XML file. This method will attempt to locate
the file by using Class.getResource(String)
.
FileNotFoundException
- if the XML file cannot be found.
JAXBException
- if the schema file used (if any) is malformed, if
the XML file cannot be read, or if the XML file is not
schema-valid.
XMLStreamException
- if there is a problem opening the XML file,
if the XML is not well-formed, or for some other
"unexpected processing conditions".public static ScanLoop fromXml(Reader reader) throws JAXBException, XMLStreamException
reader
.
reader
- the source of the XML data.
If this value is null, null is returned.
reader
.
XMLStreamException
- if the XML is not well-formed,
or for some other "unexpected processing conditions".
JAXBException
- if anything else goes wrong during the
transformation.public void testScansForResourceFromJaxb() throws JAXBException
JAXBException
- if the any scan of this loop has
no resource and the useResourceOfPriorScan flag is false.public void clearId()
clearId
in class ScanLoopElement
public ScanLoop clone()
The returned loop is, for the most part, a deep copy of this one. For example, any scans or (inner) scan loops in the returned loop will be copies of their counterparts in this loop. However, there are a few exceptions:
Identifiable.UNIDENTIFIED
.
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class ScanLoopElement
public boolean equals(Object o)
o
is equal to this scan loop.
In order to be equal to this loop, o
must be non-null and
of the same class as this loop. In order for two loops to be
equal, they must contain equal elements in the same order. Their
iteration counts and maximum durations must also be equal.
equals
in class ScanLoopElement
public int hashCode()
ScanLoopElement
hashCode
in class ScanLoopElement
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |