|
|||||||||
| Home >> All >> com >> eireneh >> bible >> [ passage overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.eireneh.bible.passage
Class Verse

java.lang.Objectcom.eireneh.bible.passage.Verse
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Comparable, PassageConstants, java.io.Serializable, VerseBase
- public class Verse
- extends java.lang.Object
- implements VerseBase
- extends java.lang.Object
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.
|
Distribution Licence: Project B is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The License is available on the internet here, by writing to Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, Or locally at the Licence link below. The copyright to this program is held by it's authors. |
- Version:
- D9.I9.T7
| 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[] |
protected static Verse |
DEFAULT
The default verse |
protected static com.eireneh.util.Logger |
log
The log stream |
private java.lang.String |
original_name
The original string for picky users |
(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[] |
| Fields inherited from interface com.eireneh.bible.passage.PassageConstants |
ACCURACY_BOOK_CHAPTER, ACCURACY_BOOK_ONLY, ACCURACY_BOOK_VERSE, ACCURACY_CHAPTER_VERSE, ACCURACY_NONE, ACCURACY_VERSE_ONLY, CASE_LOWER, CASE_MIXED, CASE_SENTANCE, CASE_UPPER, CASES, RANGE_ALLOWED_DELIMS, RANGE_PREF_DELIM, REF_ALLOWED_DELIMS, REF_PREF_DELIM, RESTRICT_BOOK, RESTRICT_CHAPTER, RESTRICT_NONE, RESTRICTIONS, VERSE_ALLOWED_DELIMS, VERSE_END_MARK1, VERSE_END_MARK2, VERSE_NUMERIC_BOOK, VERSE_PREF_DELIM1, VERSE_PREF_DELIM2 |
| 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(java.lang.String desc)
Construct a Verse from a String - something like "Gen 1:1". |
|
Verse(java.lang.String desc,
Verse basis)
Construct a Ref from a String and a Verse. |
|
| Method Summary | |
Verse |
add(int extra)
Get the verse that is a few verses on from the one we've got. |
boolean |
adjacentTo(Verse that)
Is this verse adjacent to another verse |
private static void |
checkValidChapterOrVerse(java.lang.String text)
Is this text valid in a chapter/verse context |
java.lang.Object |
clone()
Get a copy of ourselves. |
int |
compareTo(java.lang.Object obj)
Compare this to a given object |
boolean |
equals(java.lang.Object obj)
Is this Object equal to us. |
static int |
getAccuracy(java.lang.String desc)
Does this string exactly define a Verse. |
private static int |
getAccuracy(java.lang.String[] parts)
Does this string exactly define a Verse. |
int |
getBook()
Return the book that we refer to |
int |
getChapter()
Return the chapter that we refer to |
java.lang.String |
getName()
Translate the Passage into a human readable string |
java.lang.String |
getName(Verse base)
Translate the Passage into a human readable string |
int |
getOrdinal()
Return the verse id that we refer to, where Gen 1:1 = 1, and Rev 22:21 = 31104 |
int[] |
getRefArray()
Return the verse that we refer to |
int |
getVerse()
Return the verse that we refer to |
int |
hashCode()
This returns the ordinal number of the verse so new Verse("Rev 22:21").hashCode() = 31104
|
static boolean |
isEndMarker(java.lang.String text)
Is this string a legal marker for 'to the end of the chapter' |
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 |
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(java.lang.String text)
This is simply a convenience function to wrap Integer.parseInt() and give us a reasonable exception on failure. |
private void |
readObject(java.io.ObjectInputStream in)
Write out the object to the given ObjectOutputStream |
private void |
set(int ordinal)
Set the references. |
private void |
set(int[] ref)
Set the references. |
private void |
set(int book,
int chapter,
int verse)
Verify and set the references. |
private void |
set(int book,
int chapter,
java.lang.String verse_str)
Verify and set the references. |
private void |
set(int book,
java.lang.String chapter_str,
java.lang.String verse_str)
Verify and set the references. |
private void |
set(java.lang.String book_str,
int chapter,
int verse)
Verify and set the references. |
private void |
set(java.lang.String book_str,
int chapter,
java.lang.String verse_str)
Verify and set the references. |
private void |
set(java.lang.String book_str,
java.lang.String chapter_str,
int verse)
Verify and set the references. |
private void |
set(java.lang.String book_str,
java.lang.String chapter_str,
java.lang.String verse_str)
Verify and set the references. |
private void |
setAndPatch(int[] ref)
Mutate into this reference and fix the reference if needed. |
private void |
setAndPatch(int book,
int chapter,
int verse)
Mutate into this reference and fix the reference if needed. |
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. |
private static java.lang.String[] |
tokenize(java.lang.String command,
java.lang.String delim)
Take a string and parse it into an Array of Strings where each part is likely to be a verse part (book, chapter, verse, ...) |
java.lang.String |
toString()
Translate the Passage into a human readable string. |
Verse[] |
toVerseArray()
Create an array of Verses |
java.util.Enumeration |
verseElements()
Enumerate over the verse in this verse! This may seem silly, however is is very useful to be able to treat Verses and Ranges the same (VerseBase) and this is a common accessor. |
private void |
writeObject(java.io.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 |
serialVersionUID
static final long serialVersionUID
- To make serialization work across new versions
- See Also:
- Constant Field Values
BOOK
private static final int BOOK
- To make the code more readible, the book is the first part of a int[]
- See Also:
- Constant Field Values
CHAPTER
private static final int CHAPTER
- To make the code more readible, the chapter is the second part of a int[]
- See Also:
- Constant Field Values
VERSE
private static final int VERSE
- To make the code more readible, the verse is the third part of a int[]
- See Also:
- Constant Field Values
DEFAULT
protected static final Verse DEFAULT
- The default verse
book
private transient int book
- The book number. Genesis=1
chapter
private transient int chapter
- The chapter number
verse
private transient int verse
- The verse number
original_name
private transient java.lang.String original_name
- The original string for picky users
log
protected static com.eireneh.util.Logger log
- The log stream
| Constructor Detail |
Verse
public Verse()
- The default Verse is Genesis 1:1. I didn't want to provide this
constructor however, you are supposed to provide a default ctor
for all beans. For this reason I suggest you don't use it.
Verse
public Verse(java.lang.String desc) throws NoSuchVerseException
- Construct a Verse from a String - something like "Gen 1:1".
in case the user does not want to have their typing 'fixed' by a
meddling patronizing computer. The following initial letters can
not be matched at all - 'bfquvwx'.
Verse
public Verse(java.lang.String desc, Verse basis) throws NoSuchVerseException
- Construct a Ref from a String and a Verse. For example given "2:2"
and a basis of Gen 1:1 the result would be Gen 2:2
Verse
public Verse(int book,
int chapter,
int verse)
throws NoSuchVerseException
- Create a Verse from book, chapter and verse numbers, throwing up
if the specified Verse does not exist
Verse
public 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.
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?
Verse
public Verse(int ordinal)
throws NoSuchVerseException
- Set a Verse using a Verse Ordinal number - WARNING Do not use this
method unless you really know the dangers of doing so. Ordinals are
not always going to be the same. So you should use a Verse or an
int[3] in preference to an int ordinal whenever possible. Ordinal
numbers are 1 based and not 0 based.
| Method Detail |
toString
public java.lang.String toString()
- Translate the Passage into a human readable string. This is
simply an alias for getName();
getName
public java.lang.String getName()
getName
public java.lang.String getName(Verse base)
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- 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
equals
public boolean equals(java.lang.Object obj)
- Is this Object equal to us. Points to note:
If you override equals(), you must override hashCode() too.
If you are doing this it is a good idea to be immutable.
hashCode
public int hashCode()
- This returns the ordinal number of the verse
so
new Verse("Rev 22:21").hashCode() = 31104However should should not reply on this being true
compareTo
public int compareTo(java.lang.Object obj)
- Compare this to a given object
- Specified by:
compareToin interfacejava.lang.Comparable
adjacentTo
public boolean adjacentTo(Verse that)
- Is this verse adjacent to another verse
subtract
public int subtract(Verse that)
- How many verses are there in between the 2 Verses.
The answer is -ve if that is bigger than this.
The answer is inclusive of that and exclusive of this, so that
gen11.difference(gen12) == 1
subtract
public Verse subtract(int n)
- Get the verse n down from here this Verse.
add
public Verse add(int extra)
- Get the verse that is a few verses on from the one
we've got.
getBook
public int getBook()
- Return the book that we refer to
getChapter
public int getChapter()
- Return the chapter that we refer to
getVerse
public int getVerse()
- Return the verse that we refer to
isStartOfChapter
public boolean isStartOfChapter()
- Is this verse the first in a chapter
isEndOfChapter
public boolean isEndOfChapter()
- Is this verse the first in a chapter
isStartOfBook
public boolean isStartOfBook()
- Is this verse the first in a chapter
isEndOfBook
public boolean isEndOfBook()
- Is this verse the first in a chapter
isSameChapter
public boolean isSameChapter(Verse that)
- Is this verse in the same chapter as that one
isSameBook
public boolean isSameBook(Verse that)
- Is this verse in the same book as that one
getRefArray
public int[] getRefArray()
- Return the verse that we refer to
getOrdinal
public int getOrdinal()
- Return the verse id that we refer to, where Gen 1:1 = 1, and
Rev 22:21 = 31104
getAccuracy
public static int getAccuracy(java.lang.String desc) throws NoSuchVerseException
- Does this string exactly define a Verse. For example:
- getAccuracy("Gen") == ACCURACY_BOOK_ONLY;
- getAccuracy("Gen 1:1") == ACCURACY_BOOK_VERSE;
- getAccuracy("Gen 1") == ACCURACY_BOOK_CHAPTER;
- getAccuracy("Jude 1") == ACCURACY_BOOK_VERSE;
- getAccuracy("Jude 1:1") == ACCURACY_BOOK_VERSE;
- getAccuracy("1:1") == ACCURACY_CHAPTER_VERSE;
- getAccuracy("1") == ACCURACY_VERSE_ONLY;
- getAccuracy("") == ACCURACY_NONE;
getAccuracy
private static int getAccuracy(java.lang.String[] parts) throws NoSuchVerseException
- Does this string exactly define a Verse. For example:
- getAccuracy("Gen") == ACCURACY_BOOK_ONLY;
- getAccuracy("Gen 1:1") == ACCURACY_BOOK_VERSE;
- getAccuracy("Gen 1") == ACCURACY_BOOK_CHAPTER;
- getAccuracy("Jude 1") == ACCURACY_BOOK_VERSE;
- getAccuracy("Jude 1:1") == ACCURACY_BOOK_VERSE;
- getAccuracy("1:1") == ACCURACY_CHAPTER_VERSE;
- getAccuracy("1") == ACCURACY_VERSE_ONLY;
- getAccuracy("") == ACCURACY_NONE;
checkValidChapterOrVerse
private static final void checkValidChapterOrVerse(java.lang.String text) throws NoSuchVerseException
- Is this text valid in a chapter/verse context
max
public static final Verse max(Verse a, Verse b)
- Return the bigger of the 2 verses. If the verses are equal()
then return Verse a
min
public static final Verse min(Verse a, Verse b)
- Return the smaller of the 2 verses. If the verses are equal()
then return Verse a
isEndMarker
public static boolean isEndMarker(java.lang.String text)
- Is this string a legal marker for 'to the end of the chapter'
toVerseArray
public Verse[] toVerseArray()
- Create an array of Verses
- Specified by:
toVerseArrayin interfaceVerseBase
verseElements
public java.util.Enumeration verseElements()
- Enumerate over the verse in this verse! This may seem silly,
however is is very useful to be able to treat Verses and Ranges
the same (VerseBase) and this is a common accessor.
- Specified by:
verseElementsin interfaceVerseBase
tokenize
private static java.lang.String[] tokenize(java.lang.String command, java.lang.String delim)
- Take a string and parse it into an Array of Strings where each
part is likely to be a verse part (book, chapter, verse, ...)
parseInt
protected static int parseInt(java.lang.String text) throws NoSuchVerseException
- This is simply a convenience function to wrap Integer.parseInt()
and give us a reasonable exception on failure. It is called by
VerseRange hence protected, however I would prefer private
setAndPatch
private final void setAndPatch(int book,
int chapter,
int verse)
- Mutate into this reference and fix the reference if needed.
This nust only be called from a ctor to maintain immutability
setAndPatch
private final void setAndPatch(int[] ref)
- Mutate into this reference and fix the reference if needed.
This must only be called from a ctor to maintain immutability
set
private final void set(java.lang.String book_str, int chapter, int verse) throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(java.lang.String book_str, java.lang.String chapter_str, int verse) throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(java.lang.String book_str, java.lang.String chapter_str, java.lang.String verse_str) throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(java.lang.String book_str, int chapter, java.lang.String verse_str) throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(int book,
java.lang.String chapter_str,
java.lang.String verse_str)
throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(int book,
int chapter,
java.lang.String verse_str)
throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(int book,
int chapter,
int verse)
throws NoSuchVerseException
- Verify and set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(int[] ref)
throws NoSuchVerseException
- Set the references.
This must only be called from a ctor to maintain immutability
set
private final void set(int ordinal)
throws NoSuchVerseException
- Set the references.
This must only be called from a ctor to maintain immutability
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
- Write out the object to the given ObjectOutputStream
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
- Write out the object to the given ObjectOutputStream
|
|||||||||
| Home >> All >> com >> eireneh >> bible >> [ passage overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.eireneh.bible.passage.Verse