|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.jsword.passage.Verse
public final class Verse
A Passage is a pointer to a single verse. Externally its unique
identifier is a String of the form "Gen 1:1" Internally we use
int[] { book, chapter, verse }
A Verse is designed to be immutable. This is a necessary from a collections point of view. A Verse should always be valid, although some versions may not return any text for verses that they consider to be mis-translated in some way.
Optimization information: I spent some time optimizing this class
because it is at the heart of things. My benchmark started st 11.25s.
By taking the int[] and turning it into 3 ints and it took 10.8s.
Cacheing the ordinal number just took the time from 12s to 12s! I guess
that the time and extra memory taken up by the extra int overrode the
time it saved by repeated queries to the same verse. I guess this would
change if we were using a [Ranged|Distinct]Passage instead of a Bitwise
Passage (as in the test). Maybe it would be a good idea to have an
extra class OrdCacheVerse (or something) that gave us the best of both
worlds?
Removing the default initialization of the ints took the time down by
about 0.25s also.
for license details.
The copyright to this program is held by it's authors.
,
Serialized FormNested Class Summary | |
---|---|
(package private) class |
Verse.VerseIterator
Iterator over 1 verse - For being a VerseBase. |
Field Summary | |
---|---|
private int |
book
The book number. |
private static int |
BOOK
To make the code more readible, the book is the first part of a int[] |
private int |
chapter
The chapter number |
private static int |
CHAPTER
To make the code more readible, the chapter is the second part of a int[] |
static Verse |
DEFAULT
The default verse |
private static Logger |
log
The log stream |
private String |
originalName
The original string for picky users |
private Key |
parent
The parent key. |
(package private) static long |
serialVersionUID
To make serialization work across new versions |
private int |
verse
The verse number |
private static int |
VERSE
To make the code more readible, the verse is the third part of a int[] |
static String |
VERSE_OSIS_DELIM
What characters should we use to separate parts of an OSIS verse reference |
static String |
VERSE_PREF_DELIM1
What characters should we use to separate the book from the chapter |
static String |
VERSE_PREF_DELIM2
What characters should we use to separate the chapter from the verse |
Constructor Summary | |
---|---|
Verse()
The default Verse is Genesis 1:1. |
|
Verse(int ordinal)
Set a Verse using a Verse Ordinal number - WARNING Do not use this method unless you really know the dangers of doing so. |
|
Verse(int book,
int chapter,
int verse)
Create a Verse from book, chapter and verse numbers, throwing up if the specified Verse does not exist. |
|
Verse(int book,
int chapter,
int verse,
boolean patch_up)
Create a Verse from book, chapter and verse numbers, patching up if the specified verse does not exist. |
|
Verse(String original,
int book,
int chapter,
int verse)
Create a Verse from book, chapter and verse numbers, throwing up if the specified Verse does not exist. |
Method Summary | |
---|---|
Verse |
add(int extra)
Get the verse that is a few verses on from the one we've got. |
void |
addAll(Key key)
Adds the specified element to this set if it is not already present. |
boolean |
adjacentTo(Verse that)
Is this verse adjacent to another verse |
void |
blur(int by,
RestrictionType restrict)
Widen the range of the verses/keys in this list. |
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). |
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 |
equals(Object obj)
This needs to be declared here so that it is visible as a method on a derived Key. |
Key |
get(int index)
Gets a key from a specific point in this list of children. |
int |
getBook()
Return the book that we refer to |
int |
getCardinality()
Returns the number of elements in this set (its cardinality). |
int |
getChapter()
Return the chapter that we refer to |
int |
getChildCount()
Returns the number of children that this node has. |
Verse |
getFirstVerseInBook()
Create a new Verse being the first verse in the current book |
Verse |
getFirstVerseInChapter()
Create a new Verse being the first verse in the current book |
Verse |
getLastVerseInBook()
Create a new Verse being the last verse in the current book |
Verse |
getLastVerseInChapter()
Create a new Verse being the last verse in the current book |
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. |
int |
getOrdinal()
Return the verse id that we refer to, where Gen 1:1 = 1, and Rev 22:21 = 31104 |
String |
getOsisID()
The OSIS defined id specification for this Key. |
String |
getOsisRef()
The OSIS defined reference specification for this Key. |
Key |
getParent()
All keys have parents unless they are the root of a Key. |
int[] |
getRefArray()
Return the verse that we refer to |
String |
getRootName()
A Human readable version of the Key's top level name. |
int |
getVerse()
Return the verse that we refer to |
int |
hashCode()
This needs to be declared here so that it is visible as a method on a derived Key. |
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 |
isEndOfBook()
Is this verse the first in a chapter |
boolean |
isEndOfChapter()
Is this verse the first in a chapter |
boolean |
isSameBook(Verse that)
Is this verse in the same book as that one |
boolean |
isSameChapter(Verse that)
Is this verse in the same chapter as that one |
boolean |
isStartOfBook()
Is this verse the first in a chapter |
boolean |
isStartOfChapter()
Is this verse the first in a chapter |
Iterator |
iterator()
|
static Verse |
max(Verse a,
Verse b)
Return the bigger of the 2 verses. |
static Verse |
min(Verse a,
Verse b)
Return the smaller of the 2 verses. |
protected static int |
parseInt(String text)
This is simply a convenience function to wrap Integer.parseInt() and give us a reasonable exception on failure. |
private void |
readObject(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 |
retainAll(Key key)
Removes all but the specified element from this set. |
private void |
set(int ordinal)
Set the references. |
private void |
set(int book,
int chapter,
int verse)
Verify and set the references. |
private void |
setAndPatch(int book,
int chapter,
int verse)
Mutate into this reference and fix the reference if needed. |
void |
setParent(Key parent)
Set a parent Key. |
Verse |
subtract(int n)
Get the verse n down from here this Verse. |
int |
subtract(Verse that)
How many verses are there in between the 2 Verses. |
String |
toString()
|
Verse[] |
toVerseArray()
Create an array of Verses |
private void |
writeObject(ObjectOutputStream out)
Write out the object to the given ObjectOutputStream |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final long serialVersionUID
private static final int BOOK
private static final int CHAPTER
private static final int VERSE
public static final String VERSE_OSIS_DELIM
public static final String VERSE_PREF_DELIM1
public static final String VERSE_PREF_DELIM2
public static final Verse DEFAULT
private transient Key parent
Key
private transient int book
private transient int chapter
private transient int verse
private transient String originalName
private static final Logger log
Constructor Detail |
---|
public Verse()
Verse(String original, int book, int chapter, int verse) throws NoSuchVerseException
original
- The original verse referencebook
- The book number (Genesis = 1)chapter
- The chapter numberverse
- The verse number
NoSuchVerseException
- If the reference is illegalpublic Verse(int book, int chapter, int verse) throws NoSuchVerseException
book
- The book number (Genesis = 1)chapter
- The chapter numberverse
- The verse number
NoSuchVerseException
- If the reference is illegalpublic Verse(int book, int chapter, int verse, boolean patch_up)
The actual value of the boolean is ignored. However for future
proofing you should only use 'true'. Do not use patch_up=false, use
Verse(int, int, int)
This so that we can declare this
constructor to not throw an exception. Is there a better way of
doing this?
book
- The book number (Genesis = 1)chapter
- The chapter numberverse
- The verse numberpatch_up
- True to trigger reference fixingpublic Verse(int ordinal) throws NoSuchVerseException
ordinal
- The verse id
NoSuchVerseException
- If the reference is illegalMethod Detail |
---|
public String toString()
toString
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 getRootName()
Key
getRootName
in interface Key
public String getOsisRef()
Key
getOsisRef
in interface Key
public String getOsisID()
Key
getOsisID
in interface Key
public Object clone()
Key
clone
in interface Key
clone
in class Object
public boolean equals(Object obj)
Key
equals
in interface Key
equals
in class Object
public int hashCode()
Key
hashCode
in interface Key
hashCode
in class Object
public int compareTo(Object obj)
compareTo
in interface Comparable
public boolean adjacentTo(Verse that)
that
- The thing to compare against
public int subtract(Verse that)
gen11.difference(gen12) == 1
that
- The Verse to compare this to
public Verse subtract(int n)
n
- The number to count down by
public Verse add(int extra)
extra
- the number of verses later than the one we're one
public int getBook()
public int getChapter()
public int getVerse()
public boolean isStartOfChapter()
public boolean isEndOfChapter()
public boolean isStartOfBook()
public boolean isEndOfBook()
public boolean isSameChapter(Verse that)
that
- The verse to compate to
public boolean isSameBook(Verse that)
that
- The verse to compate to
public int[] getRefArray()
public int getOrdinal()
public static Verse max(Verse a, Verse b)
a
- The first verse to compareb
- The second verse to compare
public static Verse min(Verse a, Verse b)
a
- The first verse to compareb
- The second verse to compare
public Verse[] toVerseArray()
public Verse getLastVerseInBook()
public Verse getLastVerseInChapter()
public Verse getFirstVerseInBook()
public Verse getFirstVerseInChapter()
public Key getParent()
Key
getParent
in interface Key
public void setParent(Key parent)
parent
- The parent Key for this verseprotected static int parseInt(String text) throws NoSuchVerseException
text
- The string to be parsed
NoSuchVerseException
- If the reference is illegalprivate void setAndPatch(int book, int chapter, int verse)
book
- The book to set (Genesis = 1)chapter
- The chapter to setverse
- The verse to setprivate void set(int book, int chapter, int verse) throws NoSuchVerseException
book
- The book to set (Genesis = 1)chapter
- The chapter to setverse
- The verse to set
NoSuchVerseException
- If the verse can not be understoodprivate void set(int ordinal) throws NoSuchVerseException
ordinal
- The ordinal of the verse
NoSuchVerseException
- If the verse can not be understoodprivate void writeObject(ObjectOutputStream out) throws IOException
out
- The stream to write our state to
IOException
- if the read failsprivate void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
in
- The stream to read our state from
IOException
- if the read fails
ClassNotFoundException
- If the read data is incorrectpublic boolean canHaveChildren()
Key
canHaveChildren
in interface Key
public int getChildCount()
Key
getChildCount
in interface Key
public int getCardinality()
Key
getCardinality
in interface Key
public boolean isEmpty()
Key
isEmpty
in interface Key
public boolean contains(Key key)
Key
contains
in interface Key
key
- element whose presence in this set is to be tested.
public Iterator iterator()
iterator
in interface Iterable
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 Key get(int index)
Key
get
in interface Key
index
- The index of the Key to retrieve
public int indexOf(Key that)
Key
indexOf
in interface Key
that
- The Key to find
public void blur(int by, RestrictionType restrict)
Key
blur
in interface Key
by
- The number of verses/keys to widen byrestrict
- How should we restrict the blurring?Passage
|
Copyright ยจ 2003-2007 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |