private void store( ResourceBundle resources, BibleBook book, Map fullMap, Map shortMap, Map altMap) { String osisName = book.getOSIS(); String fullBook = getString(resources, osisName + FULL_KEY); String shortBook = getString(resources, osisName + SHORT_KEY); if (shortBook.length() == 0) { shortBook = fullBook; } String altBook = getString(resources, osisName + ALT_KEY); BookName bookName = new BookName(locale, BibleBook.fromOSIS(osisName), fullBook, shortBook, altBook); books.put(book, bookName); fullMap.put(bookName.getNormalizedLongName(), bookName); shortMap.put(bookName.getNormalizedShortName(), bookName); String[] alternates = StringUtil.split(BookName.normalize(altBook, locale), ','); for (int j = 0; j < alternates.length; j++) { altMap.put(alternates[j], bookName); } }
/** * Load up the resources for Bible book and section names, and cache the upper and lower * versions of them. */ private void initialize() { int ntCount = 0; int otCount = 0; int ncCount = 0; BibleBook[] bibleBooks = BibleBook.values(); for (BibleBook book : bibleBooks) { int ordinal = book.ordinal(); if (ordinal > BibleBook.INTRO_OT.ordinal() && ordinal < BibleBook.INTRO_NT.ordinal()) { ++ntCount; } else if (ordinal > BibleBook.INTRO_NT.ordinal() && ordinal <= BibleBook.REV.ordinal()) { ++otCount; } else { ++ncCount; } } // Create the book name maps books = new LinkedHashMap<BibleBook, BookName>(ntCount + otCount + ncCount); String className = BibleNames.class.getName(); String shortClassName = ClassUtil.getShortClassName(className); ResourceBundle resources = ResourceBundle.getBundle( shortClassName, locale, CWClassLoader.instance(BibleNames.class)); fullNT = new HashMap<String, BookName>(ntCount); shortNT = new HashMap<String, BookName>(ntCount); altNT = new HashMap<String, BookName>(ntCount); for (int i = BibleBook.MATT.ordinal(); i <= BibleBook.REV.ordinal(); ++i) { BibleBook book = bibleBooks[i]; store(resources, book, fullNT, shortNT, altNT); } fullOT = new HashMap<String, BookName>(otCount); shortOT = new HashMap<String, BookName>(otCount); altOT = new HashMap<String, BookName>(otCount); for (int i = BibleBook.GEN.ordinal(); i <= BibleBook.MAL.ordinal(); ++i) { BibleBook book = bibleBooks[i]; store(resources, book, fullOT, shortOT, altOT); } fullNC = new HashMap<String, BookName>(ncCount); shortNC = new HashMap<String, BookName>(ncCount); altNC = new HashMap<String, BookName>(ncCount); store(resources, BibleBook.INTRO_BIBLE, fullNC, shortNC, altNC); store(resources, BibleBook.INTRO_OT, fullNC, shortNC, altNC); store(resources, BibleBook.INTRO_NT, fullNC, shortNC, altNC); for (int i = BibleBook.REV.ordinal() + 1; i < bibleBooks.length; ++i) { BibleBook book = bibleBooks[i]; store(resources, book, fullNC, shortNC, altNC); } }
/** * Get a book from its name. * * @param find The string to identify * @return The BibleBook, On error null */ public BibleBook getBook(String find) { BibleBook book = null; if (containsLetter(find)) { book = BibleBook.fromOSIS(find); if (book == null) { book = getLocalizedBibleNames().getBook(find, false); } if (book == null) { book = englishBibleNames.getBook(find, false); } if (book == null) { book = getLocalizedBibleNames().getBook(find, true); } if (book == null) { book = englishBibleNames.getBook(find, true); } } return book; }