public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } SubLObject sublObj = (SubLObject) obj; if (!sublObj.isList()) { return false; } SubLList otherCons = sublObj.toList(); SubLListListIterator iter1 = null; SubLListListIterator iter2 = null; Resourcer resourcer = Resourcer.getInstance(); try { iter1 = resourcer.acquireSubLListListIterator(this); iter2 = resourcer.acquireSubLListListIterator(otherCons); while (iter1.hasNext() && (!iter1.isNextImproperElement())) { if ((!iter2.hasNext()) || (iter2.isNextImproperElement())) { return false; } if (!iter1.next().equals(iter2.next())) { return false; } } if (iter1.isNextImproperElement()) { if (iter2.isNextImproperElement()) { return iter1.getDottedElement().equals(iter2.getDottedElement()); } return false; } else if (iter2.hasNext()) { // iter1 is prefix of iter2 case return false; } // they should be equal at this point return true; } finally { resourcer.releaseSubLListListIterator(iter1); resourcer.releaseSubLListListIterator(iter2); } }
public String toString() { if (PrintLow.shouldPrintAtCurrentLevel()) { final SubLObject oldLevel = PrintLow.maybeIncreasePrintLevel(); try { if (this == SubLNil.NIL) { return "NIL"; } SubLListListIterator iter = null; Resourcer resourcer = Resourcer.getInstance(); try { final StringBuilder buf = new StringBuilder("("); final boolean checkLength = PrintLow.controlPrintLength(); final int printLength = PrintLow.maxPrintLength(); int counter = 0; boolean terminatedEarly = false; iter = resourcer.acquireSubLListListIterator(this); while (iter.hasNext() && (!iter.isNextImproperElement())) { buf.append(iter.next()); if (checkLength) { counter++; if (counter >= printLength) { buf.append(" ... "); terminatedEarly = true; break; } } if (iter.hasNext()) { buf.append(" "); } } if (!terminatedEarly && iter.isNextImproperElement()) { buf.append(" . ").append(iter.getDottedElement()); } buf.append(")"); return buf.toString(); } finally { resourcer.releaseSubLListListIterator(iter); } } finally { PrintLow.maybeDecreasePrintLevel(oldLevel); } } else { return "( # )"; } }
public int hashCode(int currentDepth) { if (currentDepth < MAX_HASH_DEPTH) { SubLListListIterator iter = null; Resourcer resourcer = Resourcer.getInstance(); int hashCode = 0; try { int index = 0; iter = resourcer.acquireSubLListListIterator(this); while (iter.hasNext() && (!iter.isNextImproperElement()) && (index++ < MAX_HASH_LENGTH)) { hashCode ^= iter.nextSubLObject().hashCode(currentDepth + 1); index++; } if (iter.isNextImproperElement()) { hashCode ^= iter.getDottedElement().hashCode(currentDepth + 1); } return hashCode; } finally { resourcer.releaseSubLListListIterator(iter); } } else { return DEFAULT_EXCEEDED_HASH_VALUE; } }