T
- the type of datapublic class ImmutableTimeStampedCache<T extends TimeStamped> extends Object implements TimeStampedCache<T>
TimeStamped
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.Constructor and Description |
---|
ImmutableTimeStampedCache(int neighborsSize,
Collection<? extends T> data)
Create a new cache with the given neighbors size and data.
|
Modifier and Type | Method and Description |
---|---|
static <TS extends TimeStamped> |
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 by
TimeStampedCache.getNeighbors(AbsoluteDate) . |
String |
toString() |
public ImmutableTimeStampedCache(int neighborsSize, Collection<? extends T> data)
neighborsSize
- the size of the list returned from
getNeighbors(AbsoluteDate)
. Must be less than or equal to
data.size()
.data
- the backing data for this cache. The list will be copied to
ensure immutability. To guarantee immutability the entries in
data
must be immutable themselves. There must be more data
than neighborsSize
.IllegalArgumentException
- if neightborsSize > data.size()
or if neighborsSize
is negativepublic Stream<T> getNeighbors(AbsoluteDate central)
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.
getNeighbors
in interface TimeStampedCache<T extends TimeStamped>
central
- central dateTimeStampedCache.getNeighborsSize()
.public int getNeighborsSize()
TimeStampedCache.getNeighbors(AbsoluteDate)
.getNeighborsSize
in interface TimeStampedCache<T extends TimeStamped>
public T getEarliest()
getEarliest
in interface TimeStampedCache<T extends TimeStamped>
public T getLatest()
getLatest
in interface TimeStampedCache<T extends TimeStamped>
public List<T> getAll()
constructor
.public static final <TS extends TimeStamped> ImmutableTimeStampedCache<TS> emptyCache()
TS
- the type of dataImmutableTimeStampedCache
.Copyright © 2002-2022 CS GROUP. All rights reserved.