gov.sns.xal.model.elem
Class ElementSeq

java.lang.Object
  |
  +--gov.sns.xal.model.elem.ElementSeq
All Implemented Interfaces:
IComponent, IComposite
Direct Known Subclasses:
IdealMagWedgeDipole, Lattice, LineModel, RfCavity, RingModel, Sector

public abstract class ElementSeq
extends java.lang.Object
implements IComposite

Convenience abstract base class for a composite modeling element. The composite is represented as a sequence of modeling elements, perhaps other composites. Specifically we have an ordered list of child modeling elements. Propagation of probes (objects exposing the IProbe interface) is done by passing it sequentially to each child. Of couse if a child is also a composite the same is done there.


Field Summary
static int s_szDefReserve
          default number of element positions to reserve in list array
 
Constructor Summary
ElementSeq(java.lang.String strType)
          Creates a new instance of ElementSeq without a sequence identifier.
ElementSeq(java.lang.String strType, java.lang.String strId)
          Creates a new instance of ElementSeq
ElementSeq(java.lang.String strType, java.lang.String strId, int szReserve)
          Creates a new instance of ElementSeq and reserves space for a szReserve length sequence.
 
Method Summary
 void addChild(IComponent iComp)
          Add a component object at the tail of the sequence.
 java.util.Iterator childIterator()
          Return an Iterator object that cycles through all the direct children of the sequence.
 void concatenateEquals(ElementSeq seq)
          Concatenate the indicated ElementSeq object to the tail of this sequence.
 IComponent getChild(int indChild)
          Get the child IComponent interface at location specified by index.
 int getChildCount()
          Get the number of direct children in this sequence.
 java.lang.String getComments()
          Get any user comments regarding this sequence.
 java.lang.String getId()
          Get the sequence identifier
 int getLeafCount()
          Get the number of Element derived objects contained in this sequence.
 double getLength()
          Return the length of the sequence.
 java.lang.String getType()
          Get the type identifier for the composite element.
 java.util.Iterator globalIterator()
          Return an Iterator object that iterates over every IComponent object in this composite.
 java.util.Iterator localIterator()
          Return an Iterator object that iterates over the direct descendants only of this composite element, in order.
 void print(java.io.PrintWriter os)
          Dump contents to a text stream.
 void propagate(IProbe probe)
          Propagate probe through sequence
 boolean remove(IComponent iElem)
          Remove an element from the entire tree.
 void setComments(java.lang.String strComment)
          Sets any user comment associated with this sequence.
 void setId(java.lang.String strId)
          Set the string identifier for the element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_szDefReserve

public static final int s_szDefReserve
default number of element positions to reserve in list array

See Also:
Constant Field Values
Constructor Detail

ElementSeq

public ElementSeq(java.lang.String strType)
Creates a new instance of ElementSeq without a sequence identifier.


ElementSeq

public ElementSeq(java.lang.String strType,
                  java.lang.String strId)
Creates a new instance of ElementSeq

Parameters:
strId - identifier of the sequence

ElementSeq

public ElementSeq(java.lang.String strType,
                  java.lang.String strId,
                  int szReserve)
Creates a new instance of ElementSeq and reserves space for a szReserve length sequence.

Parameters:
strId - identifier of the sequence
szReserve - number of Element spaces to reserve
Method Detail

setId

public void setId(java.lang.String strId)
Set the string identifier for the element.

Parameters:
strId - new string identifier for element

setComments

public void setComments(java.lang.String strComment)
Sets any user comment associated with this sequence.

Parameters:
strComment - string containing user comments

getType

public java.lang.String getType()
Get the type identifier for the composite element.

Specified by:
getType in interface IComponent
Returns:
type indentifier for ElementSeq

getId

public java.lang.String getId()
Get the sequence identifier

Specified by:
getId in interface IComponent
Returns:
sequence identifier

getLength

public double getLength()
Return the length of the sequence. The length of the sequence is determined but summing the lengths of all the contained IElement objects.

Specified by:
getLength in interface IComponent
Returns:
total length of the sequence (in meters)

propagate

public void propagate(IProbe probe)
               throws ModelException
Propagate probe through sequence

Specified by:
propagate in interface IComposite
Parameters:
probe - the state of the probe will be advance using the elements dynamics
Throws:
ModelException - an error occurred while advancing the probe state

localIterator

public java.util.Iterator localIterator()
Return an Iterator object that iterates over the direct descendants only of this composite element, in order.

Specified by:
localIterator in interface IComposite
Returns:
interface to iterator object
See Also:
Iterator

globalIterator

public java.util.Iterator globalIterator()
Return an Iterator object that iterates over every IComponent object in this composite. For IComponent which are also composite the parent is returned first, then all its children. This would be the order in which the probe visits each component.

Specified by:
globalIterator in interface IComposite
Returns:
Iterator interface to iterator object
See Also:
Iterator

getChildCount

public int getChildCount()
Get the number of direct children in this sequence. Note that this is not the number of leaves in the sequence.

Specified by:
getChildCount in interface IComposite
Returns:
number of direct descendents

getChild

public IComponent getChild(int indChild)
Get the child IComponent interface at location specified by index.

Specified by:
getChild in interface IComposite
Parameters:
indChild - position index within the sequence list
Returns:
child at position indChild

addChild

public void addChild(IComponent iComp)
Add a component object at the tail of the sequence.

Specified by:
addChild in interface IComposite
Parameters:
iComp - new component object

remove

public boolean remove(IComponent iElem)
Remove an element from the entire tree. The element can be a single leaf node or a composite node.

Specified by:
remove in interface IComposite
Parameters:
iElem - interface to the child to be removed
Returns:
return true if element was found and removed, false otherwise

getComments

public java.lang.String getComments()
Get any user comments regarding this sequence. Returns the null string if none.

Returns:
string containing user comments

getLeafCount

public int getLeafCount()
Get the number of Element derived objects contained in this sequence.

Returns:
number of Element object w/in sequence

childIterator

public java.util.Iterator childIterator()
Return an Iterator object that cycles through all the direct children of the sequence. Note that any child may have children itself.

Returns:
iterator of IElement interfaces

concatenateEquals

public void concatenateEquals(ElementSeq seq)
Concatenate the indicated ElementSeq object to the tail of this sequence.

Parameters:
seq - object to conjoin to this one

print

public void print(java.io.PrintWriter os)
Dump contents to a text stream.

Parameters:
os - output stream