Package org.orekit.utils
Class ImmutableTimeStampedCache<T extends TimeStamped>
- java.lang.Object
-
- org.orekit.utils.ImmutableTimeStampedCache<T>
-
- Type Parameters:
T
- the type of data
- All Implemented Interfaces:
TimeStampedCache<T>
public class ImmutableTimeStampedCache<T extends TimeStamped> extends Object implements TimeStampedCache<T>
A cache ofTimeStamped
data that provides concurrency through immutability. This strategy is suitable when all of the cached data is stored in memory. (For example,UTCScale
) This class then provides convenient methods for accessing the data.- Author:
- Evan Ward
-
-
Constructor Summary
Constructors Constructor Description ImmutableTimeStampedCache(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 TimeStamped>
ImmutableTimeStampedCache<TS>emptyCache()
Get an empty immutable cache, cast to the correct type.List<T>
getAll()
Get all of 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(AbsoluteDate central)
Get the entries surrounding a central date.int
getNeighborsSize()
Get the fixed size of the lists returned byTimeStampedCache.getNeighbors(AbsoluteDate)
.String
toString()
-
-
-
Constructor Detail
-
ImmutableTimeStampedCache
public ImmutableTimeStampedCache(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(AbsoluteDate)
. 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
- ifneightborsSize > data.size()
or ifneighborsSize
is negative
-
-
Method Detail
-
getNeighbors
public Stream<T> getNeighbors(AbsoluteDate 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 interfaceTimeStampedCache<T extends TimeStamped>
- Parameters:
central
- central date- Returns:
- list of cached entries surrounding the specified date. The size
of the list is guaranteed to be
TimeStampedCache.getNeighborsSize()
.
-
getNeighborsSize
public int getNeighborsSize()
Description copied from interface:TimeStampedCache
Get the fixed size of the lists returned byTimeStampedCache.getNeighbors(AbsoluteDate)
.- Specified by:
getNeighborsSize
in interfaceTimeStampedCache<T extends TimeStamped>
- Returns:
- size of the list
-
getEarliest
public T getEarliest()
Description copied from interface:TimeStampedCache
Get the earliest entry in this cache.- Specified by:
getEarliest
in interfaceTimeStampedCache<T extends TimeStamped>
- Returns:
- earliest cached entry
-
getLatest
public T getLatest()
Description copied from interface:TimeStampedCache
Get the latest entry in this cache.- Specified by:
getLatest
in interfaceTimeStampedCache<T extends TimeStamped>
- Returns:
- latest cached entry
-
getAll
public List<T> getAll()
Get all of the data in this cache.- Returns:
- a sorted collection of all data passed in the
constructor
.
-
emptyCache
public static final <TS extends TimeStamped> ImmutableTimeStampedCache<TS> emptyCache()
Get an empty immutable cache, cast to the correct type.- Type Parameters:
TS
- the type of data- Returns:
- an empty
ImmutableTimeStampedCache
.
-
-