Package net.ssehub.easy.varModel.cst
Class VariablePool
java.lang.Object
net.ssehub.easy.varModel.cst.VariablePool
Utility class for caching / pooling variables in order to save memory.
Please use this class local to a model / operation in order avoid that memory
remains allocated although not used.
- Author:
- Sascha El-Sharkawy, Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclear()Clears this pool for reuse or to force unallocation of memory.static final IntegerkeyObject(AbstractVariable decl) Returns the key object for hashes, also for tests.final booleanReturns whether this pool knows a certain variable.final VariableReturns aVariablefor the givenAbstractVariable.toString()
-
Field Details
-
ENABLE
private static final boolean ENABLE- See Also:
-
variablesCache
-
-
Constructor Details
-
VariablePool
public VariablePool()
-
-
Method Details
-
obtainVariable
Returns aVariablefor the givenAbstractVariable. This method will cache already createdVariables to reduce memory consumption.- Parameters:
decl- AAbstractVariablefor which aVariableshall be created.- Returns:
- A cached
Variablefor the givenAbstractVariableor a new one if no cached variable exists, a new one is created and will be cached for future calls.
-
keyObject
Returns the key object for hashes, also for tests. This is needed, as the equals/hashcode implementation ofAbstractVariableis just based on the name and does not cope with local variables. This method shall remind dependent implementations about the aforementionied problem.- Parameters:
decl- the declaration- Returns:
- the key/hash object
-
knowsVariable
Returns whether this pool knows a certain variable.- Parameters:
decl- the variable declaration- Returns:
trueif the pool knows the variable,falseelse
-
clear
public final void clear()Clears this pool for reuse or to force unallocation of memory. -
toString
-