[jsword-svn] r2220 - in trunk/jsword/src/main/java/org/crosswire/jsword/versification: . system

dmsmith at crosswire.org dmsmith at crosswire.org
Tue Jan 24 14:46:35 MST 2012


Author: dmsmith
Date: 2012-01-24 14:46:35 -0700 (Tue, 24 Jan 2012)
New Revision: 2220

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleBookList.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleInfo.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/ReferenceSystem.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/ReferenceSystems.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic2.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemGerman.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJV.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJVA.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLeningrad.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLuther.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemMT.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSV.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSVA.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodal.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodalP.java
   trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemVulg.java
Log:
In progress check in of v11n code. This is probably a breaker.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleBookList.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleBookList.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleBookList.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -22,6 +22,7 @@
 package org.crosswire.jsword.versification;
 
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 /**
  * A BibleBookList is an ordered list of one or more BibleBooks.
@@ -31,7 +32,7 @@
  *      The copyright to this program is held by it's authors.
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
-public class BibleBookList {
+public class BibleBookList implements Iterable<BibleBook> {
     /**
      * Create an ordered BibleBookList from the input.
      * @param books
@@ -96,11 +97,55 @@
      * 
      * @return an Iterator over the books
      */
-    public Iterator getBooks() {
-        return null;
+    public Iterator<BibleBook> iterator() {
+        return new Iterator<BibleBook>() {
+
+            BibleBook nextBook = books[0];
+
+            @Override
+            public boolean hasNext() {
+                return nextBook != null;
+            }
+
+            @Override
+            public BibleBook next() {
+
+                if (nextBook == null) {
+                    throw new NoSuchElementException();
+                }
+
+                BibleBook current = nextBook;
+                nextBook = getNextBook(nextBook);
+                return current;
+            }
+
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+            
+        };
     }
 
     /**
+     * Return the first book in the list.
+     * 
+     * @return the first book in the list
+     */
+    public BibleBook getFirstBook() {
+        return books[0];
+    }
+
+    /**
+     * Return the first book in the list.
+     * 
+     * @return the first book in the list
+     */
+    public BibleBook getLastBook() {
+        return books[books.length - 1];
+    }
+
+    /**
      * Given a BibleBook, get the previous BibleBook in this ReferenceSystem. If it is the first book, return null.
      * @param book A BibleBook in the ReferenceSystem
      * @return the previous BibleBook or null.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleInfo.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleInfo.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleInfo.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -25,7 +25,7 @@
 import org.crosswire.jsword.book.CaseType;
 import org.crosswire.jsword.passage.NoSuchVerseException;
 import org.crosswire.jsword.passage.Verse;
-import org.crosswire.jsword.versification.system.SystemKJV;
+import org.crosswire.jsword.versification.system.ReferenceSystems;
 
 /**
  * BibleInfo is a static class that deals with Bible book names, and conversion to and from
@@ -34,6 +34,8 @@
  * of the KJV Bible. It is not true of other versifications such as Luther's.
  * </p>
  *
+ * @deprecated Use ReferenceSystems.getReferenceSystem("KJV") instead.
+ * 
  * @see gnu.lgpl.License for license details.<br>
  *      The copyright to this program is held by it's authors.
  * @author Joe Walker [joe at eireneh dot com]
@@ -270,466 +272,11 @@
 
     /** The OSIS name of the reference system. */
     public static String osisName = "KJV";
+    public static ReferenceSystem referenceSystem = ReferenceSystems.instance().getReferenceSystem(osisName);
 
-    /** The ordered list of BibleBooks */
-    public static BibleBook[] kjvBooks =
-    {
-        // JSword introduction to the Bible
-        BibleBook.INTRO_BIBLE,
-        // JSword introduction to the Old Testament
-        BibleBook.INTRO_OT,
-        // Old Testament
-        BibleBook.GEN,
-        BibleBook.EXOD,
-        BibleBook.LEV,
-        BibleBook.NUM,
-        BibleBook.DEUT,
-        BibleBook.JOSH,
-        BibleBook.JUDG,
-        BibleBook.RUTH,
-        BibleBook.SAM1,
-        BibleBook.SAM2,
-        BibleBook.KGS1,
-        BibleBook.KGS2,
-        BibleBook.CHR1,
-        BibleBook.CHR2,
-        BibleBook.EZRA,
-        BibleBook.NEH,
-        BibleBook.ESTH,
-        BibleBook.JOB,
-        BibleBook.PS,
-        BibleBook.PROV,
-        BibleBook.ECCL,
-        BibleBook.SONG,
-        BibleBook.ISA,
-        BibleBook.JER,
-        BibleBook.LAM,
-        BibleBook.EZEK,
-        BibleBook.DAN,
-        BibleBook.HOS,
-        BibleBook.JOEL,
-        BibleBook.AMOS,
-        BibleBook.OBAD,
-        BibleBook.JONAH,
-        BibleBook.MIC,
-        BibleBook.NAH,
-        BibleBook.HAB,
-        BibleBook.ZEPH,
-        BibleBook.HAG,
-        BibleBook.ZECH,
-        BibleBook.MAL,
-        // JSword introduction to the New Testament
-        BibleBook.INTRO_NT,
-        // New Testament
-        BibleBook.MATT,
-        BibleBook.MARK,
-        BibleBook.LUKE,
-        BibleBook.JOHN,
-        BibleBook.ACTS,
-        BibleBook.ROM,
-        BibleBook.COR1,
-        BibleBook.COR2,
-        BibleBook.GAL,
-        BibleBook.EPH,
-        BibleBook.PHIL,
-        BibleBook.COL,
-        BibleBook.THESS1,
-        BibleBook.THESS2,
-        BibleBook.TIM1,
-        BibleBook.TIM2,
-        BibleBook.TITUS,
-        BibleBook.PHLM,
-        BibleBook.HEB,
-        BibleBook.JAS,
-        BibleBook.PET1,
-        BibleBook.PET2,
-        BibleBook.JOHN1,
-        BibleBook.JOHN2,
-        BibleBook.JOHN3,
-        BibleBook.JUDE,
-        BibleBook.REV,
-    };
-
-    /** Constant for the max verse number in each chapter */
-    public static final int[][] kjvLastVerse =
-    {
-        // Bible Introduction
-        {
-                0,
-        },
-        // Old Testament Introduction
-        {
-                0,
-        },
-        // Gen
-        {
-                0,    31,    25,    24,    26,    32,    22,    24,    22,    29,
-               32,    32,    20,    18,    24,    21,    16,    27,    33,    38,
-               18,    34,    24,    20,    67,    34,    35,    46,    22,    35,
-               43,    55,    32,    20,    31,    29,    43,    36,    30,    23,
-               23,    57,    38,    34,    34,    28,    34,    31,    22,    33,
-               26,
-        },
-        // Exod
-        {
-                0,    22,    25,    22,    31,    23,    30,    25,    32,    35,
-               29,    10,    51,    22,    31,    27,    36,    16,    27,    25,
-               26,    36,    31,    33,    18,    40,    37,    21,    43,    46,
-               38,    18,    35,    23,    35,    35,    38,    29,    31,    43,
-               38,
-        },
-        // Lev
-        {
-                0,    17,    16,    17,    35,    19,    30,    38,    36,    24,
-               20,    47,     8,    59,    57,    33,    34,    16,    30,    37,
-               27,    24,    33,    44,    23,    55,    46,    34,
-        },
-        // Num
-        {
-                0,    54,    34,    51,    49,    31,    27,    89,    26,    23,
-               36,    35,    16,    33,    45,    41,    50,    13,    32,    22,
-               29,    35,    41,    30,    25,    18,    65,    23,    31,    40,
-               16,    54,    42,    56,    29,    34,    13,
-        },
-        // Deut
-        {
-                0,    46,    37,    29,    49,    33,    25,    26,    20,    29,
-               22,    32,    32,    18,    29,    23,    22,    20,    22,    21,
-               20,    23,    30,    25,    22,    19,    19,    26,    68,    29,
-               20,    30,    52,    29,    12,
-        },
-        // Josh
-        {
-                0,    18,    24,    17,    24,    15,    27,    26,    35,    27,
-               43,    23,    24,    33,    15,    63,    10,    18,    28,    51,
-                9,    45,    34,    16,    33,
-        },
-        // Judg
-        {
-                0,    36,    23,    31,    24,    31,    40,    25,    35,    57,
-               18,    40,    15,    25,    20,    20,    31,    13,    31,    30,
-               48,    25,
-        },
-        // Ruth
-        {
-                0,    22,    23,    18,    22,
-        },
-        // 1Sam
-        {
-                0,    28,    36,    21,    22,    12,    21,    17,    22,    27,
-               27,    15,    25,    23,    52,    35,    23,    58,    30,    24,
-               42,    15,    23,    29,    22,    44,    25,    12,    25,    11,
-               31,    13,
-        },
-        // 2Sam
-        {
-                0,    27,    32,    39,    12,    25,    23,    29,    18,    13,
-               19,    27,    31,    39,    33,    37,    23,    29,    33,    43,
-               26,    22,    51,    39,    25,
-        },
-        // 1Kgs
-        {
-                0,    53,    46,    28,    34,    18,    38,    51,    66,    28,
-               29,    43,    33,    34,    31,    34,    34,    24,    46,    21,
-               43,    29,    53,
-        },
-        // 2Kgs
-        {
-                0,    18,    25,    27,    44,    27,    33,    20,    29,    37,
-               36,    21,    21,    25,    29,    38,    20,    41,    37,    37,
-               21,    26,    20,    37,    20,    30,
-        },
-        // 1Chr
-        {
-                0,    54,    55,    24,    43,    26,    81,    40,    40,    44,
-               14,    47,    40,    14,    17,    29,    43,    27,    17,    19,
-                8,    30,    19,    32,    31,    31,    32,    34,    21,    30,
-        },
-        // 2Chr
-        {
-                0,    17,    18,    17,    22,    14,    42,    22,    18,    31,
-               19,    23,    16,    22,    15,    19,    14,    19,    34,    11,
-               37,    20,    12,    21,    27,    28,    23,     9,    27,    36,
-               27,    21,    33,    25,    33,    27,    23,
-        },
-        // Ezra
-        {
-                0,    11,    70,    13,    24,    17,    22,    28,    36,    15,
-               44,
-        },
-        // Neh
-        {
-                0,    11,    20,    32,    23,    19,    19,    73,    18,    38,
-               39,    36,    47,    31,
-        },
-        // Esth
-        {
-                0,    22,    23,    15,    17,    14,    14,    10,    17,    32,
-                3,
-        },
-        // Job
-        {
-                0,    22,    13,    26,    21,    27,    30,    21,    22,    35,
-               22,    20,    25,    28,    22,    35,    22,    16,    21,    29,
-               29,    34,    30,    17,    25,     6,    14,    23,    28,    25,
-               31,    40,    22,    33,    37,    16,    33,    24,    41,    30,
-               24,    34,    17,
-        },
-        // Ps
-        {
-                0,     6,    12,     8,     8,    12,    10,    17,     9,    20,
-               18,     7,     8,     6,     7,     5,    11,    15,    50,    14,
-                9,    13,    31,     6,    10,    22,    12,    14,     9,    11,
-               12,    24,    11,    22,    22,    28,    12,    40,    22,    13,
-               17,    13,    11,     5,    26,    17,    11,     9,    14,    20,
-               23,    19,     9,     6,     7,    23,    13,    11,    11,    17,
-               12,     8,    12,    11,    10,    13,    20,     7,    35,    36,
-                5,    24,    20,    28,    23,    10,    12,    20,    72,    13,
-               19,    16,     8,    18,    12,    13,    17,     7,    18,    52,
-               17,    16,    15,     5,    23,    11,    13,    12,     9,     9,
-                5,     8,    28,    22,    35,    45,    48,    43,    13,    31,
-                7,    10,    10,     9,     8,    18,    19,     2,    29,   176,
-                7,     8,     9,     4,     8,     5,     6,     5,     6,     8,
-                8,     3,    18,     3,     3,    21,    26,     9,     8,    24,
-               13,    10,     7,    12,    15,    21,    10,    20,    14,     9,
-                6,
-        },
-        // Prov
-        {
-                0,    33,    22,    35,    27,    23,    35,    27,    36,    18,
-               32,    31,    28,    25,    35,    33,    33,    28,    24,    29,
-               30,    31,    29,    35,    34,    28,    28,    27,    28,    27,
-               33,    31,
-        },
-        // Eccl
-        {
-                0,    18,    26,    22,    16,    20,    12,    29,    17,    18,
-               20,    10,    14,
-        },
-        // Song
-        {
-                0,    17,    17,    11,    16,    16,    13,    13,    14,
-        },
-        // Isa
-        {
-                0,    31,    22,    26,     6,    30,    13,    25,    22,    21,
-               34,    16,     6,    22,    32,     9,    14,    14,     7,    25,
-                6,    17,    25,    18,    23,    12,    21,    13,    29,    24,
-               33,     9,    20,    24,    17,    10,    22,    38,    22,     8,
-               31,    29,    25,    28,    28,    25,    13,    15,    22,    26,
-               11,    23,    15,    12,    17,    13,    12,    21,    14,    21,
-                      22,    11,    12,    19,    12,    25,    24,
-        },
-        // Jer
-        {
-                0,    19,    37,    25,    31,    31,    30,    34,    22,    26,
-               25,    23,    17,    27,    22,    21,    21,    27,    23,    15,
-               18,    14,    30,    40,    10,    38,    24,    22,    17,    32,
-               24,    40,    44,    26,    22,    19,    32,    21,    28,    18,
-               16,    18,    22,    13,    30,     5,    28,     7,    47,    39,
-               46,    64,    34,
-        },
-        // Lam
-        {
-            0,    22,    22,    66,    22,    22,
-        },
-        // Ezek
-        {
-                0,    28,    10,    27,    17,    17,    14,    27,    18,    11,
-               22,    25,    28,    23,    23,     8,    63,    24,    32,    14,
-               49,    32,    31,    49,    27,    17,    21,    36,    26,    21,
-               26,    18,    32,    33,    31,    15,    38,    28,    23,    29,
-               49,    26,    20,    27,    31,    25,    24,    23,    35,
-        },
-        // Dan
-        {
-                0,    21,    49,    30,    37,    31,    28,    28,    27,    27,
-               21,    45,    13,
-        },
-        // Hos
-        {
-                0,    11,    23,     5,    19,    15,    11,    16,    14,    17,
-               15,    12,    14,    16,     9,
-        },
-        // Joel
-        {
-                0,    20,    32,    21,
-        },
-        // Amos
-        {
-                0,    15,    16,    15,    13,    27,    14,    17,    14,    15,
-        },
-        // Obad
-        {
-                0,    21,
-        },
-        // Jonah
-        {
-                0,    17,    10,    10,    11,
-        },
-        // Mic
-        {
-                0,    16,    13,    12,    13,    15,    16,    20,
-        },
-        // Nah
-        {
-                0,    15,    13,    19,
-        },
-        // Hab
-        {
-                0,    17,    20,    19,
-        },
-        // Zeph
-        {
-                0,    18,    15,    20,
-        },
-        // Hag
-        {
-                0,    15,    23,
-        },
-        // Zech
-        {
-                0,    21,    13,    10,    14,    11,    15,    14,    23,    17,
-               12,    17,    14,     9,    21,
-        },
-        // Mal
-        {
-                0,    14,    17,    18,     6,
-        },
-        // New Testament Introduction
-        {
-                0,
-        },
-        // Matt
-        {
-                0,    25,    23,    17,    25,    48,    34,    29,    34,    38,
-               42,    30,    50,    58,    36,    39,    28,    27,    35,    30,
-               34,    46,    46,    39,    51,    46,    75,    66,    20,
-        },
-        // Mark
-        {
-                0,    45,    28,    35,    41,    43,    56,    37,    38,    50,
-               52,    33,    44,    37,    72,    47,    20,
-        },
-        // Luke
-        {
-                0,    80,    52,    38,    44,    39,    49,    50,    56,    62,
-               42,    54,    59,    35,    35,    32,    31,    37,    43,    48,
-               47,    38,    71,    56,    53,
-        },
-        // John
-        {
-                0,    51,    25,    36,    54,    47,    71,    53,    59,    41,
-               42,    57,    50,    38,    31,    27,    33,    26,    40,    42,
-               31,    25,
-        },
-        // Acts
-        {
-                0,    26,    47,    26,    37,    42,    15,    60,    40,    43,
-               48,    30,    25,    52,    28,    41,    40,    34,    28,    41,
-               38,    40,    30,    35,    27,    27,    32,    44,    31,
-        },
-        // Rom
-        {
-                0,    32,    29,    31,    25,    21,    23,    25,    39,    33,
-               21,    36,    21,    14,    23,    33,    27,
-        },
-        // 1Cor
-        {
-                0,    31,    16,    23,    21,    13,    20,    40,    13,    27,
-               33,    34,    31,    13,    40,    58,    24,
-        },
-        // 2Cor
-        {
-                0,    24,    17,    18,    18,    21,    18,    16,    24,    15,
-               18,    33,    21,    14,
-        },
-        // Gal
-        {
-                0,    24,    21,    29,    31,    26,    18,
-        },
-        // Eph
-        {
-                0,    23,    22,    21,    32,    33,    24,
-        },
-        // Phil
-        {
-                0,    30,    30,    21,    23,
-        },
-        // Col
-        {
-                0,    29,    23,    25,    18,
-        },
-        // 1Thess
-        {
-                0,    10,    20,    13,    18,    28,
-        },
-        // 2Thess
-        {
-                0,    12,    17,    18,
-        },
-        // 1Tim
-        {
-                0,    20,    15,    16,    16,    25,    21,
-        },
-        // 2Tim
-        {
-                0,    18,    26,    17,    22,
-        },
-        // Titus
-        {
-                0,    16,    15,    15,
-        },
-        // Phlm
-        {
-                0,    25,
-        },
-        // Heb
-        {
-                0,    14,    18,    19,    16,    14,    20,    28,    13,    28,
-               39,    40,    29,    25,
-        },
-        // Jas
-        {
-                0,    27,    26,    18,    17,    20,
-        },
-        // 1Pet
-        {
-                0,    25,    25,    22,    19,    14,
-        },
-        // 2Pet
-        {
-                0,    21,    22,    18,
-        },
-        // 1John
-        {
-                0,    10,    29,    24,    21,    21,
-        },
-        // 2John
-        {
-                0,    13,
-        },
-        // 3John
-        {
-                0,    14,
-        },
-        // Jude
-        {
-                0,    25,
-        },
-        // Rev
-        {
-                0,    20,    29,    22,    11,    14,    17,    17,    13,    21,
-               11,    19,    17,    18,    20,     8,    21,    18,    24,    21,
-               15,    27,    21,
-        },
-    };
-
     /**
      * Constant for the ordinal number of the first verse in each chapter.
      */
-    // Note the sentinel at the end of the array is one greater
-    // than the last ordinal in the last book
     public static final int[][] kjvChapterStarts =
     {
         // Bible Introduction
@@ -1104,15 +651,7 @@
         },
     };
 
-    public static ReferenceSystem referenceSystem = new ReferenceSystem(osisName, SystemKJV.booksOT, SystemKJV.booksNT, SystemKJV.lastVerseOT, SystemKJV.lastVerseNT);
-
     /**
-     * A singleton used to do initialization. Could be used to change static
-     * methods to non-static
-     */
-    static final BibleInfo instance = new BibleInfo();
-
-    /**
      * Get the BookName.
      * This is merely a convenience function that validates that book is not null,
      * throwing NoSuchVerseException if it is.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/ReferenceSystem.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/ReferenceSystem.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/ReferenceSystem.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -47,69 +47,12 @@
      * 
      * @param osisName
      *            The name of this reference system
-     * @param books
-     *            An ordered list of books in this reference system. The list
-     *            should always start with INTRO_BIBLE and INTRO_OT. The first
-     *            New Testament book should be preceded by INTRO_NT.
-     * @param lastVerse
-     *            For each book in books, this has an array with one entry for
-     *            each chapter including chapter 0 whose value is the highest
-     *            numbered verse in that chapter.
-     */
-    public ReferenceSystem(String osisName, BibleBook[] books, int[][] lastVerse) {
-        this.osisName = osisName;
-        this.bookList = new BibleBookList(books);
-
-        int ordinal = 0;
-        int bookCount = lastVerse.length;
-
-        // Create an independent copy of lastVerse.
-        this.lastVerse = lastVerse.clone();
-        for (int bookIndex = 0; bookIndex < bookCount; bookIndex++) {
-            this.lastVerse[bookIndex] = lastVerse[bookIndex].clone();
-        }
-
-        // Initialize chapterStarts to be a parallel array to lastVerse,
-        // but with chapter starts
-        this.chapterStarts = new int[bookCount][];
-        for (int bookIndex = 0; bookIndex < bookCount; bookIndex++) {
-
-            // Remember where the OT ends
-            if (bookList.getBook(bookIndex) == BibleBook.INTRO_NT) {
-                this.otMaxOrdinal = ordinal - 1;
-            }
-
-            // Save off the chapter starts
-            int[] src = this.lastVerse[bookIndex];
-            int numChapters = src.length;
-            int[] dest = new int[numChapters];
-            this.chapterStarts[bookIndex] = dest;
-            for (int chapterIndex = 0; chapterIndex < numChapters; chapterIndex++) {
-                // Save off the chapter start
-                dest[chapterIndex] = ordinal;
-
-                // Set ordinal to the start of the next chapter or book introduction.
-                // The number of verses in each chapter, when including verse 0,
-                // is one more that the largest numbered verse in the chapter.
-                ordinal += src[chapterIndex] + 1;
-            }
-        }
-
-        // Remember where the NT ends
-        this.ntMaxOrdinal = ordinal - 1;
-    }
-
-    /**
-     * Construct a ReferenceSystem.
-     * 
-     * @param osisName
-     *            The name of this reference system
      * @param booksOT
      *            An ordered list of books in this reference system. The list
      *            should not include INTRO_BIBLE, or INTRO_OT.
-     * @param booksOT
+     * @param booksNT
      *            An ordered list of books in this reference system. The list
-     *            should not include INTRO_BIBLE, or INTRO_OT.
+     *            should not include INTRO_NT.
      * @param 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
@@ -441,6 +384,46 @@
     }
 
     /**
+     * How many chapters in this range
+     * 
+     * @return The number of chapters. Always >= 1.
+     */
+    public int getChapterCount(Verse start, Verse end) {
+        BibleBook startBook = start.getBook();
+        int startChap = start.getChapter();
+        BibleBook endBook = end.getBook();
+        int endChap = end.getChapter();
+
+        if (startBook == endBook) {
+            return endChap - startChap + 1;
+        }
+
+        // So we are going to have to count up chapters from start to end
+        int total = getLastChapter(startBook) - startChap;
+        BibleBookList books = getBooks();
+        startBook = books.getNextBook(startBook);
+        endBook = books.getPreviousBook(endBook);
+        for (BibleBook b =  startBook; b != endBook; b = books.getNextBook(b)) {
+            total += getLastChapter(b);
+        }
+        total += endChap;
+
+        return total;
+    }
+
+    /**
+     * How many books in this range
+     * 
+     * @return The number of books. Always >= 1.
+     */
+    public int getBookCount(Verse start, Verse end) {
+        int startBook = getBooks().getOrdinal(start.getBook());
+        int endBook = getBooks().getOrdinal(end.getBook());
+
+        return endBook - startBook + 1;
+    }
+
+    /**
      * The maximum number of verses in the Bible, including module, testament, book and chapter introductions.
      *
      * @return the number of addressable verses in this versification.
@@ -607,7 +590,7 @@
             verse = ord - chapterStarts[bookIndex][chapterIndex];
         }
 
-        return new Verse(book, chapterIndex, verse, true);
+        return new Verse(book, chapterIndex, verse);
     }
 
     /**
@@ -694,9 +677,10 @@
         int patchedChapter = chapter;
         int patchedVerse = verse;
 
-        // If the book is null, then patch to GENESIS
+        // If the book is null,
+        // then patch to the first book in the reference system
         if (patchedBook == null) {
-            patchedBook = BibleBook.GEN;
+            patchedBook = getBooks().getFirstBook();
         }
         // If they are too small
         if (patchedChapter < 0) {
@@ -707,11 +691,13 @@
         }
 
         while (patchedChapter > getLastChapter(patchedBook)) {
-            patchedChapter -= getLastChapter(patchedBook);
+            patchedChapter -= getLastChapter(patchedBook) + 1;
             patchedBook = bookList.getNextBook(patchedBook);
 
+            // If we have gone beyond the last book
+            // then return the last chapter and verse in that book
             if (patchedBook == null) {
-                patchedBook = BibleBook.REV;
+                patchedBook = getBooks().getLastBook();
                 patchedChapter = getLastChapter(patchedBook);
                 patchedVerse = getLastVerse(patchedBook, patchedChapter);
                 return new Verse(patchedBook, patchedChapter, patchedVerse);
@@ -726,8 +712,10 @@
                 patchedChapter -= getLastChapter(patchedBook);
                 patchedBook = bookList.getNextBook(patchedBook);
 
+                // If we have gone beyond the last book
+                // then return the last chapter and verse in that book
                 if (patchedBook == null) {
-                    patchedBook = BibleBook.REV;
+                    patchedBook = getBooks().getLastBook();
                     patchedChapter = getLastChapter(patchedBook);
                     patchedVerse = getLastVerse(patchedBook, patchedChapter);
                     return new Verse(patchedBook, patchedChapter, patchedVerse);

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/ReferenceSystems.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/ReferenceSystems.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/ReferenceSystems.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -22,29 +22,152 @@
 package org.crosswire.jsword.versification.system;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.crosswire.jsword.versification.ReferenceSystem;
 
 /**
  * The ReferenceSystems class manages the creation of ReferenceSystems as needed.
+ * It delays the construction of the ReferenceSystem until getReferenceSystem(String name) is called.
  *
  * @see gnu.lgpl.License for license details.<br>
  *      The copyright to this program is held by it's authors.
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class ReferenceSystems {
-    
+
+    /**
+     * Get the singleton instance of ReferenceSystems.
+     * 
+     * @return the singleton
+     */
+    public static ReferenceSystems instance() {
+        return instance;
+    }
+
+    /**
+     * Get the ReferenceSystem by its name. If name is null then return the default ReferenceSystem.
+     * 
+     * @param name the name of the ReferenceSystem
+     * @return the ReferenceSystem or null if it is not known.
+     */
     public synchronized ReferenceSystem getReferenceSystem(String name) {
-        if (rsMap.containsKey(name)) {
-            return rsMap.get(name);
+        String actual = name;
+        if (actual == null) {
+            actual = DEFAULT_REFERENCE_SYSTEM;
         }
+
+        // This class delays the building of a ReferenceSystem to when it is
+        // actually needed.
+        ReferenceSystem rs = fluffed.get(actual);
+        if (rs == null) {
+            rs = fluff(actual);
+            if (rs != null) {
+                fluffed.put(actual, rs);
+            }
+        }
+
+        return rs;
+    }
+
+    /**
+     * Determine whether the named ReferenceSystem is known.
+     * 
+     * @param name the name of the ReferenceSystem
+     * @return true when the ReferenceSystem is available for use
+     */
+    public synchronized boolean isDefined(String name) {
+        return name == null || known.contains(name);
+    }
+
+    private ReferenceSystem fluff(String name) {
+        if (SystemKJV.name.equals(name)) {
+            return new SystemKJV();
+        }
+        if (SystemCatholic.name.equals(name)) {
+            return new SystemCatholic();
+        }
+        if (SystemCatholic2.name.equals(name)) {
+            return new SystemCatholic2();
+        }
+        if (SystemKJVA.name.equals(name)) {
+            return new SystemKJVA();
+        }
+        if (SystemGerman.name.equals(name)) {
+            return new SystemGerman();
+        }
+        if (SystemLeningrad.name.equals(name)) {
+            return new SystemLeningrad();
+        }
+        if (SystemLuther.name.equals(name)) {
+            return new SystemLuther();
+        }
+        if (SystemMT.name.equals(name)) {
+            return new SystemMT();
+        }
+        if (SystemNRSV.name.equals(name)) {
+            return new SystemNRSV();
+        }
+        if (SystemNRSVA.name.equals(name)) {
+            return new SystemNRSVA();
+        }
+        if (SystemSynodal.name.equals(name)) {
+            return new SystemSynodal();
+        }
+        if (SystemSynodalP.name.equals(name)) {
+            return new SystemSynodalP();
+        }
         return null;
     }
 
+    /**
+     * Add a ReferenceSystem that is not predefined by JSword.
+     * 
+     * @param rs the ReferenceSystem to register
+     */
+    public synchronized void register(ReferenceSystem rs) {
+        fluffed.put(rs.getOSISName(), rs);
+        known.add(rs.getOSISName());
+    }
+
+    /**
+     * This class is a singleton, enforced by a private constructor.
+     */
     private ReferenceSystems() {
-        
+        known = new HashSet<String>();
+        known.add(SystemCatholic.name);
+        known.add(SystemCatholic2.name);
+        known.add(SystemKJV.name);
+        known.add(SystemGerman.name);
+        known.add(SystemKJVA.name);
+        known.add(SystemLeningrad.name);
+        known.add(SystemLuther.name);
+        known.add(SystemMT.name);
+        known.add(SystemNRSV.name);
+        known.add(SystemNRSVA.name);
+        known.add(SystemSynodal.name);
+        known.add(SystemSynodalP.name);
+        known.add(SystemVulg.name);
+        fluffed = new HashMap<String, ReferenceSystem>();
     }
 
-    private Map<String, ReferenceSystem> rsMap = new HashMap<String, ReferenceSystem>();
+    /**
+     * The default ReferenceSystem for JSword is the KJV.
+     * This is subject to change at any time.
+     */
+    private final String DEFAULT_REFERENCE_SYSTEM = "KJV";
+
+    /**
+     * The set of v11n names.
+     */
+    private Set<String> known;
+
+    /**
+     * The map of instantiated ReferenceSystems, given by their names.
+     */
+    private Map<String, ReferenceSystem> fluffed;
+
+    private static final ReferenceSystems instance = new ReferenceSystems();
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -32,6 +32,14 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemCatholic extends ReferenceSystem {
+
+    /**
+     * Build the "Catholic" ReferenceSystem.
+     */
+    public SystemCatholic() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "Catholic";
 
     public static BibleBook[] booksNT = SystemDefault.booksNT;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic2.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic2.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemCatholic2.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -34,6 +34,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemCatholic2 extends ReferenceSystem {
+    /**
+     * Build the "Catholic2" ReferenceSystem.
+     */
+    public SystemCatholic2() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "Catholic2";
     public static BibleBook[] booksNT = SystemDefault.booksNT;
     public static int[][] lastVerseNT = SystemCatholic.lastVerseNT;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemGerman.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemGerman.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemGerman.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -32,6 +32,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemGerman extends ReferenceSystem {
+    /**
+     * Build the "German" ReferenceSystem.
+     */
+    public SystemGerman() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "German";
     public static BibleBook[] booksNT = SystemDefault.booksNT;
     public static int[][] lastVerseNT =

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJV.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJV.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJV.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -33,6 +33,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemKJV extends ReferenceSystem {
+    /**
+     * Build the "KJV" ReferenceSystem.
+     */
+    public SystemKJV() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "KJV";
     public static BibleBook[] booksNT = SystemDefault.booksNT;
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJVA.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJVA.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemKJVA.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -32,6 +32,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemKJVA extends ReferenceSystem {
+    /**
+     * Build the "KJVA" ReferenceSystem.
+     */
+    public SystemKJVA() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "KJVA";
 
     public static BibleBook[] booksNT = SystemDefault.booksNT;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLeningrad.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLeningrad.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLeningrad.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -36,6 +36,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemLeningrad extends ReferenceSystem {
+    /**
+     * Build the "Leningrad" ReferenceSystem.
+     */
+    public SystemLeningrad() {
+        super(name, booksOT, booksNT, lastVerseOT, null);
+    }
+
     public static String name = "Leningrad";
 
     public static BibleBook[] booksNT = SystemDefault.booksNone;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLuther.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLuther.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemLuther.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -32,6 +32,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemLuther extends ReferenceSystem {
+    /**
+     * Build the "Luther" ReferenceSystem.
+     */
+    public SystemLuther() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "Luther";
 
     // Different ordering of SystemDefault.booksNT

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemMT.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemMT.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemMT.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -36,6 +36,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemMT extends ReferenceSystem {
+    /**
+     * Build the "MT" ReferenceSystem.
+     */
+    public SystemMT() {
+        super(name, booksOT, booksNT, lastVerseOT, null);
+    }
+
     public static String name = "MT";
 
     public static BibleBook[] booksNT = SystemDefault.booksNone;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSV.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSV.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSV.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -34,6 +34,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemNRSV extends ReferenceSystem {
+    /**
+     * Build the "NRSV" ReferenceSystem.
+     */
+    public SystemNRSV() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "NRSV";
     public static BibleBook[] booksNT = SystemDefault.booksNT;
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSVA.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSVA.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemNRSVA.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -32,6 +32,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemNRSVA extends ReferenceSystem {
+    /**
+     * Build the "NRSVA" ReferenceSystem.
+     */
+    public SystemNRSVA() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "NRSVA";
 
     public static BibleBook[] booksNT = SystemDefault.booksNT;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodal.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodal.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodal.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -57,6 +57,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemSynodal extends ReferenceSystem {
+    /**
+     * Build the "Synodal" ReferenceSystem.
+     */
+    public SystemSynodal() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "Synodal";
 
     // The books are the SystemDefault.booksNT

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodalP.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodalP.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemSynodalP.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -35,6 +35,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemSynodalP extends ReferenceSystem {
+    /**
+     * Build the "SynodalP" ReferenceSystem.
+     */
+    public SystemSynodalP() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "SynodalP";
     public static BibleBook[] booksNT = SystemDefault.booksNT;
     public static final int[][] lastVerseNT =

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemVulg.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemVulg.java	2012-01-23 05:07:36 UTC (rev 2219)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/system/SystemVulg.java	2012-01-24 21:46:35 UTC (rev 2220)
@@ -32,6 +32,13 @@
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class SystemVulg extends ReferenceSystem {
+    /**
+     * Build the "Vulg" ReferenceSystem.
+     */
+    public SystemVulg() {
+        super(name, booksOT, booksNT, lastVerseOT, lastVerseNT);
+    }
+
     public static String name = "Vulg";
 
     // Start with SystemDefault.booksNT




More information about the jsword-svn mailing list