| BibleInfo.java |
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 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * 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 * ID: $Id: BibleInfo.java 2223 2012-01-26 21:28:02Z dmsmith $
21 */
22 package org.crosswire.jsword.versification;
23
24 import org.crosswire.jsword.JSOtherMsg;
25 import org.crosswire.jsword.book.CaseType;
26 import org.crosswire.jsword.passage.NoSuchVerseException;
27 import org.crosswire.jsword.passage.Verse;
28 import org.crosswire.jsword.versification.system.Versifications;
29
30 /**
31 * BibleInfo is a static class that deals with Bible book names, and conversion to and from
32 * ordinal number and Verse.
33 * <p>This class is likely to be reworked in it's entirety. It is really only true
34 * of the KJV Bible. It is not true of other versifications such as Luther's.
35 * </p>
36 *
37 * @deprecated Use Versifications.instance().getDefaultVersification() instead.
38 *
39 * @see gnu.lgpl.License for license details.<br>
40 * The copyright to this program is held by it's authors.
41 * @author Joe Walker [joe at eireneh dot com]
42 * @author DM Smith [dmsmith555 at yahoo dot com]
43 */
44 @Deprecated
45 public final class BibleInfo {
46 /**
47 * constant for the old testament
48 * @deprecated use {@link Testament#OLD} instead.
49 */
50 @Deprecated
51 public static final int TESTAMENT_OLD = 0;
52
53 /**
54 * constant for the new testament
55 * @deprecated use {@link Testament#NEW} instead.
56 */
57 @Deprecated
58 public static final int TESTAMENT_NEW = 1;
59
60 /**
61 * Ensure that we can not be instantiated
62 */
63 private BibleInfo() {
64 }
65
66 /**
67 * Get the immediately following book in the current versification.
68 * @param book
69 * @return the next book or null if no following book
70 * @deprecated use Versification.getBooks().getNextBook(BibleBook) instead
71 * see {@link Versification#getBooks()} and {@link BibleBookList#getNextBook(BibleBook)}.
72 */
73 @Deprecated
74 public static BibleBook getNextBook(BibleBook book) {
75 return v11n.getBooks().getNextBook(book);
76 }
77
78 /**
79 * Get the immediately prior book in the current versification.
80 * @param book
81 * @return the previous book or null if no previous book
82 * @deprecated use Versification.getBooks().getPreviousBook(BibleBook) instead
83 * see {@link Versification#getBooks()} and {@link BibleBookList#getPreviousBook(BibleBook)}.
84 */
85 @Deprecated
86 public static BibleBook getPreviousBook(BibleBook book) {
87 return v11n.getBooks().getPreviousBook(book);
88 }
89
90 /**
91 * Get the ordered array of books belonging to this versification.
92 * This includes the 3 introductions.
93 *
94 * @return the array of books
95 * @deprecated use {@link Versification#getBooks()} instead
96 */
97 @Deprecated
98 public static BibleBook[] getBooks() {
99 return BibleBook.getBooks();
100 }
101
102 /**
103 * Get the last valid chapter number for a book.
104 *
105 * @param book
106 * The book part of the reference.
107 * @return The last valid chapter number for a book.
108 * @deprecated use {@link Versification#getLastChapter(BibleBook)} instead
109 */
110 @Deprecated
111 public static int chaptersInBook(BibleBook book) {
112 return v11n.getLastChapter(book);
113 }
114
115 /**
116 * Get the last valid verse number for a chapter.
117 *
118 * @param book
119 * The book part of the reference.
120 * @param chapter
121 * The current chapter
122 * @return The last valid verse number for a chapter
123 * If the book or chapter number is not valid
124 * @deprecated use {@link Versification#getLastVerse(BibleBook, int)} instead
125 */
126 @Deprecated
127 public static int versesInChapter(BibleBook book, int chapter) {
128 return v11n.getLastVerse(book, chapter);
129 }
130
131 /**
132 * The maximum number of verses in the Bible, including module, testament, book and chapter introductions.
133 *
134 * @return the number of addressable verses in this versification.
135 * @deprecated use {@link Versification#maximumOrdinal()} instead
136 */
137 @Deprecated
138 public static int maximumOrdinal() {
139 return v11n.maximumOrdinal();
140 }
141
142 /**
143 * Where does this verse come in the Bible. The value that this returns should be treated as opaque, useful for a bit set.
144 * The introductions to the Book, OT/NT Testaments, Bible books and chapters are included here.
145 * <ul>
146 * <li>0 - INTRO_BIBLE 0:0 - The Book introduction</li>
147 * <li>1 - INTRO_OT 0:0 - The OT Testament introduction</li>
148 * <li>2 - Gen 0:0 - The introduction to the book of Genesis</li>
149 * <li>3 - Gen 1:0 - The introduction to Genesis chapter 1</li>
150 * <li>4 - Gen 1:1</li>
151 * <li>...</li>
152 * <li>35 - Gen 1:31</li>
153 * <li>36 - Gen 2:0 - The introduction to Genesis chapter 2</li>
154 * <li>37 - Gen 2:1</li>
155 * <li>...</li>
156 * <li>n - last verse in the OT</li>
157 * <li>n + 1 - INTRO_NT, 0, 0 - The New Testament introduction</li>
158 * <li>n + 2 - Matt 0:0 - The introduction to Matt</li>
159 * <li>n + 3 - Matt 1:0 - The introduction to Matt 1</li>
160 * <li>n + 4 - Matt 1:1</li>
161 * <li>...</li>
162 * </ul>
163 *
164 * @param verse
165 * The verse to convert
166 * @return The ordinal number of verses
167 * @deprecated use {@link Versification#getOrdinal()} instead
168 */
169 @Deprecated
170 public static int getOrdinal(Verse verse) {
171 return v11n.getOrdinal(verse);
172 }
173
174 /**
175 * Where does this verse come in the Bible. The value that this returns should be treated as opaque, useful for a bit set.
176 * The introductions to the Book, OT/NT Testaments, Bible books and chapters are included here.
177 * <ul>
178 * <li>0 - INTRO_BIBLE 0:0 - The Book introduction</li>
179 * <li>1 - INTRO_OT 0:0 - The OT Testament introduction</li>
180 * <li>2 - Gen 0:0 - The introduction to the book of Genesis</li>
181 * <li>3 - Gen 1:0 - The introduction to Genesis chapter 1</li>
182 * <li>4 - Gen 1:1</li>
183 * <li>...</li>
184 * <li>35 - Gen 1:31</li>
185 * <li>36 - Gen 2:0 - The introduction to Genesis chapter 2</li>
186 * <li>37 - Genesis 2:1</li>
187 * <li>...</li>
188 * <li>n - last verse in the OT</li>
189 * <li>0 - INTRO_NT, 0, 0 - The New Testament introduction</li>
190 * <li>1 - Matt 0:0 - The introduction to Matt</li>
191 * <li>2 - Matt 1:0 - The introduction to Matt 1</li>
192 * <li>3 - Matt 1:1</li>
193 * <li>...</li>
194 * </ul>
195 *
196 * @param verse
197 * The verse to convert
198 * @return The ordinal number of verses
199 * @deprecated use {@link Versification#getTestamentOrdinal()} instead
200 */
201 @Deprecated
202 public static int getTestamentOrdinal(int ordinal) {
203 return v11n.getTestamentOrdinal(ordinal);
204 }
205
206 /**
207 * Get the testament of a given verse
208 * @deprecated use {@link Versification#getTestament(int)} instead
209 */
210 @Deprecated
211 public static Testament getTestament(int ordinal) {
212 return v11n.getTestament(ordinal);
213 }
214
215 /**
216 * Give the count of verses in the testament or the whole Bible.
217 *
218 * @param testament The testament to count. If null, then all testaments.
219 * @return the number of verses in the testament
220 * @deprecated use {@link Versification#getCount(Testament)} instead
221 */
222 @Deprecated
223 public static int getCount(Testament testament) {
224 return v11n.getCount(testament);
225 }
226
227 /**
228 * Where does this verse come in the Bible. This will unwind the value returned by getOrdinal(Verse).
229 *
230 * @param ordinal
231 * The ordinal number of the verse
232 * @return A Verse
233 * @exception NoSuchVerseException
234 * If the reference is illegal
235 * @deprecated use {@link Versification#decodeOrdinal(int)} instead
236 */
237 @Deprecated
238 public static Verse decodeOrdinal(int ordinal) {
239 return v11n.decodeOrdinal(ordinal);
240 }
241
242 /**
243 * Does the following represent a real verse?. It is code like this that
244 * makes me wonder if I18 is done well/worth doing. All this code does is
245 * check if the numbers are valid, but the exception handling code is huge
246 * :(
247 *
248 * @param book
249 * The book part of the reference.
250 * @param chapter
251 * The chapter part of the reference.
252 * @param verse
253 * The verse part of the reference.
254 * @exception NoSuchVerseException
255 * If the reference is illegal
256 * @deprecated use {@link Versification#validate(BibleBook, int, int)} instead
257 */
258 @Deprecated
259 public static void validate(BibleBook book, int chapter, int verse) throws NoSuchVerseException {
260 v11n.validate(book, chapter, verse);
261 }
262
263 /**
264 * Fix up these verses so that they are as valid a possible. This is
265 * currently done so that we can say "Gen 1:1" + 31 = "Gen 1:32" and
266 * "Gen 1:32".patch() is "Gen 2:1".
267 * <p>
268 * There is another patch system that allows us to use large numbers to mean
269 * "the end of" so "Gen 1:32".otherPatch() gives "Gen 1:31". This could be
270 * useful to allow the user to enter things like "Gen 1:99" meaning the end
271 * of the chapter. Or "Isa 99:1" to mean the last chapter in Isaiah verse 1
272 * or even "Rev 99:99" to mean the last verse in the Bible.
273 * <p>
274 * However I have not implemented this because I've used a different
275 * convention: "Gen 1:$" (OLB compatible) or "Gen 1:ff" (common commentary
276 * usage) to mean the end of the chapter - So the functionality is there
277 * anyway.
278 * <p>
279 * I think that getting into the habit of typing "Gen 1:99" is bad. It could
280 * be the source of surprises "Psa 119:99" is not what you'd might expect,
281 * and neither is "Psa 99:1" is you wanted the last chapter in Psalms -
282 * expecting us to type "Psa 999:1" seems like we're getting silly.
283 * <p>
284 * However despite this maybe we should provide the functionality anyway.
285 *
286 * @param book the book to obtain
287 * @param chapter the supposed chapter
288 * @param verse the supposed verse
289 * @return The resultant verse.
290 * @deprecated use {@link Versification#patch(BibleBook, int, int)} instead
291 */
292 @Deprecated
293 public static Verse patch(BibleBook book, int chapter, int verse) {
294 return v11n.patch(book, chapter, verse);
295 }
296
297 /**
298 * Count the books in the Bible.
299 *
300 * @return The number of books in the Bible, including the three introductions
301 * @deprecated use {@link Versification#getBooks()} and {@link BibleBookList#getBookCount()} instead
302 */
303 @Deprecated
304 public static int booksInBible() {
305 return v11n.getBooks().getBookCount();
306 }
307
308 private static Versification v11n = Versifications.instance().getDefaultVersification();
309
310 /**
311 * Get the BookName.
312 * This is merely a convenience function that validates that book is not null,
313 * throwing NoSuchVerseException if it is.
314 *
315 * @param book
316 * The book of the Bible
317 * @return The requested BookName
318 * @exception NoSuchVerseException
319 * If the book is not valid
320 * @deprecated Use {@link BibleBook#getBookName()} instead.
321 */
322 @Deprecated
323 public static BookName getBookName(BibleBook book) throws NoSuchVerseException {
324 try {
325 return book.getBookName();
326 } catch (NullPointerException ex) {
327 throw new NoSuchVerseException(JSOtherMsg.lookupText("Book must not be null"));
328 }
329 }
330
331 /**
332 * Get number of a book from its name.
333 *
334 * @param find
335 * The string to identify
336 * @return The BibleBook, On error null
337 * @deprecated use {@link BibleBook#getBook(String)}
338 */
339 @Deprecated
340 public static BibleBook getBook(String find) {
341 return BibleBook.getBook(find);
342 }
343
344 /**
345 * Is the given string a valid book name. If this method returns true then
346 * getBook() will return a BibleBook and not throw an exception.
347 *
348 * @param find
349 * The string to identify
350 * @return true when the book name is recognized
351 * @deprecated use {@link BibleBook#isBook(String)}
352 */
353 @Deprecated
354 public static boolean isBookName(String find) {
355 return BibleBook.isBook(find);
356 }
357
358 /**
359 * Count the chapters in the Bible.
360 *
361 * @return 1189 always - the number of chapters in the Bible
362 * @deprecated do not use
363 */
364 @Deprecated
365 public static int chaptersInBible() {
366 return 1189;
367 }
368
369 /**
370 * The maximum number of verses in the Bible, including module, testament, book and chapter introductions.
371 * Note: it used to exclude introductions.
372 *
373 * @return the number of addressable verses in this versification.
374 * @deprecated use {@link BibleInfo#maximumOrdinal()}
375 */
376 @Deprecated
377 public static int versesInBible() {
378 return maximumOrdinal();
379 }
380
381 /**
382 * Get the preferred name of a book. Altered by the case setting (see
383 * setBookCase() and isFullBookName())
384 * This is merely a convenience function that validates that book is not null,
385 * throwing NoSuchVerseException if it is.
386 *
387 * @param book
388 * The book of the Bible
389 * @return The full name of the book
390 * @exception NoSuchVerseException
391 * If the book is not valid
392 * @deprecated Use {@link BibleBook#getPreferredName()} instead.
393 */
394 @Deprecated
395 public static String getPreferredBookName(BibleBook book) throws NoSuchVerseException {
396 try {
397 return book.getPreferredName();
398 } catch (NullPointerException ex) {
399 throw new NoSuchVerseException(JSOtherMsg.lookupText("Book must not be null"));
400 }
401 }
402
403 /**
404 * Get the full name of a book (e.g. "Genesis"). Altered by the case setting
405 * (see setBookCase())
406 * This is merely a convenience function that validates that book is not null,
407 * throwing NoSuchVerseException if it is.
408 *
409 * @param book
410 * The book of the Bible
411 * @return The full name of the book
412 * @exception NoSuchVerseException
413 * If the book is not valid
414 * @deprecated Use {@link BibleBook#getLongName()} instead.
415 */
416 @Deprecated
417 public static String getLongBookName(BibleBook book) throws NoSuchVerseException {
418 try {
419 return book.getLongName();
420 } catch (NullPointerException ex) {
421 throw new NoSuchVerseException(JSOtherMsg.lookupText("Book must not be null"));
422 }
423 }
424
425 /**
426 * Get the short name of a book (e.g. "Gen"). Altered by the case setting
427 * (see setBookCase())
428 * This is merely a convenience function that validates that book is not null,
429 * throwing NoSuchVerseException if it is.
430 *
431 * @param book
432 * The book of the Bible
433 * @return The short name of the book
434 * @exception NoSuchVerseException
435 * If the book is not valid
436 * @deprecated Use {@link BibleBook#getShortName()} instead.
437 */
438 @Deprecated
439 public static String getShortBookName(BibleBook book) throws NoSuchVerseException {
440 try {
441 return book.getShortName();
442 } catch (NullPointerException ex) {
443 throw new NoSuchVerseException(JSOtherMsg.lookupText("Book must not be null"));
444 }
445 }
446
447 /**
448 * Get the OSIS name for a book.
449 * This is merely a convenience function that validates that book is not null,
450 * throwing NoSuchVerseException if it is.
451 *
452 * @param book
453 * The book of the Bible
454 * @return the OSIS defined short name for a book
455 * @exception NoSuchVerseException
456 * If the book is not valid
457 * @deprecated Use {@link BibleBook#getOSIS()} instead.
458 */
459 @Deprecated
460 public static String getOSISName(BibleBook book) throws NoSuchVerseException {
461 try {
462 return book.getOSIS();
463 } catch (NullPointerException ex) {
464 throw new NoSuchVerseException(JSOtherMsg.lookupText("Book must not be null"));
465 }
466 }
467
468 /**
469 * How many verses between verse1 and verse2 (inclusive).
470 *
471 * @param verse1
472 * The earlier verse.
473 * @param verse2
474 * The later verse.
475 * @return the number of verses
476 * @exception NoSuchVerseException
477 * If either reference is illegal
478 * @deprecated Use {@link Versification#subtract(Verse, Verse)} instead.
479 */
480 @Deprecated
481 public static int verseCount(Verse verse1, Verse verse2) throws NoSuchVerseException {
482 return verse2.subtract(verse1) + 1;
483 }
484
485 /**
486 * This is only used by config.
487 *
488 * @param bookCase
489 * The new case to use for reporting book names
490 * @exception IllegalArgumentException
491 * If the case is not between 0 and 2
492 * @see #getCase()
493 * @deprecated use {@link BookName#setCase(int)}
494 */
495 @Deprecated
496 public static void setCase(int bookCase) {
497 BookName.setCase(bookCase);
498 }
499
500 /**
501 * This is only used by config
502 *
503 * @return The current case setting
504 * @see #setCase(CaseType)
505 * @deprecated use {@link BookName#getCase()}
506 */
507 @Deprecated
508 public static int getCase() {
509 return BookName.getCase();
510 }
511
512 /**
513 * How do we report the names of the books?. These are static. This is on
514 * the assumption that we will not want to have different sections of the
515 * app using a different format. I expect this to be a good assumption, and
516 * it saves passing a Book class around everywhere. CaseType.MIXED is not
517 * allowed
518 *
519 * @param newBookCase
520 * The new case to use for reporting book names
521 * @exception IllegalArgumentException
522 * If the case is not between 0 and 2
523 * @see #getCase()
524 * @deprecated use {@link BookName#setCase(CaseType)}
525 */
526 @Deprecated
527 public static void setCase(CaseType newBookCase) {
528 BookName.setCase(newBookCase);
529 }
530
531 /**
532 * This is only used by config
533 *
534 * @return Whether the name is long or short. Default is Full (true).
535 * @see #setFullBookName(boolean)
536 * @deprecated use {@link BookName#isFullBookName()}
537 */
538 @Deprecated
539 public static boolean isFullBookName() {
540 return BookName.isFullBookName();
541 }
542
543 /**
544 * Set whether the name should be full or abbreviated, long or short.
545 *
546 * @param fullName
547 * The new case to use for reporting book names
548 * @see #isFullBookName()
549 * @deprecated use {@link BookName#setFullBookName(boolean)}
550 */
551 @Deprecated
552 public static void setFullBookName(boolean fullName) {
553 BookName.setFullBookName(fullName);
554 }
555
556 /**
557 * How do we report the names of the books?.
558 *
559 * @return The current case setting
560 * @see #setCase(int)
561 * @deprecated use {@link BookName#getDefaultCase()}
562 */
563 @Deprecated
564 public static CaseType getDefaultCase() {
565 return BookName.getDefaultCase();
566 }
567
568 }
569