Package org.apache.commons.collections4.map

# Class PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<K,V>

java.lang.Object
org.apache.commons.collections4.map.PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<K,V>

Type Parameters:
  `K` - The type of the keys in the map
  `V` - The type of the values in the map

All Implemented Interfaces:
  `Serializable`, `PassiveExpiringMap.ExpirationPolicy<K,V>`

Enclosing class:
  `PassiveExpiringMap<K,V>`

public static class PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<K,V> extends Object implements PassiveExpiringMap.ExpirationPolicy<K,V>
A `ExpirationPolicy` that returns an expiration time that is a constant about of time in the future from the current time.

Since:
  4.0
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ConstantTimeToLiveExpirationPolicy()`
  Default constructor.
  `ConstantTimeToLiveExpirationPolicy(long timeToLiveMillis)`
  Constructs a policy with the given time-to-live constant measured in milliseconds.
  `ConstantTimeToLiveExpirationPolicy(long timeToLive, TimeUnit timeUnit)`
  Constructs a policy with the given time-to-live constant measured in the given time unit of measure.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `expirationTime(K key, V value)`
  Determine the expiration time for the given key-value entry.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ConstantTimeToLiveExpirationPolicy

    public ConstantTimeToLiveExpirationPolicy()
    Default constructor. Constructs a policy using a negative time-to-live value that results in entries never expiring.

  - ### ConstantTimeToLiveExpirationPolicy

    public ConstantTimeToLiveExpirationPolicy(long timeToLiveMillis)
    Constructs a policy with the given time-to-live constant measured in milliseconds. A negative time-to-live value indicates entries never expire. A zero time-to-live value indicates entries expire (nearly) immediately.
    Parameters:
      `timeToLiveMillis` - The constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

  - ### ConstantTimeToLiveExpirationPolicy

    public ConstantTimeToLiveExpirationPolicy(long timeToLive, TimeUnit timeUnit)
    Constructs a policy with the given time-to-live constant measured in the given time unit of measure.
    Parameters:
      `timeToLive` - The constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
      `timeUnit` - The unit of time for the `timeToLive` parameter, must not be null.
    Throws:
      `NullPointerException` - if the time unit is null.

- ## Method Details

  - ### expirationTime

    public long expirationTime(K key, V value)
    Determine the expiration time for the given key-value entry.
    Specified by:
      `expirationTime` in interface `PassiveExpiringMap.ExpirationPolicy<K,V>`
    Parameters:
      `key` - The key for the entry (ignored).
      `value` - The value for the entry (ignored).
    Returns:
      if `timeToLiveMillis` ≥ 0, an expiration time of `timeToLiveMillis` + `System.currentTimeMillis()` is returned. Otherwise, -1 is returned indicating the entry never expires.