org.crosswire.jsword.versification
Class Versification

java.lang.Object
  extended by org.crosswire.jsword.versification.Versification
All Implemented Interfaces:
Serializable, ReferenceSystem
Direct Known Subclasses:
SystemCatholic, SystemCatholic2, SystemDefault, SystemGerman, SystemKJV, SystemKJVA, SystemLeningrad, SystemLuther, SystemMT, SystemNRSV, SystemNRSVA, SystemSynodal, SystemSynodalP, SystemVulg

public class Versification
extends Object
implements ReferenceSystem, Serializable

A named Versification defines the order of BibleBooks by Testament, the number of chapters in each BibleBook, the number of verses in each chapter.

Author:
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

Field Summary
private  BibleBookList bookList
           
private  int[][] chapterStarts
          Constant for the ordinal number of the first verse in each chapter.
private  int[][] lastVerse
          Constant for the max verse number in each chapter
private  String name
          The OSIS name of the reference system.
private  int ntMaxOrdinal
          The last ordinal number of the New Testament and the maximum ordinal number of this Reference System
private  int otMaxOrdinal
          The last ordinal number of the Old Testament
private static long serialVersionUID
          Serialization ID
 
Constructor Summary
Versification()
           
Versification(String name, BibleBook[] booksOT, BibleBook[] booksNT, int[][] lastVerseOT, int[][] lastVerseNT)
          Construct a Versification.
 
Method Summary
 Verse add(Verse verse, int n)
          Get the verse that is a few verses on from the one we've got.
 boolean adjacentTo(Verse first, Verse second)
          Is this verse adjacent to another verse
 Verse decodeOrdinal(int ordinal)
          Where does this verse come in the Bible.
 int distance(Verse start, Verse end)
          How many verses are there in between the 2 Verses.
static void dump(PrintStream out, String name, BibleBookList bookList, int[][] array)
           
 VerseRange getAllVerses()
          Get a VerseRange encompassing this Versification.
 int getBookCount(Verse start, Verse end)
          How many books in this range
 BibleBookList getBooks()
           
 int getChapterCount(Verse start, Verse end)
          How many chapters in this range
 int getCount(Testament testament)
          Give the count of verses in the testament or the whole Bible.
 Verse getFirstVerseInBook(Verse verse)
          Create a new Verse being the first verse in the current book
 Verse getFirstVerseInChapter(Verse verse)
          Create a new Verse being the first verse in the current book
 int getLastChapter(BibleBook book)
          Get the last valid chapter number for a book.
 int getLastVerse(BibleBook book, int chapter)
          Get the last valid verse number for a chapter.
 Verse getLastVerseInBook(Verse verse)
          Create a new Verse being the last verse in the current book
 Verse getLastVerseInChapter(Verse verse)
          Create a new Verse being the last verse in the current book
 String getName()
          Get the OSIS name for this Versification.
 int getOrdinal(Verse verse)
          Where does this verse come in the Bible.
 Testament getTestament(int ordinal)
          Get the testament of a given verse
 int getTestamentOrdinal(int ordinal)
          Where does this verse come in the Bible.
 boolean isEndOfBook(Verse verse)
          Is this verse the last in the book
 boolean isEndOfChapter(Verse verse)
          Is this verse the first in a chapter
 boolean isSameBook(Verse a, Verse b)
          Is this verse in the same book as that one
 boolean isSameChapter(Verse a, Verse that)
          Is this verse in the same chapter as that one
 boolean isStartOfBook(Verse verse)
          Is this verse the first in a chapter
 boolean isStartOfChapter(Verse verse)
          Is this verse the first in a chapter
 Verse max(Verse a, Verse b)
          Determine the later of the two verses.
 int maximumOrdinal()
          The maximum number of verses in the Bible, including module, testament, book and chapter introductions.
 Verse min(Verse a, Verse b)
          Determine the earlier of the two verses.
static void optimize(PrintStream out, BibleBookList bookList, int[][] lastVerse)
           
 Verse patch(BibleBook book, int chapter, int verse)
          Fix up these verses so that they are as valid a possible.
 Verse subtract(Verse verse, int n)
          Get the verse n down from here this Verse.
 void validate(BibleBook book, int chapter, int verse)
          Does the following represent a real verse?.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private String name
The OSIS name of the reference system.


bookList

private BibleBookList bookList

otMaxOrdinal

private int otMaxOrdinal
The last ordinal number of the Old Testament


ntMaxOrdinal

private int ntMaxOrdinal
The last ordinal number of the New Testament and the maximum ordinal number of this Reference System


lastVerse

private int[][] lastVerse
Constant for the max verse number in each chapter


chapterStarts

private int[][] chapterStarts
Constant for the ordinal number of the first verse in each chapter.


serialVersionUID

private static final long serialVersionUID
Serialization ID

See Also:
Constant Field Values
Constructor Detail

Versification

public Versification()

Versification

public Versification(String name,
                     BibleBook[] booksOT,
                     BibleBook[] booksNT,
                     int[][] lastVerseOT,
                     int[][] lastVerseNT)
Construct a Versification.

Parameters:
name - The name of this reference system
booksOT - An ordered list of books in this reference system. The list should not include INTRO_BIBLE, or INTRO_OT.
booksNT - An ordered list of books in this reference system. The list should not include INTRO_NT.
lastVerseOT - For each book in booksOT, this has an array with one entry for each chapter whose value is the highest numbered verse in that chapter. Do not include chapter 0.
lastVerseNT - For each book in booksNT, this has an array with one entry for each chapter whose value is the highest numbered verse in that chapter. Do not include chapter 0.
Method Detail

getName

public String getName()
Get the OSIS name for this Versification.

Returns:
the OSIS name of the Versification

getBooks

public BibleBookList getBooks()

getLastChapter

public int getLastChapter(BibleBook book)
Get the last valid chapter number for a book.

Parameters:
book - The book part of the reference.
Returns:
The last valid chapter number for a book.

getLastVerse

public int getLastVerse(BibleBook book,
                        int chapter)
Get the last valid verse number for a chapter.

Parameters:
book - The book part of the reference.
chapter - The current chapter
Returns:
The last valid verse number for a chapter

getAllVerses

public VerseRange getAllVerses()
Get a VerseRange encompassing this Versification.


getLastVerseInBook

public Verse getLastVerseInBook(Verse verse)
Create a new Verse being the last verse in the current book

Returns:
The last verse in this book

getLastVerseInChapter

public Verse getLastVerseInChapter(Verse verse)
Create a new Verse being the last verse in the current book

Returns:
The last verse in this book

getFirstVerseInBook

public Verse getFirstVerseInBook(Verse verse)
Create a new Verse being the first verse in the current book

Returns:
The first verse in this book

getFirstVerseInChapter

public Verse getFirstVerseInChapter(Verse verse)
Create a new Verse being the first verse in the current book

Returns:
The first verse in this book

isStartOfChapter

public boolean isStartOfChapter(Verse verse)
Is this verse the first in a chapter

Returns:
true or false ...

isEndOfChapter

public boolean isEndOfChapter(Verse verse)
Is this verse the first in a chapter

Returns:
true or false ...

isStartOfBook

public boolean isStartOfBook(Verse verse)
Is this verse the first in a chapter

Returns:
true or false ...

isEndOfBook

public boolean isEndOfBook(Verse verse)
Is this verse the last in the book

Returns:
true or false ...

isSameChapter

public boolean isSameChapter(Verse a,
                             Verse that)
Is this verse in the same chapter as that one

Parameters:
that - The verse to compare to
Returns:
true or false ...

isSameBook

public boolean isSameBook(Verse a,
                          Verse b)
Is this verse in the same book as that one

Parameters:
a - The verse to compare to
b - The verse to compare to
Returns:
true or false ...

adjacentTo

public boolean adjacentTo(Verse first,
                          Verse second)
Is this verse adjacent to another verse

Parameters:
first - The first verse in the comparison
second - The second verse in the comparison
Returns:
true if the verses are adjacent.

distance

public int distance(Verse start,
                    Verse end)
How many verses are there in between the 2 Verses. The answer is -ve if start is bigger than end. The answer is inclusive of start and exclusive of end, so that distance(gen11, gen12) == 1

Parameters:
start - The first Verse in the range
end - The last Verse in the range
Returns:
The count of verses between this and that.

min

public Verse min(Verse a,
                 Verse b)
Determine the earlier of the two verses. If a == b then return a.

Parameters:
a - the first verse to compare
b - the second verse to compare
Returns:
The earlier of the two verses

max

public Verse max(Verse a,
                 Verse b)
Determine the later of the two verses. If a == b then return b.

Parameters:
a - the first verse to compare
b - the second verse to compare
Returns:
The later of the two verses

subtract

public Verse subtract(Verse verse,
                      int n)
Get the verse n down from here this Verse.

Parameters:
n - The number to count down by
Returns:
The new Verse

add

public Verse add(Verse verse,
                 int n)
Get the verse that is a few verses on from the one we've got.

Parameters:
n - the number of verses later than the one we're one
Returns:
The new verse

getChapterCount

public int getChapterCount(Verse start,
                           Verse end)
How many chapters in this range

Returns:
The number of chapters. Always >= 1.

getBookCount

public int getBookCount(Verse start,
                        Verse end)
How many books in this range

Returns:
The number of books. Always >= 1.

maximumOrdinal

public int maximumOrdinal()
The maximum number of verses in the Bible, including module, testament, book and chapter introductions.

Returns:
the number of addressable verses in this versification.

getOrdinal

public int getOrdinal(Verse verse)
Where does this verse come in the Bible. The value that this returns should be treated as opaque, useful for a bit set. The introductions to the Book, OT/NT Testaments, Bible books and chapters are included here.

Parameters:
verse - The verse to convert
Returns:
The ordinal number of verses

getTestamentOrdinal

public int getTestamentOrdinal(int ordinal)
Where does this verse come in the Bible. The value that this returns should be treated as opaque, useful for a bit set. The introductions to the Book, OT/NT Testaments, Bible books and chapters are included here.

Parameters:
verse - The verse to convert
Returns:
The ordinal number of verses

getTestament

public Testament getTestament(int ordinal)
Get the testament of a given verse


getCount

public int getCount(Testament testament)
Give the count of verses in the testament or the whole Bible.

Parameters:
testament - The testament to count. If null, then all testaments.
Returns:
the number of verses in the testament

decodeOrdinal

public Verse decodeOrdinal(int ordinal)
Where does this verse come in the Bible. This will unwind the value returned by getOrdinal(Verse). If the ordinal value is less than 0 or greater than the last verse in this Versification, then constrain it to the first or last verse in this Versification.

Parameters:
ordinal - The ordinal number of the verse
Returns:
A Verse

validate

public void validate(BibleBook book,
                     int chapter,
                     int verse)
              throws NoSuchVerseException
Does the following represent a real verse?. It is code like this that makes me wonder if I18 is done well/worth doing. All this code does is check if the numbers are valid, but the exception handling code is huge :(

Parameters:
book - The book part of the reference.
chapter - The chapter part of the reference.
verse - The verse part of the reference.
Throws:
NoSuchVerseException - If the reference is illegal

patch

public Verse patch(BibleBook book,
                   int chapter,
                   int verse)
Fix up these verses so that they are as valid a possible. This is currently done so that we can say "Gen 1:1" + 31 = "Gen 1:32" and "Gen 1:32".patch() is "Gen 2:1".

There is another patch system that allows us to use large numbers to mean "the end of" so "Gen 1:32".otherPatch() gives "Gen 1:31". This could be useful to allow the user to enter things like "Gen 1:99" meaning the end of the chapter. Or "Isa 99:1" to mean the last chapter in Isaiah verse 1 or even "Rev 99:99" to mean the last verse in the Bible.

However I have not implemented this because I've used a different convention: "Gen 1:$" (OLB compatible) or "Gen 1:ff" (common commentary usage) to mean the end of the chapter - So the functionality is there anyway.

I think that getting into the habit of typing "Gen 1:99" is bad. It could be the source of surprises "Psa 119:99" is not what you'd might expect, and neither is "Psa 99:1" is you wanted the last chapter in Psalms - expecting us to type "Psa 999:1" seems like we're getting silly.

However despite this maybe we should provide the functionality anyway.

Parameters:
book - the book to obtain
chapter - the supposed chapter
verse - the supposed verse
Returns:
The resultant verse.

dump

public static void dump(PrintStream out,
                        String name,
                        BibleBookList bookList,
                        int[][] array)

optimize

public static void optimize(PrintStream out,
                            BibleBookList bookList,
                            int[][] lastVerse)

Copyright ? 2003-2011