org.crosswire.jsword.passage
Class BitwisePassage

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

public class BitwisePassage
extends AbstractPassage

A Passage that is implemented using a BitSet - one for each verse. The attributes of the style are:

The BitSet has one more bit than the number of verses in the Bible. This would waste 1 bit per BitSet but since this doesn't cause BitSet to need an extra long it doesn't, and it saves us some maths.

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

Nested Class Summary
private  class BitwisePassage.VerseIterator
          Iterate over the Verses
 
Nested classes/interfaces inherited from class org.crosswire.jsword.passage.AbstractPassage
AbstractPassage.VerseRangeIterator
 
Field Summary
(package private) static long serialVersionUID
          To make serialization work across new versions
protected  BitSet store
          The place the real data is stored
 
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
protected BitwisePassage()
          Create an empty BitwisePassage.
protected BitwisePassage(String refs)
          Create a Verse from a human readable string.
 
Method Summary
 void add(Key obj)
          Add this Verse/VerseRange to this Passage
 void addAll(Key key)
          Adds the specified element to this set if it is not already present.
 void blur(int verses, RestrictionType restrict)
          Widen the range of the verses/keys in this list.
 void clear()
          Removes all of the elements from this set (optional operation).
 Object clone()
          Get a copy of ourselves.
 boolean contains(Key obj)
          Returns true if this set contains the specified element.
 int countVerses()
          Returns the number of verses in this collection.
 boolean isEmpty()
          Does this Passage have 0 members
 Iterator iterator()
           
 Iterator rangeIterator(RestrictionType restrict)
          Like verseElements() that iterates over VerseRanges instead of Verses.
private  void readObject(ObjectInputStream in)
          Call the support mechanism in AbstractPassage
 void remove(Key obj)
          Remove this Verse/VerseRange from this Passage
 void removeAll(Key key)
          Removes the specified elements from this set if it is present.
 void retainAll(Key key)
          Removes all but the specified element from this set.
private  void writeObject(ObjectOutputStream out)
          Call the support mechanism in AbstractPassage
 
Methods inherited from class org.crosswire.jsword.passage.AbstractPassage
addPassageListener, addVerses, booksInPassage, canHaveChildren, chaptersInPassage, compareTo, containsAll, countRanges, equals, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, get, getChildCount, getName, getName, getOsisID, getOsisRef, getOverview, getParent, getRangeAt, getVerseAt, hashCode, indexOf, lowerEventSuppresionAndTest, lowerNormalizeProtection, normalize, optimizeReads, optimizeWrites, raiseEventSuppresion, raiseNormalizeProtection, readDescription, readObjectSupport, removePassageListener, setParent, toString, toVerseRange, trimRanges, trimVerses, versesInPassage, writeDescription, writeObjectSupport
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
To make serialization work across new versions

See Also:
Constant Field Values

store

protected transient BitSet store
The place the real data is stored

Constructor Detail

BitwisePassage

protected BitwisePassage()
Create an empty BitwisePassage. There are no ctors from either Verse or VerseRange so you need to do new DistinctPassage().add(...);


BitwisePassage

protected BitwisePassage(String refs)
                  throws NoSuchVerseException
Create a Verse from a human readable string. The opposite of toString(), Given any BitwisePassage v1, and the following DistinctPassage v2 = new BitwisePassage(v1.toString()); Then v1.equals(v2); Theoretically, since there are many ways of representing a BitwisePassage as text string comparision along the lines of: v1.toString().equals(v2.toString()) could be false. Practically since toString() is standardized this will be true however. 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 BitwisePassage
Throws:
NoSuchVerseException - If the string is not parsable
Method Detail

clone

public Object clone()
Get a copy of ourselves. Points to note: Call clone() not new() on member Objects, and on us. Do not use Copy Constructors! - they do not inherit well. Think about this needing to be synchronized If this is not cloneable then writing cloneable children is harder

Specified by:
clone in interface Key
Overrides:
clone in class AbstractPassage
Returns:
A complete copy of ourselves

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 AbstractPassage
Returns:
the number of Verses in this collection
See Also:
Verse

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 AbstractPassage
Returns:
true if this set contains no elements.

iterator

public Iterator iterator()

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 AbstractPassage
Parameters:
restrict - Do we break ranges over chapters
Returns:
A list enumerator

contains

public boolean contains(Key obj)
Description copied from interface: Key
Returns true if this set contains the specified element.

Specified by:
contains in interface Key
Specified by:
contains in interface Passage
Overrides:
contains in class AbstractPassage
Parameters:
obj - element whose presence in this set is to be tested.
Returns:
true if this set contains the specified element.

add

public void add(Key obj)
Description copied from interface: Passage
Add this Verse/VerseRange to this Passage

Parameters:
obj - The Verses to be removed from this Passage

remove

public void remove(Key obj)
Description copied from interface: Passage
Remove this Verse/VerseRange from this Passage

Parameters:
obj - The Verses to be removed from this Passage

addAll

public void addAll(Key key)
Description copied from interface: Key
Adds the specified element to this set if it is not already present.

Specified by:
addAll in interface Key
Overrides:
addAll in class AbstractPassage
Parameters:
key - element to be added to this set.

removeAll

public void removeAll(Key key)
Description copied from interface: Key
Removes the specified elements from this set if it is present.

Specified by:
removeAll in interface Key
Overrides:
removeAll in class AbstractPassage
Parameters:
key - object to be removed from this set, if present.

retainAll

public void retainAll(Key key)
Description copied from interface: Key
Removes all but the specified element from this set.

Specified by:
retainAll in interface Key
Overrides:
retainAll in class AbstractPassage
Parameters:
key - object to be left in this set.

clear

public void clear()
Description copied from interface: Key
Removes all of the elements from this set (optional operation). This set will be empty after this call returns (unless it throws an exception).

Specified by:
clear in interface Key
Overrides:
clear in class AbstractPassage

blur

public void blur(int verses,
                 RestrictionType restrict)
Description copied from interface: Key
Widen the range of the verses/keys in this list. This is primarily for "find x within n verses of y" type applications.

Specified by:
blur in interface Key
Overrides:
blur in class AbstractPassage
Parameters:
verses - The number of verses/keys to widen by
restrict - How should we restrict the blurring?
See Also:
Passage

writeObject

private void writeObject(ObjectOutputStream out)
                  throws IOException
Call the support mechanism in AbstractPassage

Parameters:
out - The stream to write our state to
Throws:
IOException - if the read fails
See Also:
AbstractPassage.writeObjectSupport(ObjectOutputStream)

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Call the support mechanism in AbstractPassage

Parameters:
in - The stream to read our state from
Throws:
IOException - if the read fails
ClassNotFoundException - If the read data is incorrect
See Also:
AbstractPassage.readObjectSupport(ObjectInputStream)

Copyright ยจ 2003-2006