@Override public int compare(Node a, Node b) { int diff = a.type.ordinal() - b.type.ordinal(); if (diff != 0) return diff; switch (a.type) { case EMPTY: return 0; // All empty nodes are the same case TERM: return WritableComparator.compareBytes(text, a.start, a.end - a.start, text, b.start, b.end - b.start); case OR: case AND: diff = a.children.size() - b.children.size(); if (diff != 0) return diff; for (int i = 0; i < a.children.size(); i++) { diff = compare(a.children.get(i), b.children.get(i)); if (diff != 0) return diff; } } return 0; } }
@Override public int compare(Node a, Node b) { int diff = a.type.ordinal() - b.type.ordinal(); if (diff != 0) return diff; switch (a.type) { case EMPTY: return 0; // All empty nodes are the same case TERM: return WritableComparator.compareBytes(text, a.start, a.end - a.start, text, b.start, b.end - b.start); case OR: case AND: diff = a.children.size() - b.children.size(); if (diff != 0) return diff; for (int i = 0; i < a.children.size(); i++) { diff = compare(a.children.get(i), b.children.get(i)); if (diff != 0) return diff; } } return 0; } }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }