Class StickyFunc<X,​Y>

  • Type Parameters:
    X - Type of input
    Y - Type of output
    All Implemented Interfaces:
    Func<X,​Y>

    public final class StickyFunc<X,​Y>
    extends Object
    implements Func<X,​Y>
    Func that caches previously calculated values and doesn't recalculate again.

    This Func 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 SyncFunc.

    There is no thread-safety guarantee.

    Since:
    0.1
    See Also:
    Sticky
    • Constructor Detail

      • StickyFunc

        public StickyFunc​(Func<X,​Y> fnc)
        Ctor.
        Parameters:
        fnc - Func original
      • StickyFunc

        public StickyFunc​(Func<X,​Y> fnc,
                          int max)
        Ctor.
        Parameters:
        fnc - Func original
        max - Maximum cache size
        Since:
        0.26
    • Method Detail

      • apply

        public Y apply​(X input)
                throws Exception
        Description copied from interface: Func
        Apply it.
        Specified by:
        apply in interface Func<X,​Y>
        Parameters:
        input - The argument
        Returns:
        The result
        Throws:
        Exception - If fails