package abstrasy;
import abstrasy.interpreter.InterpreterException;
import abstrasy.interpreter.StdErrors;
/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
* http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/
public class MemoizeKey {
String value;
long qtype;
int hash;
public MemoizeKey(Node node) throws InterpreterException {
this.qtype=node.getQType();
try {
value=node.nodeToSerializedString(Node.createCList());
//System.out.println(value);
}
catch (Exception e) {
if(Interpreter.isDebugMode())
e.printStackTrace();
throw new InterpreterException(StdErrors.createTrace(node, e));
}
hash=value.hashCode();
}
public int hashCode(){
return hash;
}
public boolean equals(Object other){
if(other instanceof MemoizeKey){
MemoizeKey otherk=(MemoizeKey)other;
return otherk.qtype==qtype && otherk.hash==hash && otherk.value.equals(value);
}
else{
return false;
}
}
public Node toNode() throws InterpreterException {
Interpreter interpreter = Interpreter.interpr_getNewChildInterpreter();
interpreter.setSource(value);
try {
interpreter.compile();
}
catch (Exception e) {
if(Interpreter.isDebugMode())
e.printStackTrace();
throw new InterpreterException(StdErrors.createTrace(interpreter, e));
}
return interpreter.getNode();
/*switch(type){
case Node.TYPE_NUMBER:
return new Node(((Double)value).doubleValue()).letQuoted((qtype & Node.VTYPE_QTYPES)!=0);
case Node.TYPE_PCODE:
return Node.createPCode(((Integer)value).intValue()).letQuoted((qtype & Node.VTYPE_QTYPES)!=0);
case Node.TYPE_STRING:
return new Node((String)value).letQuoted((qtype & Node.VTYPE_QTYPES)!=0);
case Node.TYPE_SYMBOL:
return Node.createSymbol((String)value).letQuoted((qtype & Node.VTYPE_QTYPES)!=0);
case Node.TYPE_NOTHING:
return Node.createNothing().letQuoted((qtype & Node.VTYPE_QTYPES)!=0);
default:
throw new InterpreterException(StdErrors.Invalid_parameter);
}*/
}
}