Expirable.java

  1. package swingtree.style;

  2. import swingtree.animation.LifeSpan;

  3. import java.util.Objects;

  4. /**
  5.  *  A wrapper class for a payload that has a lifetime which
  6.  *  is used to determine if the payload is expired or not.
  7.  **/
  8. final class Expirable<T>
  9. {
  10.     private final LifeSpan _lifeSpan;
  11.     private final T        _value;


  12.     Expirable( LifeSpan lifeSpan, T payload ) {
  13.         _lifeSpan = Objects.requireNonNull(lifeSpan);
  14.         _value    = Objects.requireNonNull(payload);
  15.     }

  16.     /**
  17.      *  Determines if the lifetime of this instance is expired,
  18.      *  which is based on the current time and the start and end
  19.      *  of the lifespan.
  20.      *  @return True if the lifetime of this instance is expired,
  21.      *          false otherwise.
  22.      **/
  23.     boolean isExpired() { return _lifeSpan.isExpired(); }

  24.     /**
  25.      *  Exposes the thing that can expire.
  26.      *  @return The payload of this instance.
  27.      **/
  28.     T get() { return _value; }

  29.     /**
  30.      *  Exposes the lifespan of this instance,
  31.      *  which is used to determine if the payload is expired.
  32.      *  @return The time span of this instance.
  33.      **/
  34.     LifeSpan getLifeSpan() { return _lifeSpan; }
  35. }