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   * © CrossWire Bible Society, 2005 - 2016
18   *
19   */
20  package org.crosswire.jsword.versification;
21  
22  import java.util.HashMap;
23  import java.util.Locale;
24  import java.util.Map;
25  
26  /**
27   * A BibleBook is a book of the Bible. It may or may not be canonical.
28   * Note that the ordering of these books varies from one Versification to another.
29   *
30   * @see gnu.lgpl.License The GNU Lesser General Public License for details.
31   * @author DM Smith
32   */
33  public enum BibleBook {
34      // JSword introduction to the Bible
35      INTRO_BIBLE("Intro.Bible"),
36      // JSword introduction to the Old Testament
37      INTRO_OT("Intro.OT"),
38      // Old Testament
39      GEN("Gen"),
40      EXOD("Exod"),
41      LEV("Lev"),
42      NUM("Num"),
43      DEUT("Deut"),
44      JOSH("Josh"),
45      JUDG("Judg"),
46      RUTH("Ruth"),
47      SAM1("1Sam"),
48      SAM2("2Sam"),
49      KGS1("1Kgs"),
50      KGS2("2Kgs"),
51      CHR1("1Chr"),
52      CHR2("2Chr"),
53      EZRA("Ezra"),
54      NEH("Neh"),
55      ESTH("Esth"),
56      JOB("Job"),
57      PS("Ps"),
58      PROV("Prov"),
59      ECCL("Eccl"),
60      SONG("Song"),
61      ISA("Isa"),
62      JER("Jer"),
63      LAM("Lam"),
64      EZEK("Ezek"),
65      DAN("Dan"),
66      HOS("Hos"),
67      JOEL("Joel"),
68      AMOS("Amos"),
69      OBAD("Obad", true),
70      JONAH("Jonah"),
71      MIC("Mic"),
72      NAH("Nah"),
73      HAB("Hab"),
74      ZEPH("Zeph"),
75      HAG("Hag"),
76      ZECH("Zech"),
77      MAL("Mal"),
78      // JSword introduction to the New Testament
79      INTRO_NT("Intro.NT"),
80      // New Testament
81      MATT("Matt"),
82      MARK("Mark"),
83      LUKE("Luke"),
84      JOHN("John"),
85      ACTS("Acts"),
86      ROM("Rom"),
87      COR1("1Cor"),
88      COR2("2Cor"),
89      GAL("Gal"),
90      EPH("Eph"),
91      PHIL("Phil"),
92      COL("Col"),
93      THESS1("1Thess"),
94      THESS2("2Thess"),
95      TIM1("1Tim"),
96      TIM2("2Tim"),
97      TITUS("Titus"),
98      PHLM("Phlm", true),
99      HEB("Heb"),
100     JAS("Jas"),
101     PET1("1Pet"),
102     PET2("2Pet"),
103     JOHN1("1John"),
104     JOHN2("2John", true),
105     JOHN3("3John", true),
106     JUDE("Jude", true),
107     REV("Rev"),
108     // Apocrypha
109     TOB("Tob"),
110     JDT("Jdt"),
111     ADD_ESTH("AddEsth"),
112     WIS("Wis"),
113     SIR("Sir"),
114     BAR("Bar"),
115     EP_JER("EpJer", true),
116     PR_AZAR("PrAzar"),
117     SUS("Sus"),
118     BEL("Bel"),
119     MACC1("1Macc"),
120     MACC2("2Macc"),
121     MACC3("3Macc"),
122     MACC4("4Macc"),
123     PR_MAN("PrMan", true),
124     ESD1("1Esd"),
125     ESD2("2Esd"),
126     PSS151("Ps151"),
127     // Rahlfs' LXX
128     ODES("Odes"),
129     PSALM_SOL("PssSol"),
130     // Vulgate & other later Latin mss
131     EP_LAO("EpLao"),
132     ESD3("3Esd"),
133     ESD4("4Esd"),
134     ESD5("5Esd"),
135     // Ethiopian Orthodox Canon/Ge'ez Translation
136     EN1("1En"),
137     JUBS("Jub"),
138     BAR4("4Bar"),
139     ASCEN_ISA("AscenIsa"),
140     PS_JOS("PsJos"),
141     // Coptic Orthodox Canon
142     APOSTOLIC("AposCon"),
143     CLEM1("1Clem"),
144     CLEM2("2Clem"),
145     // Armenian Orthodox Canon
146     COR3("3Cor"),
147     EP_COR_PAUL("EpCorPaul"),
148     JOS_ASEN("JosAsen"),
149     T12PATR("T12Patr"),
150     T12PATR_TASH("T12Patr.TAsh"),
151     T12PATR_TBENJ("T12Patr.TBenj"),
152     T12PATR_TDAN("T12Patr.TDan"),
153     T12PATR_GAD("T12Patr.TGad"),
154     T12PATR_TISS("T12Patr.TIss"),
155     T12PATR_TJOS("T12Patr.TJos"),
156     T12PATR_TJUD("T12Patr.TJud"),
157     T12PATR_TLEVI("T12Patr.TLevi"),
158     T12PATR_TNAPH("T12Patr.TNaph"),
159     T12PATR_TREU("T12Patr.TReu"),
160     T12PATR_TSIM("T12Patr.TSim"),
161     T12PATR_TZeb("T12Patr.TZeb"),
162     // Peshitta
163     BAR2("2Bar"),
164     EP_BAR("EpBar"),
165     // Codex Sinaiticus
166     BARN("Barn"),
167     HERM("Herm"),
168     HERM_MAND("Herm.Mand"),
169     HERM_SIM("Herm.Sim"),
170     HERM_VIS("Herm.Vis"),
171     // Other books
172     ADD_DAN("AddDan"),
173     ADD_PS("AddPs"),
174     ESTH_GR("EsthGr");
175 
176     BibleBook(String osis, boolean shortBook) {
177         this(osis);
178         this.isShortBook = shortBook;
179     }
180 
181     BibleBook(String osis) {
182         this.osis = osis;
183     }
184 
185     /**
186      * Get the OSIS representation of this BibleBook.
187      *
188      * @return the OSIS name
189      */
190     public String getOSIS() {
191         return osis;
192     }
193 
194     /**
195      * Get the OSIS representation of this BibleBook.
196      *
197      * @return the OSIS name
198      */
199     @Override
200     public String toString() {
201         return osis;
202     }
203 
204     /**
205      * Case insensitive search for BibleBook for an OSIS name.
206      *
207      * @param osis
208      * @return the matching BibleBook or null
209      */
210     public static BibleBook fromOSIS(String osis) {
211         String match = BookName.normalize(osis, Locale.ENGLISH);
212         return osisMap.get(match);
213     }
214 
215     /**
216      * @param osis the osis book reference, case sensitive
217      * @return the corresponding BibleBook
218      */
219     public static BibleBook fromExactOSIS(String osis) {
220         return exactMatches.get(osis);
221     }
222 
223     /**
224      * @return true to indicate a 1-chapter book only
225      */
226     public boolean isShortBook() {
227         return isShortBook;
228     }
229 
230     /**
231      * The OSIS name for the book. 
232      */
233     private String osis;
234 
235     /**
236      * Indicates that the book consists of a single chapter.
237      */
238     private boolean isShortBook;
239 
240     /** A quick lookup based on OSIS name for the book */
241     private static Map<String, BibleBook> osisMap = new HashMap<String, BibleBook>(128);
242     private static Map<String, BibleBook> exactMatches = new HashMap<String, BibleBook>(128);
243 
244      static {
245         for (BibleBook book : BibleBook.values()) {
246             osisMap.put(BookName.normalize(book.getOSIS(), Locale.ENGLISH), book);
247             exactMatches.put(book.getOSIS(), book);
248         }
249     }
250 
251 }
252