Class Scope
- java.lang.Object
-
- io.pebbletemplates.pebble.template.Scope
-
public class Scope extends java.lang.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 Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.Object>
backingMap
The map of variables known at this scopeprivate boolean
local
A "local" scope ensures that the search for a particular variable will end at this scope whether or not it was found.
-
Constructor Summary
Constructors Constructor Description Scope(java.util.Map<java.lang.String,java.lang.Object> backingMap, boolean local)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(java.lang.String key)
Checks if this scope contains a variable of a certain name.java.lang.Object
get(java.lang.String key)
Retrieves the variable at this scopejava.util.Set<java.lang.String>
getKeys()
Returns keys of all the variables at this scope.boolean
isLocal()
Returns whether or not this scope is "local".void
put(java.lang.String key, java.lang.Object value)
Adds a variable to this scopeScope
shallowCopy()
Creates a shallow copy of the Scope.
-
-
-
Method Detail
-
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(java.lang.String key, java.lang.Object value)
Adds a variable to this scope- Parameters:
key
- The name of the variablevalue
- The value of the variable
-
get
public java.lang.Object get(java.lang.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(java.lang.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 java.util.Set<java.lang.String> getKeys()
Returns keys of all the variables at this scope.- Returns:
- A set of keys
-
-