Package org.orekit.utils
Class ImmutableFieldTimeStampedCache<T extends FieldTimeStamped<KK>,KK extends CalculusFieldElement<KK>>
- java.lang.Object
-
- org.orekit.utils.ImmutableFieldTimeStampedCache<T,KK>
-
- Type Parameters:
T
- the type of dataKK
- the type the field element
- All Implemented Interfaces:
FieldTimeStampedCache<T,KK>
public class ImmutableFieldTimeStampedCache<T extends FieldTimeStamped<KK>,KK extends CalculusFieldElement<KK>> extends Object implements FieldTimeStampedCache<T,KK>
A cache ofTimeStamped
data that provides concurrency through immutability. This strategy is suitable when all the cached data is stored in memory. (For example,UTCScale
) This class then provides convenient methods for accessing the data.- Author:
- Evan Ward, Vincent Cucchietti
-
-
Constructor Summary
Constructors Constructor Description ImmutableFieldTimeStampedCache(int neighborsSize, Collection<? extends T> data)
Create a new cache with the given neighbors size and data.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <TS extends FieldTimeStamped<CFE>,CFE extends CalculusFieldElement<CFE>>
ImmutableFieldTimeStampedCache<TS,CFE>emptyCache(Field<CFE> field)
Get an empty immutable cache, cast to the correct type.List<T>
getAll()
Get all the data in this cache.T
getEarliest()
Get the earliest entry in this cache.T
getLatest()
Get the latest entry in this cache.Stream<T>
getNeighbors(FieldAbsoluteDate<KK> central)
Get the entries surrounding a central date.int
getNeighborsSize()
Get the fixed size of the lists returned byFieldTimeStampedCache.getNeighbors(FieldAbsoluteDate)
.String
toString()
-
-
-
Constructor Detail
-
ImmutableFieldTimeStampedCache
public ImmutableFieldTimeStampedCache(int neighborsSize, Collection<? extends T> data)
Create a new cache with the given neighbors size and data.- Parameters:
neighborsSize
- the size of the list returned fromgetNeighbors(FieldAbsoluteDate)
. Must be less than or equal todata.size()
.data
- the backing data for this cache. The list will be copied to ensure immutability. To guarantee immutability the entries indata
must be immutable themselves. There must be more data thanneighborsSize
.- Throws:
IllegalArgumentException
- ifneighborsSize > data.size()
or ifneighborsSize
is negative
-
-
Method Detail
-
emptyCache
public static <TS extends FieldTimeStamped<CFE>,CFE extends CalculusFieldElement<CFE>> ImmutableFieldTimeStampedCache<TS,CFE> emptyCache(Field<CFE> field)
Get an empty immutable cache, cast to the correct type.- Type Parameters:
TS
- the type of dataCFE
- the type of the calculus field element- Parameters:
field
- field to which the elements belong- Returns:
- an empty
ImmutableTimeStampedCache
.
-
getNeighbors
public Stream<T> getNeighbors(FieldAbsoluteDate<KK> central)
Get the entries surrounding a central date.If the central date is well within covered range, the returned array will be balanced with half the points before central date and half the points after it (depending on n parity, of course). If the central date is near the boundary, then the returned array will be unbalanced and will contain only the n earliest (or latest) entries. A typical example of the later case is leap seconds cache, since the number of leap seconds cannot be arbitrarily increased.
This method is safe for multiple threads to execute concurrently.
- Specified by:
getNeighbors
in interfaceFieldTimeStampedCache<T extends FieldTimeStamped<KK>,KK extends CalculusFieldElement<KK>>
- Parameters:
central
- central date- Returns:
- list of cached entries surrounding the specified date. The size of the list is guaranteed to be
FieldTimeStampedCache.getNeighborsSize()
.
-
getNeighborsSize
public int getNeighborsSize()
Get the fixed size of the lists returned byFieldTimeStampedCache.getNeighbors(FieldAbsoluteDate)
.- Specified by:
getNeighborsSize
in interfaceFieldTimeStampedCache<T extends FieldTimeStamped<KK>,KK extends CalculusFieldElement<KK>>
- Returns:
- size of the list
-
getEarliest
public T getEarliest()
Get the earliest entry in this cache.- Specified by:
getEarliest
in interfaceFieldTimeStampedCache<T extends FieldTimeStamped<KK>,KK extends CalculusFieldElement<KK>>
- Returns:
- earliest cached entry
-
getLatest
public T getLatest()
Get the latest entry in this cache.- Specified by:
getLatest
in interfaceFieldTimeStampedCache<T extends FieldTimeStamped<KK>,KK extends CalculusFieldElement<KK>>
- Returns:
- latest cached entry
-
getAll
public List<T> getAll()
Get all the data in this cache.- Returns:
- a sorted collection of all data passed in the
constructor
.
-
-