public class PropagationStateConverter extends Object implements IThreadAware
PropagationStateElement
and AuxiliaryStateElement
converter types to convert to their corresponding output types. For instance, a
PropagationVector
defines its values using Cartesian
types. So
if the user enters an element identification corresponding to a PropagationVector
,
it can convert the raw data into the Motion<Cartesian>
data
containing the vector value and its derivatives.Modifier and Type | Method and Description |
---|---|
<T> boolean |
adjustState(String elementID,
double[] stateToAdjust,
Motion1<T> newStateValues)
Adjust a subset of the overall state to new values based on the requested element.
|
boolean |
adjustStateFromElement(String elementID,
double[] overallRawState,
Motion1<double[]> stateElementValues)
Adjust the subset of the overall raw state corresponding to this element to new values.
|
Object |
clone(CopyContext context)
Clones this object using the specified context.
|
<T> Motion1<T> |
convertState(String elementID,
double[] state)
Convert a given state and auxiliary values to useful data based on the given element.
|
<T> DateMotionCollection1<T> |
getDateMotionCollection(String elementID,
List<JulianDate> times,
List<double[]> state)
Convert a set of time indexed data to a
DateMotionCollection1 based on a given element. |
Motion1<double[]> |
getElementFromState(String elementID,
double[] overallState)
Produces this state element's values and their derivatives from the overall raw state.
|
List<String> |
getElementIDs()
Gets a collection of the propagated and auxiliary element identification strings
enumerating the elements within the state that this converter represents.
|
boolean |
getIsThreadSafe()
Gets a value indicating whether the methods on this instance are safe to call from
multiple threads simultaneously.
|
public final Object clone(CopyContext context)
This method should be implemented to call a copy constructor on the class of the
object being cloned. The copy constructor should take the CopyContext
as a parameter
in addition to the existing instance to copy. The copy constructor should first call
CopyContext.addObjectMapping(T, T)
to identify the newly constructed instance
as a copy of the existing instance. It should then copy all fields, using
CopyContext.updateReference(T)
to copy any reference fields.
A typical implementation of ICloneWithContext
:
public static class MyClass implements ICloneWithContext {
public MyClass(MyClass existingInstance, CopyContext context) {
context.addObjectMapping(existingInstance, this);
someReference = context.updateReference(existingInstance.someReference);
}
@Override
public final Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
}
In general, all fields that are reference types should be copied with a call to
CopyContext.updateReference(T)
. There are a couple of exceptions:
If one of these exceptions applies, the CopyContext
should be given an opportunity
to update the reference before the reference is copied explicitly. Use
CopyContext.updateReference(T)
to update the reference. If CopyContext.updateReference(T)
returns
the original object, indicating that the context does not have a replacement registered,
then copy the object manually by invoking a Clone method, a copy constructor, or by manually
constructing a new instance and copying the values.
alwaysCopy = context.updateReference(existingInstance.alwaysCopy);
if (existingInstance.alwaysCopy != null && alwaysCopy == existingInstance.alwaysCopy) {
alwaysCopy = (AlwaysCopy) existingInstance.alwaysCopy.clone(context);
}
If you are implementing an evaluator (a class that implements IEvaluator
), the
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
method shares some responsibilities with the
copy context constructor. Code duplication can be avoided by doing the following:
CopyContext.updateReference(T)
. You should still call CopyContext.updateReference(T)
on any references to
non-evaluators.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as the last line in the constructor and pass it the
same CopyContext
passed to the constructor.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as normal. See the reference documentation for
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
for more information on implementing that method.
public MyClass(MyClass existingInstance, CopyContext context) {
super(existingInstance, context);
someReference = context.updateReference(existingInstance.someReference);
evaluatorReference = existingInstance.evaluatorReference;
updateEvaluatorReferences(context);
}
@Override
public void updateEvaluatorReferences(CopyContext context) {
evaluatorReference = context.updateReference(evaluatorReference);
}
@Override
public Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
private IEvaluator evaluatorReference;
clone
in interface ICloneWithContext
context
- The context to use to perform the copy.public final boolean getIsThreadSafe()
If this property is true
, all methods and properties are guaranteed to be thread safe.
Conceptually, an object that returns true
for this method acts as if there is a lock
protecting each method and property such that only one thread at a time can be inside any method or
property in the class. In reality, such locks are generally not used and are in fact discouraged. However,
the user must not experience any exceptions or inconsistent behavior that would not be experienced if such
locks were used.
If this property is false
, the behavior when using this class from multiple threads
simultaneously is undefined and may include inconsistent results and exceptions. Clients wishing to use
multiple threads should call CopyForAnotherThread.copy(T)
to get a separate instance of the
object for each thread.
getIsThreadSafe
in interface IThreadAware
@Nonnull public final List<String> getElementIDs()
@Nonnull public final <T> Motion1<T> convertState(String elementID, double[] state)
T
- The type corresponding to the output of the requested elementID
.
For instance, if requesting an elementID
corresponding to an instance of a
PropagationVector
the type should be Cartesian
but if the
elementID
corresponds to an instance of a PropagationScalar
the type should be double
.elementID
- The string identifying which propagation state or auxiliary state element to use when converting the raw state.state
- The raw state.@Nonnull public final Motion1<double[]> getElementFromState(String elementID, double[] overallState)
elementID
- The string identifying which propagation state element to use when converting the raw state.
(AuxiliaryStateElementConverter
does not output its element as a Motion
of double arrays, so auxiliary state element IDs are not supported.
Use PropagationStateConverter.convertState(java.lang.String, double[])
instead.)overallState
- The overall raw state from which to produce this element's array.@Nonnull public final <T> DateMotionCollection1<T> getDateMotionCollection(String elementID, @Nonnull List<JulianDate> times, @Nonnull List<double[]> state)
DateMotionCollection1
based on a given element.T
- The type corresponding to the output of the requested elementID
.
For instance, if requesting an elementID
corresponding to an instance of a
PropagationVector
the type should be Cartesian
but if the
elementID
corresponds to an instance of a PropagationScalar
the type should be double
.elementID
- The string identifying which propagation state or auxiliary state element to use when converting the raw state.times
- The times at which the state was recorded.state
- The raw states recorded at each of the times
.DateMotionCollection1
of the type of the requested state element output.public final <T> boolean adjustState(String elementID, double[] stateToAdjust, @Nonnull Motion1<T> newStateValues)
T
- The type corresponding to the TypeOfOutput
(get
) of
the requested element.elementID
- The identifier specifying which element's state values to update.stateToAdjust
- The overall state to adjust. Remember that if modifying the
InitialState
(get
), the array will be a copy and needs to be reinitialized
by passing the adjusted instance of a copy to NumericalPropagator.reset(JulianDate,double[])
.newStateValues
- The new state element values for the requested element.public final boolean adjustStateFromElement(String elementID, double[] overallRawState, @Nonnull Motion1<double[]> stateElementValues)
elementID
- The string identifying which propagation state element to use when converting the raw state.
(AuxiliaryStateElementConverter
does not output its element as a Motion
of double arrays, so auxiliary state element IDs are not supported.)overallRawState
- The overall raw state to adjust.stateElementValues
- The new values and derivatives for the requested element
represented as an array. To obtain an instance of this array, call PropagationStateConverter.getElementFromState(java.lang.String, double[])
.