Class Sticky<T>

  • Type Parameters:
    T - Type of result
    All Implemented Interfaces:
    Scalar<T>

    public final class Sticky<T>
    extends Object
    implements Scalar<T>
    Cached version of a Scalar.

    This Scalar decorator technically is an in-memory cache.

    Pay attention that this class is not thread-safe. It is highly recommended to always decorate it with Synced.

    This class implements Scalar, which throws a checked Exception. This may not be convenient in many cases. To make it more convenient and get rid of the checked exception you can use the Unchecked decorator. Or you may use IoChecked to wrap it in an IOException.

    
     final Scalar<Integer> scalar = new StickyScalar<>(
         () -> {
             System.out.println("Will be printed only once");
             return new SecureRandom().nextInt();
         }
     ).value()
     

    There is no thread-safety guarantee.

    Since:
    0.3
    See Also:
    StickyFunc
    • Constructor Detail

      • Sticky

        public Sticky​(Scalar<? extends T> scalar)
        Ctor.
        Parameters:
        scalar - The Scalar to cache
    • Method Detail

      • value

        public T value()
                throws Exception
        Description copied from interface: Scalar
        Convert it to the value.
        Specified by:
        value in interface Scalar<T>
        Returns:
        The value
        Throws:
        Exception - If fails