Class Scope

java.lang.Object
io.pebbletemplates.pebble.template.Scope

public class Scope extends Object
A scope is a map of variables. A "local" scope ensures that the search for a particular variable will end at this scope whether or not it was found.
  • Field Details

    • local

      private final boolean local
      A "local" scope ensures that the search for a particular variable will end at this scope whether or not it was found.
    • backingMap

      private final Map<String,Object> backingMap
      The map of variables known at this scope
  • Constructor Details

    • Scope

      public Scope(Map<String,Object> backingMap, boolean local)
      Constructor
      Parameters:
      backingMap - The backing map of variables
      local - Whether this scope is local or not
  • Method Details

    • shallowCopy

      public Scope shallowCopy()
      Creates a shallow copy of the Scope.

      This is used for the parallel tag because every new thread should have a "snapshot" of the scopes, i.e. one thread should not affect rendering output of another.

      It will construct a new collection but it will contain references to all of the original variables therefore it is not a deep copy. This is why it is import for the user to use thread-safe variables when using the parallel tag.

      Returns:
      A copy of the scope
    • put

      public void put(String key, Object value)
      Adds a variable to this scope
      Parameters:
      key - The name of the variable
      value - The value of the variable
    • get

      public Object get(String key)
      Retrieves the variable at this scope
      Parameters:
      key - The name of the variable
      Returns:
      The value of the variable
    • containsKey

      public boolean containsKey(String key)
      Checks if this scope contains a variable of a certain name.
      Parameters:
      key - The name of the variable
      Returns:
      boolean stating whether or not the backing map of this scope contains that variable
    • isLocal

      public boolean isLocal()
      Returns whether or not this scope is "local".
      Returns:
      boolean stating whether this scope is local or not.
    • getKeys

      public Set<String> getKeys()
      Returns keys of all the variables at this scope.
      Returns:
      A set of keys