Class Cache<T,​R>

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

    public class Cache<T,​R>
    extends java.lang.Object
    implements java.util.function.Function<T,​R>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<T,​R> cache  
      private java.util.function.Function<T,​R> function  
    • Constructor Summary

      Constructors 
      Constructor Description
      Cache​(java.util.function.Function<T,​R> function)
      Creates an empty cache
    • Method Summary

      Modifier and Type Method Description
      R apply​(T input)  
      R put​(T input, R output)  
      R remove​(T input)  
      void setFunction​(java.util.function.Function<T,​R> function)
      Sets the function which is used for future calls, but does not recompute already cached elements.
      int size()  
      • 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

      • cache

        private java.util.Map<T,​R> cache
      • function

        private java.util.function.Function<T,​R> function
    • Constructor Detail

      • Cache

        public Cache​(java.util.function.Function<T,​R> function)
        Creates an empty cache
        Parameters:
        function -
    • Method Detail

      • apply

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

        public R put​(T input,
                     R output)
      • remove

        public R remove​(T input)
      • size

        public int size()
        Returns:
        the cache size
        See Also:
        Map.size()
      • setFunction

        public void setFunction​(java.util.function.Function<T,​R> function)
        Sets the function which is used for future calls, but does not recompute already cached elements.
        Parameters:
        function -