Class ManifestCreatorCache<K extends java.io.Serializable,​V extends java.io.Serializable>

  • Type Parameters:
    K - the type of cache keys, which must be serializable
    V - the type of the second element of pairs used as values of the cache, which must be serializable
    All Implemented Interfaces:
    java.io.Serializable

    public final class ManifestCreatorCache<K extends java.io.Serializable,​V extends java.io.Serializable>
    extends java.lang.Object
    implements java.io.Serializable
    A serializable cache class used by the extractor to cache manifests generated with extractor's manifests generators.

    It relies internally on a ConcurrentHashMap to allow concurrent access to the cache.

    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_MAXIMUM_SIZE

        public static final int DEFAULT_MAXIMUM_SIZE
        The default maximum size of a manifest cache.
        See Also:
        Constant Field Values
      • DEFAULT_CLEAR_FACTOR

        public static final double DEFAULT_CLEAR_FACTOR
        The default clear factor of a manifest cache.
        See Also:
        Constant Field Values
    • Method Detail

      • containsKey

        public boolean containsKey​(K key)
        Tests if the specified key is in the cache.
        Parameters:
        key - the key to test its presence in the cache
        Returns:
        true if the key is in the cache, false otherwise.
      • get

        @Nullable
        public Pair<java.lang.Integer,​V> get​(K key)
        Returns the value to which the specified key is mapped, or null if the cache contains no mapping for the key.
        Parameters:
        key - the key to which getting its value
        Returns:
        the value to which the specified key is mapped, or null
      • put

        @Nullable
        public V put​(K key,
                     V value)
        Adds a new element to the cache.

        If the cache limit is reached, oldest elements will be cleared first using the load factor and the maximum size.

        Parameters:
        key - the key to put
        value - the value to associate to the key
        Returns:
        the previous value associated with the key, or null if there was no mapping for the key (note that a null return can also indicate that the cache previously associated null with the key).
      • clear

        public void clear()
        Clears the cached manifests.

        The cache will be empty after this method is called.

      • size

        public int size()
        Returns:
        the number of cached manifests in the cache
      • getMaximumSize

        public long getMaximumSize()
        Returns:
        the maximum size of the cache
      • setMaximumSize

        public void setMaximumSize​(int maximumSize)
        Sets the maximum size of the cache. If the current cache size is more than the new maximum size, the percentage of one less the clear factor of the maximum new size of manifests in the cache will be removed.
        Parameters:
        maximumSize - the new maximum size of the cache
        Throws:
        java.lang.IllegalArgumentException - if maximumSize is less than or equal to 0
      • resetMaximumSize

        public void resetMaximumSize()
        Resets the maximum size of the cache to its default value.
      • getClearFactor

        public double getClearFactor()
        Returns:
        the current clear factor of the cache, used when the cache limit size is reached
      • setClearFactor

        public void setClearFactor​(double clearFactor)
        Sets the clear factor of the cache, used when the cache limit size is reached.

        The clear factor must be a double between 0 excluded and 1 excluded.

        Note that it will be only used the next time the cache size limit is reached.

        Parameters:
        clearFactor - the new clear factor of the cache
        Throws:
        java.lang.IllegalArgumentException - if the clear factor passed a parameter is invalid
      • resetClearFactor

        public void resetClearFactor()
        Resets the clear factor to its default value.
      • toString

        @Nonnull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object