boolean test(Symbol buffer, Chunk bufferChunk, Instantiation inst) { boolean negated = (operator != null && operator.equals("-")); Symbol realSlot = (slot.isVariable()) ? inst.get(slot) : slot; if (realSlot == null) { // slot variable isn't defined yet, so save it in the instantiation to check later inst.addDelayedSlotCondition(buffer, this, bufferChunk); return true; // negated; // false; } Symbol bufferValue = bufferChunk.get(realSlot); if (bufferValue == null) return negated; // false; Symbol testValue = value; if (testValue.isVariable()) { if (bufferValue == Symbol.nil) return negated; // false; testValue = inst.get(testValue); if (testValue == null) { inst.set(value, bufferValue); return true; } } if (operator == null) return (testValue == bufferValue); else if (operator.equals("-")) return (testValue != bufferValue); else { double bufferNumber = Double.valueOf(bufferValue.getString()); double testNumber = Double.valueOf(testValue.getString()); if (operator.equals("<")) return (bufferNumber < testNumber); else if (operator.equals(">")) return (bufferNumber > testNumber); else if (operator.equals("<=")) return (bufferNumber <= testNumber); else if (operator.equals(">=")) return (bufferNumber >= testNumber); } return false; }
/** * Gets a string representation of the slot condition with an instantiation if provided. * * @return the string */ public String toString(Instantiation inst, Vector<Symbol> used) { String s = " "; if (operator != null) s += operator + " "; s += slot + " " + value; if (inst != null && value.isVariable() && (used == null || !used.contains(value))) { Symbol v = inst.get(value); if (v != null) { s = String.format("%-35s", s); s += "[" + value + " <- " + v + "]"; } if (used != null) used.add(value); } return s; }