org.crosswire.jsword.passage
Class RocketPassage

java.lang.Object
  extended by org.crosswire.jsword.passage.AbstractPassage
      extended by org.crosswire.jsword.passage.BitwisePassage
          extended by org.crosswire.jsword.passage.RocketPassage
All Implemented Interfaces:
Serializable, Cloneable, Comparable, Iterable, Key, Passage

public class RocketPassage
extends BitwisePassage

A RocketPassage is a bit and heavy implementation of Passage that goes fairly quickly once let of the leash. It manages its speed by creating contained instances of DistinctPassage and RangedPassage and selects the fastest implementation for each fo its methods from the 3 available.

Author:
Joe Walker [joe at eireneh dot com]
See Also:
for license details. The copyright to this program is held by it's authors., Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.crosswire.jsword.passage.AbstractPassage
AbstractPassage.VerseRangeIterator
 
Field Summary
private  DistinctPassage distinct
          The contained DistinctPassage
private  RangedPassage ranged
          The contained RangedPassage
private static long serialVersionUID
          Serialization ID
 
Fields inherited from class org.crosswire.jsword.passage.BitwisePassage
store
 
Fields inherited from class org.crosswire.jsword.passage.AbstractPassage
BITWISE, DISTINCT, listeners, METHOD_COUNT, originalName, RANGED, REF_ALLOWED_DELIMS, REF_OSIS_DELIM, REF_PREF_DELIM, skipNormalization, suppressEvents
 
Constructor Summary
  RocketPassage()
          Create a new RocketPassage
protected RocketPassage(String refs)
          Create a Verse from a human readable string.
 
Method Summary
 int booksInPassage()
          How many books are there in this Passage
 int chaptersInPassage(int book)
          How many chapters are there in a particular book in this Passage
 boolean containsAll(Passage that)
          Returns true if this Passage contains all of the verses in that Passage
 int countRanges(RestrictionType restrict)
          Like countVerses() that counts VerseRanges instead of Verses Returns the number of fragments in this collection.
 int countVerses()
          Returns the number of verses in this collection.
 VerseRange getRangeAt(int offset, RestrictionType restrict)
          Get a specific VerseRange from this collection
 Verse getVerseAt(int offset)
          Get a specific Verse from this collection
 boolean isEmpty()
          Does this Passage have 0 members
 Iterator iterator()
           
 void optimizeReads()
          For preformance reasons we may well want to hint to the Passage that we have done editing it for now and that it is safe to cache certain values to speed up future reads.
protected  void optimizeWrites()
          Simple method to instruct children to stop caching results
 Iterator rangeIterator(RestrictionType restrict)
          Like verseElements() that iterates over VerseRanges instead of Verses.
 int versesInPassage(int book, int chapter)
          How many chapters are there in a particular book in this Passage Note that versesInPassage(ref, 0, 0) == ref.countVerses()
 
Methods inherited from class org.crosswire.jsword.passage.BitwisePassage
add, addAll, blur, clear, clone, contains, remove, removeAll, retainAll
 
Methods inherited from class org.crosswire.jsword.passage.AbstractPassage
addPassageListener, addVerses, canHaveChildren, compareTo, equals, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, get, getChildCount, getName, getName, getOsisID, getOsisRef, getOverview, getParent, hashCode, indexOf, lowerEventSuppresionAndTest, lowerNormalizeProtection, normalize, raiseEventSuppresion, raiseNormalizeProtection, readDescription, readObjectSupport, removePassageListener, setParent, toString, toVerseRange, trimRanges, trimVerses, writeDescription, writeObjectSupport
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

distinct

private transient DistinctPassage distinct
The contained DistinctPassage


ranged

private transient RangedPassage ranged
The contained RangedPassage


serialVersionUID

private static final long serialVersionUID
Serialization ID

See Also:
Constant Field Values
Constructor Detail

RocketPassage

public RocketPassage()
Create a new RocketPassage


RocketPassage

protected RocketPassage(String refs)
                 throws NoSuchVerseException
Create a Verse from a human readable string. The opposite of getName(), Given any RangedPassage v1, and the following RangedPassage v2 = new RangedPassage(v1.getName()); Then v1.equals(v2); Theoretically, since there are many ways of representing a RangedPassage as text string comparision along the lines of: v1.getName().equals(v2.getName()) could be false. However since getName() is standardized this will be true. We don't need to worry about thread safety in a ctor since we don't exist yet.

Parameters:
refs - A String containing the text of the RangedPassage
Throws:
NoSuchVerseException - if refs is invalid
Method Detail

optimizeReads

public void optimizeReads()
For preformance reasons we may well want to hint to the Passage that we have done editing it for now and that it is safe to cache certain values to speed up future reads. Any action taken by this method will be undone simply by making a future edit, and the only loss in calling optimizeReads() is a loss of time if you then persist in writing to the Passage.

Specified by:
optimizeReads in interface Passage
Overrides:
optimizeReads in class AbstractPassage

optimizeWrites

protected void optimizeWrites()
Description copied from class: AbstractPassage
Simple method to instruct children to stop caching results

Overrides:
optimizeWrites in class AbstractPassage

countRanges

public int countRanges(RestrictionType restrict)
Description copied from interface: Passage
Like countVerses() that counts VerseRanges instead of Verses Returns the number of fragments in this collection. This does not mean the Passage needs to use VerseRanges, just that it understands the concept.

Specified by:
countRanges in interface Passage
Overrides:
countRanges in class AbstractPassage
Parameters:
restrict - Do we break ranges at chapter/book boundries
Returns:
the number of VerseRanges in this collection
See Also:
VerseRange

countVerses

public int countVerses()
Description copied from interface: Passage
Returns the number of verses in this collection. Like Collection.size() This does not mean the Passage needs to use Verses, just that it understands the concept.

Specified by:
countVerses in interface Passage
Overrides:
countVerses in class BitwisePassage
Returns:
the number of Verses in this collection
See Also:
Verse

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Overrides:
iterator in class BitwisePassage

rangeIterator

public Iterator rangeIterator(RestrictionType restrict)
Description copied from interface: Passage
Like verseElements() that iterates over VerseRanges instead of Verses. Exactly the same data will be traversed, however using rangeIterator() will usually give less iterations (and never more)

Specified by:
rangeIterator in interface Passage
Overrides:
rangeIterator in class BitwisePassage
Parameters:
restrict - Do we break ranges over chapters
Returns:
A list enumerator

isEmpty

public boolean isEmpty()
Description copied from interface: Key
Does this Passage have 0 members

Specified by:
isEmpty in interface Key
Overrides:
isEmpty in class BitwisePassage
Returns:
true if this set contains no elements.

getVerseAt

public Verse getVerseAt(int offset)
                 throws ArrayIndexOutOfBoundsException
Description copied from interface: Passage
Get a specific Verse from this collection

Specified by:
getVerseAt in interface Passage
Overrides:
getVerseAt in class AbstractPassage
Parameters:
offset - The verse offset (legal values are 0 to countVerses()-1)
Returns:
The Verse
Throws:
ArrayIndexOutOfBoundsException - If the offset is out of range

getRangeAt

public VerseRange getRangeAt(int offset,
                             RestrictionType restrict)
                      throws ArrayIndexOutOfBoundsException
Description copied from interface: Passage
Get a specific VerseRange from this collection

Specified by:
getRangeAt in interface Passage
Overrides:
getRangeAt in class AbstractPassage
Parameters:
offset - The verse range offset (legal values are 0 to countRanges()-1)
restrict - Do we break ranges at chapter/book boundries
Returns:
The Verse Range
Throws:
ArrayIndexOutOfBoundsException - If the offset is out of range

booksInPassage

public int booksInPassage()
Description copied from interface: Passage
How many books are there in this Passage

Specified by:
booksInPassage in interface Passage
Overrides:
booksInPassage in class AbstractPassage
Returns:
The number of distinct books

chaptersInPassage

public int chaptersInPassage(int book)
                      throws NoSuchVerseException
Description copied from interface: Passage
How many chapters are there in a particular book in this Passage

Specified by:
chaptersInPassage in interface Passage
Overrides:
chaptersInPassage in class AbstractPassage
Parameters:
book - The book to check (0 for distinct chapters in all books)
Returns:
The number of distinct chapters
Throws:
NoSuchVerseException - if the book is invalid

versesInPassage

public int versesInPassage(int book,
                           int chapter)
                    throws NoSuchVerseException
Description copied from interface: Passage
How many chapters are there in a particular book in this Passage Note that versesInPassage(ref, 0, 0) == ref.countVerses()

Specified by:
versesInPassage in interface Passage
Overrides:
versesInPassage in class AbstractPassage
Parameters:
book - The book to check (0 for distinct chapters in all books)
chapter - The chapter to check (0 for distinct verses in all chapters)
Returns:
The number of distinct chapters
Throws:
NoSuchVerseException - if the book/chapter is invalid

containsAll

public boolean containsAll(Passage that)
Description copied from interface: Passage
Returns true if this Passage contains all of the verses in that Passage

Specified by:
containsAll in interface Passage
Overrides:
containsAll in class AbstractPassage
Parameters:
that - Passage to be checked for containment in this collection.
Returns:
true if this reference contains all of the Verses in that Passage

Copyright ยจ 2003-2006