Class ManifestCreatorCache<K extends java.io.Serializable,V extends java.io.Serializable>
- java.lang.Object
-
- org.schabi.newpipe.extractor.utils.ManifestCreatorCache<K,V>
-
- Type Parameters:
K- the type of cache keys, which must beserializableV- the type of the second element ofpairsused as values of the cache, which must beserializable
- 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.SerializableAserializablecache class used by the extractor to cache manifests generated with extractor's manifests generators.It relies internally on a
ConcurrentHashMapto allow concurrent access to the cache.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_CLEAR_FACTORThe default clear factor of a manifest cache.static intDEFAULT_MAXIMUM_SIZEThe default maximum size of a manifest cache.
-
Constructor Summary
Constructors Constructor Description ManifestCreatorCache()Creates a newManifestCreatorCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the cached manifests.booleancontainsKey(K key)Tests if the specified key is in the cache.Pair<java.lang.Integer,V>get(K key)Returns the value to which the specified key is mapped, ornullif the cache contains no mapping for the key.doublegetClearFactor()longgetMaximumSize()Vput(K key, V value)Adds a new element to the cache.voidreset()Resets the cache.voidresetClearFactor()Resets the clear factor to itsdefault value.voidresetMaximumSize()Resets the maximum size of the cache to itsdefault value.voidsetClearFactor(double clearFactor)Sets the clear factor of the cache, used when the cache limit size is reached.voidsetMaximumSize(int maximumSize)Sets the maximum size of the cache.intsize()java.lang.StringtoString()
-
-
-
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
-
-
Constructor Detail
-
ManifestCreatorCache
public ManifestCreatorCache()
Creates a newManifestCreatorCache.
-
-
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:
trueif the key is in the cache,falseotherwise.
-
get
@Nullable public Pair<java.lang.Integer,V> get(K key)
Returns the value to which the specified key is mapped, ornullif 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 putvalue- the value to associate to the key- Returns:
- the previous value associated with the key, or
nullif there was no mapping for the key (note that a null return can also indicate that the cache previously associatednullwith the key).
-
clear
public void clear()
Clears the cached manifests.The cache will be empty after this method is called.
-
reset
public void reset()
Resets the cache.The cache will be empty and the clear factor and the maximum size will be reset to their default values.
- See Also:
clear(),resetClearFactor(),resetMaximumSize()
-
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- ifmaximumSizeis less than or equal to 0
-
resetMaximumSize
public void resetMaximumSize()
Resets the maximum size of the cache to itsdefault 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
0excluded and1excluded.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 itsdefault value.
-
toString
@Nonnull public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-