public int indexOf(Key that) { int index = 0; for (Key key : this) { if (key.equals(that)) { return index; } index++; } return -1; }
@Override public boolean equals(Object obj) { return keys.equals(obj); }
/** how far down the page was the user - allows Back to go to correct line on non-Bible pages (Bibles use verse number for positioning) */ public float getCurrentYOffsetRatio() { try { // if key has changed then offsetRatio must be reset because user has changed page if (getKey()==null || !getKey().equals(keyWhenYOffsetRatioSet) || !getCurrentDocument().equals(docWhenYOffsetRatioSet)) { currentYOffsetRatio = 0; } } catch (Exception e) { // cope with occasional NPE thrown by above if statement // just pretend we are at the top of the page if error occurs currentYOffsetRatio = 0; Log.w(TAG, "NPE getting currentYOffsetRatio"); } return currentYOffsetRatio; } public void setCurrentYOffsetRatio(float currentYOffsetRatio) {
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; KeyHistoryItem other = (KeyHistoryItem) obj; if (document == null) { if (other.document != null) return false; } else if (document.getInitials() == null) { if (other.document.getInitials() != null) return false; } else if (!document.getInitials().equals(other.document.getInitials())) return false; if (key == null) { if (other.key != null) return false; } else if (!key.equals(other.key)) return false; return true; } }
/** equality is tricky if comparing TreeKeys (as used by GenBooks) because some child keys can have the same name but different parents */ @Override public boolean equals(Object obj) { // Since this can not be null if (obj == null) { return false; } // Check that that is the same as this // Don't use instanceOf since that breaks inheritance if (!obj.getClass().equals(this.getClass())) { return false; } TreeKey otherTreeKey = (TreeKey) obj; if (!getName().equals(otherTreeKey.getName())) { return false; } // names match so now work up the tree comparing parents if (getParent() == null) { return otherTreeKey.getParent() == null; } // KeyTrees nodes can have the same name but different parents return getParent().equals(otherTreeKey.getParent()); }