@Test public void testIndexToPosition() { Assert.assertEquals(0, VerseHelper.indexToPosition(0, 0)); Assert.assertEquals(49, VerseHelper.indexToPosition(0, 49)); Assert.assertEquals(50, VerseHelper.indexToPosition(1, 0)); Assert.assertEquals(55, VerseHelper.indexToPosition(1, 5)); Assert.assertEquals(1188, VerseHelper.indexToPosition(65, 21)); }
static int indexToPosition(int bookIndex, int chapterIndex) throws IllegalArgumentException { final int bookCount = Bible.getBookCount(); if (bookIndex < 0 || bookIndex >= bookCount) { throw new IllegalArgumentException("Invalid book index: " + bookIndex); } final int chapterCount = Bible.getChapterCount(bookIndex); if (chapterIndex < 0 || chapterIndex >= chapterCount) { throw new IllegalArgumentException("Invalid chapter index: " + chapterIndex); } int position = 0; for (int i = 0; i < bookIndex; ++i) { position += Bible.getChapterCount(i); } return position + chapterIndex; }
VerseHelper { static int indexToPosition(int bookIndex, int chapterIndex) throws IllegalArgumentException { final int bookCount = Bible.getBookCount(); if (bookIndex < 0 || bookIndex >= bookCount) { throw new IllegalArgumentException("Invalid book index: " + bookIndex); } final int chapterCount = Bible.getChapterCount(bookIndex); if (chapterIndex < 0 || chapterIndex >= chapterCount) { throw new IllegalArgumentException("Invalid chapter index: " + chapterIndex); } int position = 0; for (int i = 0; i < bookIndex; ++i) { position += Bible.getChapterCount(i); } return position + chapterIndex; } }
VerseHelper { static int indexToPosition(int bookIndex, int chapterIndex) throws IllegalArgumentException { final int bookCount = Bible.getBookCount(); if (bookIndex < 0 || bookIndex >= bookCount) { throw new IllegalArgumentException("Invalid book index: " + bookIndex); } final int chapterCount = Bible.getChapterCount(bookIndex); if (chapterIndex < 0 || chapterIndex >= chapterCount) { throw new IllegalArgumentException("Invalid chapter index: " + chapterIndex); } int position = 0; for (int i = 0; i < bookIndex; ++i) { position += Bible.getChapterCount(i); } return position + chapterIndex; }  }
VerseHelper { static int indexToPosition(int bookIndex, int chapterIndex) throws IllegalArgumentException { final int bookCount = Bible.getBookCount(); if (bookIndex < 0 || bookIndex >= bookCount) { throw new IllegalArgumentException("Invalid book index: " + bookIndex); } final int chapterCount = Bible.getChapterCount(bookIndex); if (chapterIndex < 0 || chapterIndex >= chapterCount) { throw new IllegalArgumentException("Invalid chapter index: " + chapterIndex); } int position = 0; for (int i = 0; i < bookIndex; ++i) { position += Bible.getChapterCount(i); } return position + chapterIndex; }   }
VerseHelper { static int indexToPosition(int bookIndex, int chapterIndex) throws IllegalArgumentException { final int bookCount = Bible.getBookCount(); if (bookIndex < 0 || bookIndex >= bookCount) { throw new IllegalArgumentException("Invalid book index: " + bookIndex); } final int chapterCount = Bible.getChapterCount(bookIndex); if (chapterIndex < 0 || chapterIndex >= chapterCount) { throw new IllegalArgumentException("Invalid chapter index: " + chapterIndex); } int position = 0; for (int i = 0; i < bookIndex; ++i) { position += Bible.getChapterCount(i); } return position + chapterIndex; }    }