Package net.ssehub.easy.varModel.cst
Class VariablePool
- java.lang.Object
-
- net.ssehub.easy.varModel.cst.VariablePool
-
public class VariablePool extends java.lang.ObjectUtility 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
Fields Modifier and Type Field Description private static booleanENABLEprivate java.util.Map<java.lang.Integer,Variable>variablesCache
-
Constructor Summary
Constructors Constructor Description VariablePool()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this pool for reuse or to force unallocation of memory.static java.lang.IntegerkeyObject(AbstractVariable decl)Returns the key object for hashes, also for tests.booleanknowsVariable(AbstractVariable decl)Returns whether this pool knows a certain variable.VariableobtainVariable(AbstractVariable decl)Returns aVariablefor the givenAbstractVariable.java.lang.StringtoString()
-
-
-
Field Detail
-
ENABLE
private static final boolean ENABLE
- See Also:
- Constant Field Values
-
variablesCache
private java.util.Map<java.lang.Integer,Variable> variablesCache
-
-
Method Detail
-
obtainVariable
public final Variable obtainVariable(AbstractVariable decl)
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
public static final java.lang.Integer keyObject(AbstractVariable decl)
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
public final boolean knowsVariable(AbstractVariable decl)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-