|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.jsword.passage.AbstractPassage
public abstract class AbstractPassage
This is a base class to help with some of the common implementation details of being a Passage.
Importantly, this class takes care of Serialization in a general yet optimized way. I think I am going to have a look at replacement here.
for license details.
The copyright to this program is held by it's authors.
,
Serialized FormNested Class Summary | |
---|---|
protected static class |
AbstractPassage.VerseRangeIterator
Skip over verses that are part of a range |
Field Summary | |
---|---|
protected static int |
BITWISE
Serialization type constant for a BitWise layout |
protected static int |
DISTINCT
Serialization type constant for a Distinct layout |
protected List |
listeners
Support for change notification |
private static Logger |
log
The log stream |
protected static int |
METHOD_COUNT
Count of serializations methods |
protected String |
originalName
The original string for picky users |
private Key |
parent
The parent key. |
protected static int |
RANGED
Serialization type constant for a Ranged layout |
static String |
REF_ALLOWED_DELIMS
What characters can we use to separate VerseRanges in a Passage |
static String |
REF_OSIS_DELIM
What characters should we use to separate VerseRanges in a Passage |
static String |
REF_PREF_DELIM
What characters should we use to separate VerseRanges in a Passage |
protected int |
skipNormalization
Do we skip normalization for now - if we want to skip then we increment this, and the decrement it when done. |
protected int |
suppressEvents
If we have several changes to make then we increment this and then decrement it when done (and fire an event off). |
Constructor Summary | |
---|---|
protected |
AbstractPassage()
Setup that leaves original name being null |
protected |
AbstractPassage(String original_name)
Setup the original name of this reference |
Method Summary | |
---|---|
void |
addAll(Key key)
Adds the specified element to this set if it is not already present. |
void |
addPassageListener(PassageListener li)
Event Listeners - Add Listener |
protected void |
addVerses(String refs)
Create a Passage from a human readable string. |
void |
blur(int verses,
RestrictionType restrict)
Widen the range of the verses/keys in this list. |
int |
booksInPassage()
How many books are there in this Passage |
boolean |
canHaveChildren()
Returns true if the receiver is a leaf node and can not have children. |
int |
chaptersInPassage(int book)
How many chapters are there in a particular book in this Passage |
void |
clear()
Removes all of the elements from this set (optional operation). |
Object |
clone()
This needs to be declared here so that it is visible as a method on a derived Key. |
int |
compareTo(Object obj)
|
boolean |
contains(Key key)
Returns true if this set contains the specified element. |
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. |
boolean |
equals(Object obj)
|
protected void |
fireContentsChanged(Object source,
Verse start,
Verse end)
AbstractPassage subclasses must call this method before one or more elements of the list are added. |
protected void |
fireIntervalAdded(Object source,
Verse start,
Verse end)
AbstractPassage subclasses must call this method after one or more elements of the list are added. |
protected void |
fireIntervalRemoved(Object source,
Verse start,
Verse end)
AbstractPassage subclasses must call this method before one or more elements of the list are added. |
Key |
get(int index)
Gets a key from a specific point in this list. |
int |
getChildCount()
Returns the number of elements in this set (its cardinality). |
String |
getName()
A Human readable version of the Key. |
String |
getName(Key base)
Translate the Key into a human readable string, with the assumption that the specified Key has just been output, so if we are in the same region, we do not need to display the region name, and so on. |
String |
getOsisID()
The OSIS defined id specification for this Key. |
String |
getOsisRef()
The OSIS defined reference specification for this Key. |
String |
getOverview()
A summary of the verses in this Passage For example "10 verses in 4 books" |
Key |
getParent()
All keys have parents unless they are the root of a Key. |
VerseRange |
getRangeAt(int offset,
RestrictionType restrict)
Get a specific VerseRange from this collection |
Verse |
getVerseAt(int offset)
Get a specific Verse from this collection |
int |
hashCode()
|
int |
indexOf(Key that)
Reverse a Key into the position the key holds in the list |
boolean |
isEmpty()
Does this Passage have 0 members |
boolean |
lowerEventSuppresionAndTest()
If things want to prevent event firing because they are doing a set of changes that should be notified in one go, they should call raiseEventSuppression() and when done call this. |
void |
lowerNormalizeProtection()
If things want to prevent normalization because they are doing a set of changes that should be normalized in one go, they should call raiseNormalizeProtection() and when done call this. |
protected void |
normalize()
We sometimes need to sort ourselves out ... |
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 |
void |
raiseEventSuppresion()
If things want to prevent event firing because they are doing a set of changes that should be notified in one go, this is what to call. |
void |
raiseNormalizeProtection()
If things want to prevent normalization because they are doing a set of changes that should be normalized in one go, this is what to call. |
Iterator |
rangeIterator(RestrictionType restrict)
Like verseElements() that iterates over VerseRanges instead of Verses. |
void |
readDescription(Reader in)
To be compatible with humans we read/write ourselves to a file that a human can read and even edit. |
protected void |
readObjectSupport(ObjectInputStream in)
Write out the object to the given ObjectOutputStream |
void |
removeAll(Key key)
Removes the specified elements from this set if it is present. |
void |
removePassageListener(PassageListener li)
Event Listeners - Remove Listener |
void |
retainAll(Key key)
Removes all but the specified element from this set. |
void |
setParent(Key parent)
Set a parent Key. |
String |
toString()
|
protected static VerseRange |
toVerseRange(Object base)
Convert the Object to a VerseRange. |
Passage |
trimRanges(int count,
RestrictionType restrict)
Ensures that there are a maximum of count VerseRanges
in this Passage. |
Passage |
trimVerses(int count)
Ensures that there are a maximum of count Verses in
this Passage. |
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() |
void |
writeDescription(Writer out)
To be compatible with humans we read/write ourselves to a file that a human can read and even edit. |
protected void |
writeObjectSupport(ObjectOutputStream out)
Write out the object to the given ObjectOutputStream. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.crosswire.jsword.passage.Passage |
---|
add, remove |
Methods inherited from interface org.crosswire.common.util.Iterable |
---|
iterator |
Field Detail |
---|
private static final Logger log
protected static final int BITWISE
protected static final int DISTINCT
protected static final int RANGED
protected static final int METHOD_COUNT
private transient Key parent
Key
protected transient List listeners
protected transient String originalName
protected transient int suppressEvents
protected transient int skipNormalization
public static final String REF_ALLOWED_DELIMS
public static final String REF_PREF_DELIM
public static final String REF_OSIS_DELIM
Constructor Detail |
---|
protected AbstractPassage()
protected AbstractPassage(String original_name)
original_name
- The text originally used to create this Passage.Method Detail |
---|
public int compareTo(Object obj)
compareTo
in interface Comparable
public Object clone()
Key
clone
in interface Key
clone
in class Object
public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String getName()
Key
getName
in interface Key
public String getName(Key base)
Key
getName
in interface Key
base
- The key to use to cut down unnecessary output.
public String getOsisRef()
Key
getOsisRef
in interface Key
public String getOsisID()
Key
getOsisID
in interface Key
public String toString()
toString
in class Object
public String getOverview()
Passage
getOverview
in interface Passage
public boolean isEmpty()
Key
isEmpty
in interface Key
public int countVerses()
Passage
countVerses
in interface Passage
Verse
public int countRanges(RestrictionType restrict)
Passage
countRanges
in interface Passage
restrict
- Do we break ranges at chapter/book boundries
VerseRange
public int booksInPassage()
Passage
booksInPassage
in interface Passage
public int chaptersInPassage(int book) throws NoSuchVerseException
Passage
chaptersInPassage
in interface Passage
book
- The book to check (0 for distinct chapters in all books)
NoSuchVerseException
- if the book is invalidpublic int versesInPassage(int book, int chapter) throws NoSuchVerseException
Passage
versesInPassage(ref, 0, 0) == ref.countVerses()
versesInPassage
in interface Passage
book
- The book to check (0 for distinct chapters in all books)chapter
- The chapter to check (0 for distinct verses in all chapters)
NoSuchVerseException
- if the book/chapter is invalidpublic Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException
Passage
getVerseAt
in interface Passage
offset
- The verse offset (legal values are 0 to countVerses()-1)
ArrayIndexOutOfBoundsException
- If the offset is out of rangepublic VerseRange getRangeAt(int offset, RestrictionType restrict) throws ArrayIndexOutOfBoundsException
Passage
getRangeAt
in interface Passage
offset
- The verse range offset (legal values are 0 to countRanges()-1)restrict
- Do we break ranges at chapter/book boundries
ArrayIndexOutOfBoundsException
- If the offset is out of rangepublic Iterator rangeIterator(RestrictionType restrict)
Passage
rangeIterator
in interface Passage
restrict
- Do we break ranges over chapters
public boolean containsAll(Passage that)
Passage
containsAll
in interface Passage
that
- Passage to be checked for containment in this collection.
public Passage trimVerses(int count)
Passage
count
Verses in
this Passage. If there were more than count
Verses
then a new Passage is created containing the Verses from
count
+1 onwards. If there was not greater than
count
in the Passage, then the passage remains
unchanged, and null is returned.
trimVerses
in interface Passage
count
- The maximum number of Verses to allow in this collection
Verse
public Passage trimRanges(int count, RestrictionType restrict)
Passage
count
VerseRanges
in this Passage. If there were more than count
VerseRanges then a new Passage is created containing the
VerseRanges from count
+1 onwards. If there was not
greater than count
in the Passage, then the passage
remains unchanged, and null is returned.
trimRanges
in interface Passage
count
- The maximum number of VerseRanges to allow in this collectionrestrict
- Do we break ranges at chapter/book boundries
VerseRange
public void addAll(Key key)
Key
addAll
in interface Key
key
- element to be added to this set.public void removeAll(Key key)
Key
removeAll
in interface Key
key
- object to be removed from this set, if present.public void retainAll(Key key)
Key
retainAll
in interface Key
key
- object to be left in this set.public void clear()
Key
clear
in interface Key
public void blur(int verses, RestrictionType restrict)
Key
blur
in interface Key
verses
- The number of verses/keys to widen byrestrict
- How should we restrict the blurring?Passage
public void writeDescription(Writer out) throws IOException
Passage
writeDescription
in interface Passage
out
- The stream to write to
IOException
- If the file/network etc breakspublic void readDescription(Reader in) throws IOException, NoSuchVerseException
Passage
readDescription
in interface Passage
in
- The stream to read from
IOException
- If the file/network etc breaks
NoSuchVerseException
- If the file was invalidpublic void optimizeReads()
Passage
optimizeReads
in interface Passage
protected void optimizeWrites()
public void addPassageListener(PassageListener li)
Passage
addPassageListener
in interface Passage
li
- The listener to addpublic void removePassageListener(PassageListener li)
Passage
removePassageListener
in interface Passage
li
- The listener to removepublic boolean contains(Key key)
Key
contains
in interface Key
contains
in interface Passage
key
- element whose presence in this set is to be tested.
public int getChildCount()
Key
getChildCount
in interface Key
public int indexOf(Key that)
Key
indexOf
in interface Key
that
- The Key to find
public boolean canHaveChildren()
Key
canHaveChildren
in interface Key
public Key get(int index)
Key
get
in interface Key
index
- The index of the Key to retrieve
public Key getParent()
Key
getParent
in interface Key
public void setParent(Key parent)
parent
- The parent Key for this verseprotected void fireIntervalAdded(Object source, Verse start, Verse end)
source
- The thing that changed, typically "this".start
- One end of the new interval.end
- The other end of the new interval.PassageListener
protected void fireIntervalRemoved(Object source, Verse start, Verse end)
source
- The thing that changed, typically "this".start
- One end of the new interval.end
- The other end of the new interval.PassageListener
protected void fireContentsChanged(Object source, Verse start, Verse end)
source
- The thing that changed, typically "this".start
- One end of the new interval.end
- The other end of the new interval.PassageListener
protected void addVerses(String refs) throws NoSuchVerseException
toString()
. Since this method is not public it
leaves control of suppress_events up to the people
that call it.
- Parameters:
refs
- A String containing the text of the RangedPassage
- Throws:
NoSuchVerseException
- if the string is invalid
protected void normalize()
public void raiseNormalizeProtection()
public void lowerNormalizeProtection()
public void raiseEventSuppresion()
public boolean lowerEventSuppresionAndTest()
protected static VerseRange toVerseRange(Object base) throws ClassCastException
base
- The object to be cast
ClassCastException
- If this is not a Verse or a VerseRangeprotected void writeObjectSupport(ObjectOutputStream out) throws IOException
out
- The stream to write our state to
IOException
- if the read failsprotected void readObjectSupport(ObjectInputStream in) throws IOException, ClassNotFoundException
in
- The stream to read our state from
IOException
- if the read fails
ClassNotFoundException
- If the read data is incorrect
|
Copyright ยจ 2003-2006 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |