org.crosswire.jsword.versification
Class BibleInfo

java.lang.Object
  extended by org.crosswire.jsword.versification.BibleInfo

public final class BibleInfo
extends Object

BibleInfo is a static class that deals with Book number conversions and similar. We start counting at 1 for books, chapters and verses (so Genesis=1, Revelation=66). However internally books start counting at 0 and go up to 65.

I've considered merging BibleInfo and PassageUtil since they are both supporting static only classes. However they are both non-trivial, so together they would be large, and there is a good dividing line between the 2.

Author:
Joe Walker [joe at eireneh dot com], DM Smith [dmsmith555 at yahoo dot com]
See Also:
for license details. The copyright to this program is held by it's authors.

Field Summary
private static BibleNames bibleNames
          Localized BibleNames
static int BOOK
          Used for methods with int[3] parameters, for the book
private static CaseType bookCase
          How the book names are reported.
private static int BOOKS_IN_BIBLE
          Constant for the number of books in the Bible
(package private) static short[] BOOKS_IN_SECTION
          The number of books in each section
static int CHAPTER
          Used for methods with int[3] parameters, for the chapter
private static int CHAPTERS_IN_BIBLE
          Constant for the number of chapters in the Bible
(package private) static short[] CHAPTERS_IN_BOOK
          Constant for the number of chapters in each book
private static BibleNames englishBibleNames
          English BibleNames, or null when using the program's default locale
private static boolean fullBookName
          Whether long or short, full or abbreviated names are used.
(package private) static BibleInfo instance
          A singleton used to do initialization.
(package private) static short[] ORDINAL_AT_START_OF_BOOK
          Constant for the ordinal number of the first verse in each book
(package private) static short[][] ORDINAL_AT_START_OF_CHAPTER
          Constant for the ordinal number of the first verse in each chapter.
private static SectionNames sectionNames
          Localized Bible SectionNames
static int VERSE
          Used for methods with int[3] parameters, for the verse
(package private) static short VERSES_IN_BIBLE
          Constant for the number of verses in the Bible
(package private) static short[] VERSES_IN_BOOK
          Constant for the number of verses in each book
(package private) static short[][] VERSES_IN_CHAPTER
          Constant for the number of verses in each chapter
 
Constructor Summary
private BibleInfo()
          Ensure that we can not be instantiated
 
Method Summary
static int booksInBible()
          Count the books in the Bible.
static int booksInSection(int section)
          How many books are there in each of the above sections
static int chaptersInBible()
          Count the chapters in the Bible.
static int chaptersInBook(int book)
          Count the chapters in this book.
private static boolean containsLetter(String text)
          This is simply a convenience function to wrap Character.isLetter()
static int[] decodeOrdinal(int ordinal)
          Where does this verse come in the Bible.
static BookName getBookName(int book)
          Get the BookName.
static int getBookNumber(String find)
          Get number of a book from its name.
static int getCase()
          This is only used by config
static CaseType getDefaultCase()
          How do we report the names of the books?.
static String getLongBookName(int book)
          Get the full name of a book (e.g.
static String getOSISName(int book)
          Get the OSIS name for a book.
static String getPreferredBookName(int book)
          Get the preferred name of a book.
static String getSectionName(int section)
          Get the full name of a book (e.g.
static String getShortBookName(int book)
          Get the short name of a book (e.g.
private static void initialize()
          Load up the resources for Bible book and section names.
static boolean isBookName(String find)
          Is the given string a valid book name.
static boolean isFullBookName()
          This is only used by config
static int[] patch(int[] ref)
          Fix up these verses so that they are as valid a possible.
static void setCase(CaseType newBookCase)
          How do we report the names of the books?.
static void setCase(int bookCase)
          This is only used by config.
static void setFullBookName(boolean fullName)
          Set whether the name should be full or abbreviated, long or short.
static void validate(int[] ref)
          Does the following represent a real verse?
static void validate(int book, int chapter, int verse)
          Does the following represent a real verse?.
static int verseCount(int[] ref1, int[] ref2)
          How many verses between ref1 and ref2 (inclusive).
static int verseCount(int book1, int chapter1, int verse1, int book2, int chapter2, int verse2)
          How many verses between ref1 and ref2 (inclusive).
static int verseOrdinal(int[] ref)
          Where does this verse come in the Bible.
static int verseOrdinal(int book, int chapter, int verse)
          Where does this verse come in the Bible.
static int versesInBible()
          Count the verses in the Bible.
static int versesInBook(int book)
          Count the verses in a book.
static int versesInChapter(int book, int chapter)
          Count the verses in a chapter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bibleNames

private static BibleNames bibleNames
Localized BibleNames


englishBibleNames

private static BibleNames englishBibleNames
English BibleNames, or null when using the program's default locale


sectionNames

private static SectionNames sectionNames
Localized Bible SectionNames


bookCase

private static CaseType bookCase
How the book names are reported.


fullBookName

private static boolean fullBookName
Whether long or short, full or abbreviated names are used.


BOOK

public static final int BOOK
Used for methods with int[3] parameters, for the book

See Also:
Constant Field Values

CHAPTER

public static final int CHAPTER
Used for methods with int[3] parameters, for the chapter

See Also:
Constant Field Values

VERSE

public static final int VERSE
Used for methods with int[3] parameters, for the verse

See Also:
Constant Field Values

BOOKS_IN_BIBLE

private static final int BOOKS_IN_BIBLE
Constant for the number of books in the Bible

See Also:
Constant Field Values

CHAPTERS_IN_BIBLE

private static final int CHAPTERS_IN_BIBLE
Constant for the number of chapters in the Bible

See Also:
Constant Field Values

CHAPTERS_IN_BOOK

static final short[] CHAPTERS_IN_BOOK
Constant for the number of chapters in each book


VERSES_IN_BIBLE

static final short VERSES_IN_BIBLE
Constant for the number of verses in the Bible

See Also:
Constant Field Values

VERSES_IN_BOOK

static final short[] VERSES_IN_BOOK
Constant for the number of verses in each book


VERSES_IN_CHAPTER

static final short[][] VERSES_IN_CHAPTER
Constant for the number of verses in each chapter


ORDINAL_AT_START_OF_BOOK

static final short[] ORDINAL_AT_START_OF_BOOK
Constant for the ordinal number of the first verse in each book


ORDINAL_AT_START_OF_CHAPTER

static final short[][] ORDINAL_AT_START_OF_CHAPTER
Constant for the ordinal number of the first verse in each chapter. Warning if you regenerate this code (from the code at the bottom of this module) then you will need to cut the psalms line in half to get it to compile under JBuilder.


BOOKS_IN_SECTION

static final short[] BOOKS_IN_SECTION
The number of books in each section


instance

static final BibleInfo instance
A singleton used to do initialization. Could be used to change static methods to non-static

Constructor Detail

BibleInfo

private BibleInfo()
Ensure that we can not be instantiated

Method Detail

setCase

public static void setCase(int bookCase)
This is only used by config.

Parameters:
bookCase - The new case to use for reporting book names
Throws:
IllegalArgumentException - If the case is not between 0 and 2
See Also:
getCase()

getCase

public static int getCase()
This is only used by config

Returns:
The current case setting
See Also:
setCase(CaseType)

setCase

public static void setCase(CaseType newBookCase)
How do we report the names of the books?. These are static. This is on the assumption that we will not want to have different sections of the app using a different format. I expect this to be a good assumption, and it saves passing a Book class around everywhere. BibleInfo.MIXED is not allowed

Parameters:
newBookCase - The new case to use for reporting book names
Throws:
IllegalArgumentException - If the case is not between 0 and 2
See Also:
getCase()

isFullBookName

public static boolean isFullBookName()
This is only used by config

Returns:
Whether the name is long or short. Default is Full (true).
See Also:
setFullBookName(boolean)

setFullBookName

public static void setFullBookName(boolean fullName)
Set whether the name should be full or abbreviated, long or short.

Parameters:
fullName - The new case to use for reporting book names
See Also:
isFullBookName()

getDefaultCase

public static CaseType getDefaultCase()
How do we report the names of the books?.

Returns:
The current case setting
See Also:
setCase(int)

getBookName

public static BookName getBookName(int book)
                            throws NoSuchVerseException
Get the BookName.

Parameters:
book - The book number (1-66)
Returns:
The requested BookName
Throws:
NoSuchVerseException - If the book number is not valid

getPreferredBookName

public static String getPreferredBookName(int book)
                                   throws NoSuchVerseException
Get the preferred name of a book. Altered by the case setting (see setBookCase() and isLongBookName())

Parameters:
book - The book number (1-66)
Returns:
The full name of the book
Throws:
NoSuchVerseException - If the book number is not valid

getLongBookName

public static String getLongBookName(int book)
                              throws NoSuchVerseException
Get the full name of a book (e.g. "Genesis"). Altered by the case setting (see setBookCase())

Parameters:
book - The book number (1-66)
Returns:
The full name of the book
Throws:
NoSuchVerseException - If the book number is not valid

getShortBookName

public static String getShortBookName(int book)
                               throws NoSuchVerseException
Get the short name of a book (e.g. "Gen"). Altered by the case setting (see setBookCase())

Parameters:
book - The book number (1-66)
Returns:
The short name of the book
Throws:
NoSuchVerseException - If the book number is not valid

getOSISName

public static String getOSISName(int book)
                          throws NoSuchVerseException
Get the OSIS name for a book.

Parameters:
book - The book number (1-66)
Returns:
the OSIS defined short name for a book
Throws:
NoSuchVerseException - If the book number is not valid

getBookNumber

public static int getBookNumber(String find)
Get number of a book from its name.

Parameters:
find - The string to identify
Returns:
The book number (1 to 66) On error -1

isBookName

public static boolean isBookName(String find)
Is the given string a valid book name. If this method returns true then getBookNumber() will return a number and not throw an exception.

Parameters:
find - The string to identify
Returns:
The book number (1 to 66)

booksInBible

public static int booksInBible()
Count the books in the Bible.

Returns:
66 always - the number of books in the Bible

chaptersInBible

public static int chaptersInBible()
Count the chapters in the Bible.

Returns:
1189 always - the number of chapters in the Bible

versesInBible

public static int versesInBible()
Count the verses in the Bible. This counts possible verses, so this number is not affected by some versions missing out some verses as 'there in error'

Returns:
31102 always - the number of verses in the Bible

chaptersInBook

public static int chaptersInBook(int book)
                          throws NoSuchVerseException
Count the chapters in this book.

Parameters:
book - The book part of the reference.
Returns:
The number of chapters
Throws:
NoSuchVerseException - If the book number is not valid

versesInChapter

public static int versesInChapter(int book,
                                  int chapter)
                           throws NoSuchVerseException
Count the verses in a chapter.

Parameters:
book - The book part of the reference.
chapter - The current chapter
Returns:
The number of verses
Throws:
NoSuchVerseException - If the book or chapter number is not valid

versesInBook

public static int versesInBook(int book)
                        throws NoSuchVerseException
Count the verses in a book.

Parameters:
book - The book part of the reference.
Returns:
The number of verses
Throws:
NoSuchVerseException - If the book number is not valid

verseOrdinal

public static int verseOrdinal(int book,
                               int chapter,
                               int verse)
                        throws NoSuchVerseException
Where does this verse come in the Bible. Starting with Gen 1:1 as number 1 counting up one per verse and not resetting at each new chapter.

Parameters:
book - The book part of the reference.
chapter - The current chapter
verse - The current verse
Returns:
The ordinal number of verses
Throws:
NoSuchVerseException - If the reference is illegal

verseOrdinal

public static int verseOrdinal(int[] ref)
                        throws NoSuchVerseException
Where does this verse come in the Bible. Starting with Gen 1:1 as number 1 counting up one per verse and not resetting at each new chapter.

Parameters:
ref - An array of 3 ints, book, chapter, verse
Returns:
The ordinal number of the verse
Throws:
NoSuchVerseException - If the reference is illegal

decodeOrdinal

public static int[] decodeOrdinal(int ordinal)
                           throws NoSuchVerseException
Where does this verse come in the Bible. Starting with Gen 1:1 as number 1 counting up one per verse and not resetting at each new chapter.

Parameters:
ordinal - The ordinal number of the verse
Returns:
An array of 3 ints, book, chapter, verse
Throws:
NoSuchVerseException - If the reference is illegal

validate

public static void validate(int 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

validate

public static void validate(int[] ref)
                     throws NoSuchVerseException
Does the following represent a real verse?

Parameters:
ref - An array of 3 ints, book, chapter, verse
Throws:
NoSuchVerseException - If the reference is illegal

patch

public static int[] patch(int[] ref)
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 comentary 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 dispite this maybe we should provide the functionality anyway.

Parameters:
ref - An array of 3 ints, book, chapter, verse. This array will be changed.
Returns:
The original array that has been patched.

verseCount

public static int verseCount(int book1,
                             int chapter1,
                             int verse1,
                             int book2,
                             int chapter2,
                             int verse2)
                      throws NoSuchVerseException
How many verses between ref1 and ref2 (inclusive).

Parameters:
book1 - The book part of the first reference.
chapter1 - The chapter part of the first reference.
verse1 - The verse part of the first reference.
book2 - The book part of the second reference.
chapter2 - The chapter part of the second reference.
verse2 - The verse part of the second reference.
Returns:
the number of verses
Throws:
NoSuchVerseException - If either reference is illegal

verseCount

public static int verseCount(int[] ref1,
                             int[] ref2)
                      throws NoSuchVerseException
How many verses between ref1 and ref2 (inclusive).

Parameters:
ref1 - An array of 3 ints, book, chapter, verse for the first reference.
ref2 - An array of 3 ints, book, chapter, verse for the second reference.
Returns:
the number of verses
Throws:
NoSuchVerseException - If either reference is illegal

booksInSection

public static int booksInSection(int section)
How many books are there in each of the above sections

Parameters:
section - The section
Returns:
The number of books in the given section
See Also:
SectionNames.getSection(int)

getSectionName

public static String getSectionName(int section)
                             throws NoSuchVerseException
Get the full name of a book (e.g. "Genesis"). Altered by the case setting (see setBookCase())

Parameters:
section - The book number (1-66)
Returns:
The full name of the book
Throws:
NoSuchVerseException - If the book number is not valid

containsLetter

private static boolean containsLetter(String text)
This is simply a convenience function to wrap Character.isLetter()

Parameters:
text - The string to be parsed
Returns:
true if the string contains letters

initialize

private static void initialize()
Load up the resources for Bible book and section names.


Copyright ยจ 2003-2007