Java朝花夕拾の实现Comparable接口 (二)

2014-11-24 07:23:24 · 作者: · 浏览: 1
nal int p1 = position.getParagraphIndex();
if (p0 != p1) {
return p0 < p1 -1 : 1;
}

final int e0 = getElementIndex();
final int e1 = position.getElementIndex();
if (e0 != e1) {
return e0 < e1 -1 : 1;
}

final int c0 = getCharIndex();
final int c1 = position.getCharIndex();
if (c0 != c1) {
return c0 < c1 -1 : 1;
}
return 0;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ZLTextPosition)) {
return false;
}

final ZLTextPosition position = (ZLTextPosition)obj;
return samePositionAs(position);
}

@Override
public int hashCode() {
return (getParagraphIndex() << 16) + (getElementIndex() << 8) + getCharIndex();
}

@Override
public String toString() {
return getClass().getName() + " " + getParagraphIndex() + " " + getElementIndex() + " " + getCharIndex();
}

}


摘自 ASCE1885