Class NestedCache<T>

java.lang.Object
org.opentrafficsim.core.gtu.NestedCache<T>
Type Parameters:
T - value type

public class NestedCache<T>
extends Object
Utility class to cache data based on a variable (between cache instances) number of keys of any type. This replaces nested Maps.

Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Version:
$Revision$, $LastChangedDate$, by $Author$, initial version 20 apr. 2018
Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Details

    • NestedCache

      public NestedCache​(Class<?>... types)
      Constructor.
      Parameters:
      types - Class<?>...; types
  • Method Details

    • getValue

      public T getValue​(Supplier<T> supplier, Object... keys)
      Returns a value.
      Parameters:
      supplier - Supplier<T>; supplier of T for if it wasn't cached yet
      keys - Object...; list of key objects
      Returns:
      T; value
    • getKeys

      public Set<Object> getKeys()
      Return set of key objects on this level.
      Returns:
      Set; set of key objects on this level
    • getChild

      public NestedCache<T> getChild​(Object key) throws IllegalStateException
      Return branch for key.
      Parameters:
      key - Object; key
      Returns:
      NestedCache; branch for key
      Throws:
      IllegalStateException - if this is not a branch level
    • getValue

      public T getValue​(Object key) throws IllegalStateException
      Return value for key.
      Parameters:
      key - Object; key
      Returns:
      T; value for key
      Throws:
      IllegalStateException - if this is not a leaf level
    • clear

      public Object clear​(Object key)
      Clears the cache for the given key.
      Parameters:
      key - Object; key to clear the cache for
      Returns:
      Object; object that was previously cached to the key, or null if it was not cached.
    • toString

      public String toString()
      Overrides:
      toString in class Object