@Override public Object getElementAt(Passage ref, int index, RestrictionType restrict) { if (ref == null) { return null; } return ref.getVerseAt(index); }
public synchronized Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException { return ref.getVerseAt(offset); }
public Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException { return ref.getVerseAt(offset); }
/** * Cast a Key to a Verse. Only those keys that are a Verse or can * contain Verses (i.e. Passage and VerseRange) may be cast to one. * Verse containers (i.e. Passage and VerseRange) return their * first verse. * * @param key The key to cast * @return The key cast to a Verse * @throws ClassCastException */ public static Verse getVerse(Key key) { if (key instanceof Verse) { return (Verse) key; } if (key instanceof VerseRange) { VerseRange range = (VerseRange) key; return range.getStart(); } if (key instanceof Passage) { Passage ref = (Passage) key; return ref.getVerseAt(0); } throw new ClassCastException("Expected key to be a Verse, VerseRange or Passage"); }
@Override public void addAll(Key key) { //check for key empty. This avoids the AIOBounds with that.getVerseAt, during event firing if (key.isEmpty()) { //nothing to add return; } optimizeWrites(); if (key instanceof BitwisePassage) { BitwisePassage thatRef = (BitwisePassage) key; store.or(thatRef.store); } else { super.addAll(key); } // we do an extra check here because the cost of calculating the // params is non-zero and may be wasted if (suppressEvents == 0 && !key.isEmpty()) { if (key instanceof Passage) { Passage that = (Passage) key; fireIntervalAdded(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key; fireIntervalAdded(this, that.getStart(), that.getEnd()); } else if (key instanceof Verse) { Verse that = (Verse) key; fireIntervalAdded(this, that, that); } } }
if (key instanceof Passage) { Passage that = (Passage) key; fireIntervalRemoved(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key;
public int compareTo(Key obj) { Passage thatref = (Passage) obj; if (thatref.countVerses() == 0) { if (countVerses() == 0) { return 0; } // that is empty so he should come before me return -1; } if (countVerses() == 0) { // we are empty be he isn't so we are first return 1; } Verse thatfirst = thatref.getVerseAt(0); Verse thisfirst = getVerseAt(0); return getVersification().distance(thatfirst, thisfirst); }
@Override public void removeAll(Key key) { optimizeWrites(); if (key instanceof BitwisePassage) { BitwisePassage thatRef = (BitwisePassage) key; store.andNot(thatRef.store); } else { super.removeAll(key); } // we do an extra check here because the cost of calculating the // params is non-zero and may be wasted if (suppressEvents == 0 && !key.isEmpty()) { if (key instanceof Passage) { Passage that = (Passage) key; fireIntervalRemoved(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key; fireIntervalRemoved(this, that.getStart(), that.getEnd()); } else if (key instanceof Verse) { Verse that = (Verse) key; fireIntervalRemoved(this, that, that); } } }
if (key instanceof Passage) { Passage that = (Passage) key; fireIntervalAdded(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key;