public abstract class AbstractPassage extends Object implements 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.
The GNU Lesser General Public License for details.,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractPassage.VerseRangeIterator
Skip over verses that are part of a range
|
| Modifier and Type | Field and Description |
|---|---|
protected static int |
BITWISE
Serialization type constant for a BitWise layout
|
protected static int |
DISTINCT
Serialization type constant for a Distinct layout
|
protected List<PassageListener> |
listeners
Support for change notification
|
private static org.slf4j.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
|
private static long |
serialVersionUID
Serialization ID
|
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).
|
private Versification |
v11n
The Versification to which this passage belongs.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractPassage(Versification v11n)
Setup that leaves original name being null
|
protected |
AbstractPassage(Versification v11n,
String passageName)
Setup the original name of this reference
|
| Modifier and Type | Method and Description |
|---|---|
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,
Key basis)
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 false if the receiver is a leaf node and can not have children.
|
void |
clear()
Removes all of the elements from this set (optional operation).
|
AbstractPassage |
clone()
This needs to be declared here so that it is visible as a method on a
derived Key.
|
int |
compareTo(Key obj) |
boolean |
contains(Key key)
Returns true if this collection contains all the specified Verse
|
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)
This needs to be declared here so that it is visible as a method on a
derived Key.
|
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 of children.
|
int |
getCardinality()
Returns the number of elements in this set (its cardinality).
|
int |
getChildCount()
Returns the number of children that this node has.
|
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
|
String |
getRootName()
A Human readable version of the Key's top level name.
|
Verse |
getVerseAt(int offset)
Get a specific Verse from this collection
|
Versification |
getVersification()
Get the Versification that defines the Verses in this VerseKey.
|
Passage |
getWhole()
Convert this reference into one without a sub-identifier.
|
int |
hashCode()
This needs to be declared here so that it is visible as a method on a
derived Key.
|
boolean |
hasRanges(RestrictionType restrict)
Determine whether there are two or more ranges.
|
int |
indexOf(Key that)
Reverse a Key into the position the key holds in the list of children
|
boolean |
isEmpty()
Does this Key have 0 members
|
boolean |
isWhole()
A VerseKey that does not have an OSIS sub identifier is a whole reference.
|
boolean |
lowerEventSuppressionAndTest()
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.
|
(package private) void |
normalize()
We sometimes need to sort ourselves out ...
|
void |
optimizeReads()
For performance 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<VerseRange> |
rangeIterator(RestrictionType restrict)
Like iterator() 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.
|
private void |
readObject(ObjectInputStream is)
Serialization support.
|
protected void |
readObjectSupport(ObjectInputStream is)
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.
|
Passage |
reversify(Versification newVersification)
Cast this VerseKey into another Versification.
|
void |
setParent(Key parent)
Set a parent Key.
|
String |
toString() |
protected static VerseRange |
toVerseRange(Versification v11n,
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. |
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.
|
private static final org.slf4j.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 Versification v11n
private transient Key parent
Keyprotected transient List<PassageListener> 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
private static final long serialVersionUID
protected AbstractPassage(Versification v11n)
v11n - The Versification to which this Passage belongs.protected AbstractPassage(Versification v11n, String passageName)
v11n - The Versification to which this Passage belongs.passageName - The text originally used to create this Passage.public Versification getVersification()
VerseKeygetVersification in interface VerseKey<Passage>public Passage reversify(Versification newVersification)
VerseKeyNote: This is dangerous as it does not consider chapter boundaries or whether the verses in this VerseKey are actually part of the new versification. It should only be used when the start and end verses are in both Versifications. You have been warned.
public boolean isWhole()
VerseKeypublic Passage getWhole()
VerseKeypublic int compareTo(Key obj)
compareTo in interface Comparable<Key>public AbstractPassage clone()
Keypublic boolean equals(Object obj)
Keypublic int hashCode()
Keypublic String getName()
Keypublic String getName(Key base)
Keypublic String getRootName()
KeygetRootName in interface Keypublic String getOsisRef()
KeygetOsisRef in interface Keypublic String getOsisID()
Keypublic String getOverview()
PassagegetOverview in interface Passagepublic boolean isEmpty()
Keypublic int countVerses()
PassagecountVerses in interface PassageVersepublic boolean hasRanges(RestrictionType restrict)
PassagehasRanges in interface Passagerestrict - Do we break ranges at chapter/book boundariesVerseRangepublic int countRanges(RestrictionType restrict)
PassagecountRanges in interface Passagerestrict - Do we break ranges at chapter/book boundariesVerseRangepublic int booksInPassage()
PassagebooksInPassage in interface Passagepublic Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException
PassagegetVerseAt in interface Passageoffset - 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
PassagegetRangeAt in interface Passageoffset - The verse range offset (legal values are 0 to countRanges()-1)restrict - Do we break ranges at chapter/book boundariesArrayIndexOutOfBoundsException - If the offset is out of rangepublic Iterator<VerseRange> rangeIterator(RestrictionType restrict)
PassagerangeIterator in interface Passagerestrict - Do we break ranges over chapterspublic boolean containsAll(Passage that)
PassagecontainsAll in interface Passagethat - Passage to be checked for containment in this collection.public Passage trimVerses(int count)
Passagecount 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 Passagecount - The maximum number of Verses to allow in this collectionVersepublic Passage trimRanges(int count, RestrictionType restrict)
Passagecount 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 Passagecount - The maximum number of VerseRanges to allow in this collectionrestrict - Do we break ranges at chapter/book boundariesVerseRangepublic void addAll(Key key)
Keypublic void removeAll(Key key)
Keypublic void retainAll(Key key)
Keypublic void clear()
Keypublic void blur(int verses,
RestrictionType restrict)
Keypublic void writeDescription(Writer out) throws IOException
PassagewriteDescription in interface Passageout - The stream to write toIOException - If the file/network etc breakspublic void readDescription(Reader in) throws IOException, NoSuchVerseException
PassagereadDescription in interface Passagein - The stream to read fromIOException - If the file/network etc breaksNoSuchVerseException - If the file was invalidpublic void optimizeReads()
PassageoptimizeReads in interface Passageprotected void optimizeWrites()
public void addPassageListener(PassageListener li)
PassageaddPassageListener in interface Passageli - The listener to addpublic void removePassageListener(PassageListener li)
PassageremovePassageListener in interface Passageli - The listener to removepublic boolean contains(Key key)
Passagepublic int getCardinality()
KeyThis method is potentially expensive, as it often requires cycling through all the keys in the set.
getCardinality in interface Keypublic int indexOf(Key that)
Keypublic boolean canHaveChildren()
KeycanHaveChildren in interface Keypublic int getChildCount()
KeygetChildCount in interface Keypublic Key get(int index)
Keypublic Key getParent()
Keypublic 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.PassageListenerprotected 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.PassageListenerprotected 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.PassageListenerprotected void addVerses(String refs, Key basis) throws NoSuchVerseException
toString(). Since this method is not public it leaves
control of suppress_events up to the people
that call it.refs - A String containing the text of the RangedPassagebasis - The basis for understanding refsNoSuchVerseException - if the string is invalidvoid normalize()
public void raiseNormalizeProtection()
public void lowerNormalizeProtection()
public void raiseEventSuppresion()
public boolean lowerEventSuppressionAndTest()
protected static VerseRange toVerseRange(Versification v11n, Object base) throws ClassCastException
base - The object to be castClassCastException - If this is not a Verse or a VerseRangeprotected void writeObjectSupport(ObjectOutputStream out) throws IOException
out - The stream to write our state toIOException - if the read failsprivate void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException
is - IOExceptionClassNotFoundExceptionprotected void readObjectSupport(ObjectInputStream is) throws IOException, ClassNotFoundException
is - The stream to read our state fromIOException - if the read failsClassNotFoundException - If the read data is incorrect