Class CachingFunction<T,​R>

  • All Implemented Interfaces:
    java.util.function.Function<T,​R>

    public class CachingFunction<T,​R>
    extends java.lang.Object
    implements java.util.function.Function<T,​R>
    Wrapper for a Function that caches its results.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<T,​R> cache
      A cache of the wrapped values.
      private java.util.function.Function<T,​R> wrapped
      The function to be wrapped.
    • Constructor Summary

      Constructors 
      Constructor Description
      CachingFunction​(java.util.function.Function<T,​R> wrapped)
      Create a new caching function.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      R apply​(T t)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Field Detail

      • wrapped

        private final java.util.function.Function<T,​R> wrapped
        The function to be wrapped.
      • cache

        private final java.util.Map<T,​R> cache
        A cache of the wrapped values.
    • Constructor Detail

      • CachingFunction

        public CachingFunction​(java.util.function.Function<T,​R> wrapped)
        Create a new caching function.
        Parameters:
        wrapped - The Function to be wrapped.
    • Method Detail

      • apply

        public R apply​(T t)
        Specified by:
        apply in interface java.util.function.Function<T,​R>