public class PatternMap extends java.lang.Object implements ISymbol2IntMap, java.lang.Cloneable, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_RULE_PRIORITY
The default priority when associating a new rule to a symbol.
|
protected int |
fPriority
Priority of this PatternMap.
|
Modifier | Constructor and Description |
---|---|
protected |
PatternMap() |
Modifier and Type | Method and Description |
---|---|
void |
addPattern(java.util.Map<IExpr,java.lang.Integer> patternIndexMap,
IPatternObject pattern)
Set the index of
fPatternSymbolsArray where the
pattern stores it's assigned value during pattern matching. |
protected void |
addSinglePattern(IPatternObject pattern) |
protected PatternMap |
clone() |
protected IExpr[] |
copyPattern()
Copy the current values into a new array.
|
protected void |
copyPatternValuesFromPatternMatcher(PatternMap patternMap)
Copy the found pattern matches from the given
patternMap
back to this maps pattern values. |
protected int |
determinePatterns(IExpr lhsPatternExpr)
Determine all patterns (i.e. all objects of instance IPattern) in the
given expression
Increments this classes pattern counter.
|
int |
get(IExpr patternOrSymbol)
Get the
int value mapped to the given symbol. |
int |
getPriority()
Get the priority of this PatternMap
|
protected IExpr |
getValue(int index)
Return the matched value for the given
index if possisble. |
IExpr |
getValue(IPatternObject pattern)
Return the matched value for the given pattern object
|
protected java.util.List<IExpr> |
getValuesAsList() |
protected void |
initPattern()
Set all pattern values to
null ; |
protected boolean |
isAllPatternsAssigned()
Check if all symbols in the symbols array have corresponding values
assigned.
|
boolean |
isEmpty()
Gives
true if there's no symbol used in this map. |
boolean |
isPatternTest(IExpr expr,
IExpr patternTest) |
protected boolean |
isRuleWithoutPatterns()
Returns true if the given expression contains no patterns
|
protected void |
resetPattern(IExpr[] patternValuesArray)
Reset the values to the values in the given array
|
boolean |
setValue(IPatternObject pattern,
IExpr expr) |
boolean |
setValue(IPatternSequence pattern,
IAST sequence) |
int |
size()
Gives the number of symbols used in this map.
|
protected IExpr |
substitutePatternOrSymbols(IExpr lhsPatternExpr)
Substitute all patterns and symbols in the given expression with the
current value of the corresponding internal pattern values arrays
|
protected IExpr |
substituteSymbols(IExpr rhsExpr)
Substitute all symbols in the given expression with the current value of
the corresponding internal pattern values arrays
|
IExpr |
val(ISymbol symbol)
Return the matched value for the given symbol
|
protected int fPriority
public static final int DEFAULT_RULE_PRIORITY
public void addPattern(java.util.Map<IExpr,java.lang.Integer> patternIndexMap, IPatternObject pattern)
fPatternSymbolsArray
where the
pattern
stores it's assigned value during pattern matching.pattern
- patternIndexMap
- protected void addSinglePattern(IPatternObject pattern)
protected PatternMap clone()
clone
in class java.lang.Object
protected IExpr[] copyPattern()
resetPattern(IExpr[])
protected void copyPatternValuesFromPatternMatcher(PatternMap patternMap)
patternMap
back to this maps pattern values.patternMap
- protected int determinePatterns(IExpr lhsPatternExpr)
lhsPatternExpr
- the (left-hand-side) expression which could contain pattern
objects.public int get(IExpr patternOrSymbol)
int
value mapped to the given symbol.get
in interface ISymbol2IntMap
public int getPriority()
protected IExpr getValue(int index)
index
if possisble.null
if no matched expression existspublic IExpr getValue(IPatternObject pattern)
pExpr
- null
if no matched expression existspublic final IExpr val(ISymbol symbol)
symbol
- the symbolnull
if no matched expression existsprotected java.util.List<IExpr> getValuesAsList()
protected final void initPattern()
null
;protected boolean isAllPatternsAssigned()
public boolean isEmpty()
true
if there's no symbol used in this map.isEmpty
in interface ISymbol2IntMap
protected boolean isRuleWithoutPatterns()
protected void resetPattern(IExpr[] patternValuesArray)
patternValuesArray
- copyPattern()
public boolean setValue(IPatternObject pattern, IExpr expr)
public boolean setValue(IPatternSequence pattern, IAST sequence)
public int size()
size
in interface ISymbol2IntMap
protected IExpr substitutePatternOrSymbols(IExpr lhsPatternExpr)
lhsPatternExpr
- left-hand-side expression which may containe pattern objectsprotected IExpr substituteSymbols(IExpr rhsExpr)
rhsExpr
- right-hand-side expression, substitute all symbols from the
pattern-matching values