1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 or later
5    * as published by the Free Software Foundation. This program is distributed
6    * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7    * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005 - 2012
18   *     The copyright to this program is held by it's authors.
19   *
20   */
21  package org.crosswire.jsword.versification;
22  
23  import org.crosswire.jsword.JSMsg;
24  
25  /**
26   * DivisionName deals with traditional sections of the Bible.
27   * 
28   * AV11N(DMS): Is this right?
29   * <ul>
30   * <li><strong>contains(BibleBook)</strong> - This has several problems:
31   * <ol>
32   * <li>The use of BibleBook.ordinal() is dependent upon the ordering of the
33   * members of the BibleBook enum. Currently it is ordered OT and NT according to
34   * the KJV and then has the deuterocanonical and apocryphal books in no
35   * particular order.</li>
36   * <li>Each versification defines the what books are present and the order of
37   * books. So for one versification, GEN might not be the first and REV might not
38   * be the last. E.g. Some V11Ns consist only of the OT.</li>
39   * </ol>
40   * </li>
41   * <li><strong>getSize()</strong> - This can vary by versification for at least
42   * BIBLE, OT and NT for those that include deuterocanonical or apocryphal books.
43   * </li>
44   * <li><strong>getRange()</strong> - This range is fixed text giving end points
45   * that may include BibleBooks that are not intended and may exclude BibleBooks
46   * that are intended. It works for the default Versification and may not work
47   * for others.</li>
48   * <li>A given V11N might be a single testament or just the gospels. In this case,
49   * it'd be good to know whether a division isDefined()</li>
50   * </ul>
51   * 
52   * @see gnu.lgpl.License for license details.<br>
53   *      The copyright to this program is held by it's authors.
54   * @author Joe Walker [joe at eireneh dot com]
55   * @author DM Smith
56   */
57  public enum DivisionName {
58      /** BIBLE consists of the entire/whole Bible (Gen - Rev) **/
59      BIBLE {
60          @Override
61          public boolean contains(BibleBook book) {
62              int bookNum = book.ordinal();
63              return bookNum >= BibleBook.GEN.ordinal() && bookNum <= BibleBook.REV.ordinal();
64          }
65  
66          @Override
67          public int getSize() {
68              return 66;
69          }
70  
71          @Override
72          public String getName() {
73              // TRANSLATOR: The entire/whole Bible (Gen - Rev)
74              return JSMsg.gettext("The Whole Bible");
75          }
76  
77          @Override
78          public String getRange() {
79              return "Gen-Rev";
80          }
81  
82      },
83      /** OLD_TESTAMENT consists of the old testament (Gen - Mal) **/
84      OLD_TESTAMENT {
85          @Override
86          public boolean contains(BibleBook book) {
87              int bookNum = book.ordinal();
88              return bookNum >= BibleBook.GEN.ordinal() && bookNum <= BibleBook.MAL.ordinal();
89          }
90  
91          @Override
92          public int getSize() {
93              return 39;
94          }
95  
96          @Override
97          public String getName() {
98              // TRANSLATOR: The old testament (Gen - Mal)
99              return JSMsg.gettext("Old Testament");
100         }
101 
102         @Override
103         public String getRange() {
104             return "Gen-Mal";
105         }
106     },
107     /** PENTATEUCH consists of the 5 books of Moses (Gen - Deu) **/
108     PENTATEUCH {
109         @Override
110         public boolean contains(BibleBook book) {
111             int bookNum = book.ordinal();
112             return bookNum >= BibleBook.GEN.ordinal() && bookNum <= BibleBook.DEUT.ordinal();
113         }
114 
115         @Override
116         public int getSize() {
117             return 5;
118         }
119 
120         @Override
121         public String getName() {
122             // TRANSLATOR: Pentateuch is the first 5 books of the Bible.
123             return JSMsg.gettext("Pentateuch");
124         }
125 
126         @Override
127         public String getRange() {
128             return "Gen-Deu";
129         }
130     },
131     /** HISTORY consists of the history in the Old Testament of Israel */
132     HISTORY {
133         @Override
134         public boolean contains(BibleBook book) {
135             int bookNum = book.ordinal();
136             return bookNum >= BibleBook.JOSH.ordinal() && bookNum <= BibleBook.ESTH.ordinal();
137         }
138 
139         @Override
140         public int getSize() {
141             return 12;
142         }
143 
144         @Override
145         public String getName() {
146             // TRANSLATOR: History are the books of the Old Testament that give the history of Israel
147             return JSMsg.gettext("History");
148         }
149 
150         @Override
151         public String getRange() {
152             return "Jos-Est";
153         }
154     },
155     /** POETRY consists of the poetic works (Job-Song) */
156     POETRY {
157         @Override
158         public boolean contains(BibleBook book) {
159             int bookNum = book.ordinal();
160             return bookNum >= BibleBook.JOB.ordinal() && bookNum <= BibleBook.SONG.ordinal();
161         }
162 
163         @Override
164         public int getSize() {
165             return 5;
166         }
167 
168         @Override
169         public String getName() {
170             // TRANSLATOR: The poetic works of the Bible consisting of:
171             // Job, Psalms, Proverbs, Ecclesiastes, and Song of Solomon
172             return JSMsg.gettext("Poetry");
173         }
174 
175         @Override
176         public String getRange() {
177             return "Job-Song";
178         }
179     },
180     /** PROPHECY consists of the Deu 28, major prophets, minor prophets, Revelation (Isa-Mal, Rev) */
181     PROPHECY {
182         @Override
183         public boolean contains(BibleBook book) {
184             int bookNum = book.ordinal();
185             return bookNum == BibleBook.REV.ordinal() || bookNum >= BibleBook.ISA.ordinal() && bookNum <= BibleBook.MAL.ordinal();
186         }
187 
188         @Override
189         public int getSize() {
190             return 18;
191         }
192 
193         @Override
194         public String getName() {
195             // TRANSLATOR: A division of the Bible containing prophecy:
196             // Deuteronomy 28
197             // Major Prophets: Isaiah, Jeremiah, Lamentations, Ezekiel, Daniel
198             // Minor Prophets: Hosea, Joel, Amos, Obadiah, Jonah, Micah, Nahum,
199             //                 Habakkuk, Zephaniah, Haggai, Zechariah, Malachi 
200             // Revelation
201             return JSMsg.gettext("All Prophecy");
202         }
203 
204         @Override
205         public String getRange() {
206             return "Deu 28,Isa-Mal,Rev";
207         }
208     },
209     /** MAJOR_PROPHETS consists of the major prophets (Isa-Dan) */
210     MAJOR_PROPHETS {
211         @Override
212         public boolean contains(BibleBook book) {
213             int bookNum = book.ordinal();
214             return bookNum >= BibleBook.ISA.ordinal() && bookNum <= BibleBook.DAN.ordinal();
215         }
216 
217         @Override
218         public int getSize() {
219             return 5;
220         }
221 
222         @Override
223         public String getName() {
224             // TRANSLATOR: A division of the Bible containing the major prophets (Isa-Dan)
225             // Isaiah, Jeremiah, Lamentations, Ezekiel, Daniel 
226             return JSMsg.gettext("Major Prophets");
227         }
228 
229         @Override
230         public String getRange() {
231             return "Isa-Dan";
232         }
233     },
234     /** MINOR_PROPHETS consists of the minor prophets (Hos-Mal) */
235     MINOR_PROPHETS {
236         @Override
237         public boolean contains(BibleBook book) {
238             int bookNum = book.ordinal();
239             return bookNum >= BibleBook.HOS.ordinal() && bookNum <= BibleBook.MAL.ordinal();
240         }
241 
242         @Override
243         public int getSize() {
244             return 12;
245         }
246 
247         @Override
248         public String getName() {
249             // TRANSLATOR: A division of the Bible containing the minor prophets (Hos-Mal)
250             // Hosea, Joel, Amos, Obadiah, Jonah, Micah, Nahum, 
251             // Habakkuk, Zephaniah, Haggai, Zechariah, Malachi 
252             return JSMsg.gettext("Minor Prophets");
253         }
254 
255         @Override
256         public String getRange() {
257             return "Hos-Mal";
258         }
259     },
260     /** NEW_TESTAMENT consists of the new testament (Mat - Rev) **/
261     NEW_TESTAMENT {
262         @Override
263         public boolean contains(BibleBook book) {
264             int bookNum = book.ordinal();
265             return bookNum >= BibleBook.GEN.ordinal() && bookNum <= BibleBook.REV.ordinal();
266         }
267 
268         @Override
269         public int getSize() {
270             return 27;
271         }
272 
273         @Override
274         public String getName() {
275             // TRANSLATOR: The New Testament (Mat - Rev)
276             return JSMsg.gettext("New Testament");
277         }
278 
279         @Override
280         public String getRange() {
281             return "Mat-Rev";
282         }
283     },
284     /** GOSPELS_AND_ACTS consists of the 4 Gospels and Acts (Mat-Acts) */
285     GOSPELS_AND_ACTS {
286         @Override
287         public boolean contains(BibleBook book) {
288             int bookNum = book.ordinal();
289             return bookNum >= BibleBook.MATT.ordinal() && bookNum <= BibleBook.ACTS.ordinal();
290         }
291 
292         @Override
293         public int getSize() {
294             return 5;
295         }
296 
297         @Override
298         public String getName() {
299             // TRANSLATOR: A division of the Bible containing the 4 Gospels and Acts (Mat-Acts)
300             // Matthew, Mark, Luke, John, Acts
301             return JSMsg.gettext("Gospels and Acts");
302         }
303 
304         @Override
305         public String getRange() {
306             return "Mat-Acts";
307         }
308     },
309     /** LETTERS consists of the letters/epistles (Rom-Jud) */
310     LETTERS {
311         @Override
312         public boolean contains(BibleBook book) {
313             int bookNum = book.ordinal();
314             return bookNum >= BibleBook.ROM.ordinal() && bookNum <= BibleBook.JUDE.ordinal();
315         }
316 
317         @Override
318         public int getSize() {
319             return 21;
320         }
321 
322         @Override
323         public String getName() {
324             // TRANSLATOR: A division of the Bible containing the letters/epistles (Rom-Jud)
325             // Pauline: Romans, 1&2 Corinthians, Galatians, Ephesians, Philippians, Colossians,
326             //          1&2 Thessalonians, 1&2 Timothy, Titus, Philemon, Hebrews
327             // General: James, 1-2 Peter, 1-3 John, Jude
328             return JSMsg.gettext("Letters");
329         }
330 
331         @Override
332         public String getRange() {
333             return "Rom-Jud";
334         }
335     },
336     /** LETTERS consists of the Pauline letters/epistles (Rom-Heb) */
337     PAULINE_LETTERS {
338         @Override
339         public boolean contains(BibleBook book) {
340             int bookNum = book.ordinal();
341             return bookNum >= BibleBook.ROM.ordinal() && bookNum <= BibleBook.JUDE.ordinal();
342         }
343 
344         @Override
345         public int getSize() {
346             return 14;
347         }
348 
349         @Override
350         public String getName() {
351             // TRANSLATOR: A division of the Bible containing the Pauline letters/epistles (Rom-Heb)
352             // Romans, 1-2 Corinthians, Galatians, Ephesians, Philippians, Colossians,
353             // 1-2 Thessalonians, 1-2 Timothy, Titus, Philemon, Hebrews
354             return JSMsg.gettext("Letters to People");
355         }
356 
357         @Override
358         public String getRange() {
359             return "Rom-Heb";
360         }
361     },
362     /** LETTERS consists of the general letters/epistles (Jas-Jud) */
363     GENERAL_LETTERS {
364         @Override
365         public boolean contains(BibleBook book) {
366             int bookNum = book.ordinal();
367             return bookNum >= BibleBook.JAS.ordinal() && bookNum <= BibleBook.JUDE.ordinal();
368         }
369 
370         @Override
371         public int getSize() {
372             return 7;
373         }
374 
375         @Override
376         public String getName() {
377             // TRANSLATOR: A division of the Bible containing the general letters/epistles (Jas-Jud)
378             // James, 1-2 Peter, 1-3 John, Jude
379             return JSMsg.gettext("Letters from People");
380         }
381 
382         @Override
383         public String getRange() {
384             return "Jas-Jud";
385         }
386     },
387     /** REVELATION consists of the book of Revelation (Rev) */
388     REVELATION {
389         @Override
390         public boolean contains(BibleBook book) {
391             return book == BibleBook.REV;
392         }
393 
394         @Override
395         public int getSize() {
396             return 1;
397         }
398 
399         @Override
400         public String getName() {
401             // TRANSLATOR: A division of the Bible containing the book of Revelation (Rev)
402             return JSMsg.gettext("Revelation");
403         }
404 
405         @Override
406         public String getRange() {
407             return "Rev";
408         }
409     };
410 
411     /**
412      * Determine whether the book is contained within the section.
413      * @param book
414      * @return true if the book is contained within the division
415      */
416     public abstract boolean contains(BibleBook book);
417 
418     /**
419      * Get the number of whole books in the section.
420      * @return the number of whole books in the section
421      */
422     public abstract int getSize();
423 
424     /**
425      * Obtain a localized string description of the section.
426      * @return the localized name.
427      */
428     public abstract String getName();
429 
430     /**
431      * Obtain a string representation of the scope of the section.
432      * @return the localized name.
433      */
434     public abstract String getRange();
435 
436     @Override
437     public String toString() {
438         return getName();
439     }
440 
441     /**
442      * Determine the section to which this book belongs.
443      * 
444      * @param book The book to test
445      * @return the section
446      */
447     public static DivisionName getSection(BibleBook book) {
448         // Ordered by section size for speed
449         if (LETTERS.contains(book)) {
450             return LETTERS;
451         }
452 
453         if (HISTORY.contains(book)) {
454             return HISTORY;
455         }
456 
457         if (MINOR_PROPHETS.contains(book)) {
458             return MINOR_PROPHETS;
459         }
460 
461         if (GOSPELS_AND_ACTS.contains(book)) {
462             return GOSPELS_AND_ACTS;
463         }
464 
465         if (PENTATEUCH.contains(book)) {
466             return PENTATEUCH;
467         }
468 
469         if (POETRY.contains(book)) {
470             return POETRY;
471         }
472 
473         if (MAJOR_PROPHETS.contains(book)) {
474             return MAJOR_PROPHETS;
475         }
476 
477         // AAV11N(DMS): might not be true
478         return REVELATION;
479     }
480 
481     /**
482      * Handy section finder. There is a bit of moderately bad programming here
483      * because org.crosswire.biblemapper.sw*ng.GroupVerseColor uses these
484      * numbers as an index into an array, so we shouldn't change these numbers
485      * without fixing that, however I don't imagine that this section could ever
486      * change without breaking GroupVerseColor anyway so I don't see it as a big
487      * problem.
488     public static final byte PENTATEUCH = 1;
489     public static final byte HISTORY = 2;
490     public static final byte POETRY = 3;
491     public static final byte MAJOR_PROPHETS = 4;
492     public static final byte MINOR_PROPHETS = 5;
493     public static final byte GOSPELS_AND_ACTS = 6;
494     public static final byte LETTERS = 7;
495     public static final byte REVELATION = 8;
496      */
497 
498     /** Constant for the number of sections in the Bible
499     private static final int SECTIONS_IN_BIBLE = 8;
500      */
501 }
502