Class ImmutableTimeStampedCache<T extends TimeStamped>

  • Type Parameters:
    T - the type of data
    All Implemented Interfaces:

    public class ImmutableTimeStampedCache<T extends TimeStamped>
    extends Object
    implements TimeStampedCache<T>
    A cache of 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.
    Evan Ward
    • Constructor Detail

      • ImmutableTimeStampedCache

        public ImmutableTimeStampedCache​(int maxNeighborsSize,
                                         Collection<? extends T> data)
        Create a new cache with the given neighbors size and data.
        maxNeighborsSize - the maximum size of the list returned from getNeighbors(AbsoluteDate, int). 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 maxNeighborsSize.
        IllegalArgumentException - if neightborsSize > data.size() or if neighborsSize is negative
    • Method Detail

      • getNeighbors

        public Stream<T> getNeighbors​(AbsoluteDate central,
                                      int n)
        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 interface TimeStampedCache<T extends TimeStamped>
        central - central date
        n - number of neighbors (cannot exceed TimeStampedCache.getMaxNeighborsSize())
        stream of cached entries surrounding the specified date.
      • getAll

        public List<T> getAll()
        Get all of the data in this cache.
        a sorted collection of all data passed in the constructor.