Skip to content

Commit 712a748

Browse files
committed
did some stuff
1 parent 00bafa2 commit 712a748

7 files changed

Lines changed: 219 additions & 32 deletions

File tree

‎src/main/groovy/org/swordexplorer/bible/AbstractService.groovy‎

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ abstract class AbstractService implements BibleService {
66

77
def bibleData, bookList, chapters, verses
88

9-
AbstractService(jsonBibleTextFilename){
9+
AbstractService(jsonBibleTextFilename) {
1010
init(jsonBibleTextFilename)
1111
}
12-
def init(jsonBibleTextFilename){
12+
13+
def init(jsonBibleTextFilename) {
1314
bibleData = new BibleData(jsonBibleTextFilename).data()
1415
bookList = bibleData.bible.books
1516
chapters = bibleData.bible.chapters
1617
verses = bibleData.bible.verses
1718
}
1819

20+
@Override
1921
def chapterVerseCount(bkId, chapter) {
2022
def chpt = chapters.find { chptInfo ->
2123
chptInfo.book == bkId &&
@@ -24,56 +26,68 @@ abstract class AbstractService implements BibleService {
2426
chpt ? chpt.verses : 0
2527
}
2628

27-
@Override
28-
VerseRange verseSpecToVerses(String verseSpec) {
29-
30-
/// break the string into parts starting with Bookname
31-
/// Gen 5:2-6, 8-12
32-
33-
def parts = verseSpec.split(' ',2)
34-
def bkName = parts[0]
3529

36-
/// get the book
30+
@Override
31+
def parseVerseSpec(String verseSpec) {
32+
33+
def parts = verseSpec.split(':')
34+
def bkChpt = parts[0].split(' ') as List;
35+
def chpt = (bkChpt.pop() as int);
36+
def bkName = bkChpt.join(' ').trim();
37+
def verses
38+
// if the
3739
def book = bookNameToBook(bkName)
38-
3940
if (!book)
40-
throw new IllegalArgumentException("Bad book name: $bkName")
41-
42-
def theRest = parts[1]
43-
def chptAndVerses = theRest.split(':')
44-
// get the chapter
45-
def chapter = Integer.parseInt(chptAndVerses[0])
41+
throw new IllegalArgumentException("Bad book name: [$bkName]")
42+
if (parts.length == 1) {
43+
verses = "1-${chapterVerseCount(book.id, chpt)}"
44+
} else {
45+
verses = parts[1]
46+
}
47+
return [
48+
book : book,
49+
chapter: chpt,
50+
verses : verses
51+
]
52+
}
4653

47-
/// get the verses
48-
def sets = chptAndVerses[1].split(',')
54+
@Override
55+
VerseRange verseSpecToVerses(String verseSpec) {
56+
/// break the string into parts starting with Bookname
57+
/// Gen 5:2-6, 8-12
58+
def parsedVerseSpec = parseVerseSpec(verseSpec);
59+
def book = parsedVerseSpec.book
60+
def bkName = book.title
61+
def chapter = parsedVerseSpec.chapter
62+
def sets = parsedVerseSpec.verses.split(',')
4963
def verseList = []
50-
5164
sets.each { vlist ->
5265
def start, end
53-
if (vlist.contains('-')){
66+
if (vlist.contains('-')) {
5467
def l = vlist.split('-')
5568
start = l[0] as int
5669
end = l[1] as int
5770

58-
}else{
71+
} else {
5972
end = start = (vlist as int)
6073
}
6174
(start..end).each { v ->
6275
verseList << v
6376
}
6477
}
6578

66-
List<Verse> verses=[]
79+
List<Verse> verses = []
6780
verseList.each { v ->
68-
String vid = String.format("%02d%03d%03d", book.id,chapter,v)
81+
String vid = String.format("%02d%03d%03d", book.id, chapter, v)
6982
def verse = getVerse(vid)
7083
if (verse)
7184
verses << verse
7285
}
73-
new VerseRange(verseSpec, verses)
86+
new VerseRange("$bkName $chapter:${parsedVerseSpec.verses}", verses)
7487
}
7588

76-
def bookNameToBook(bkName){
89+
@Override
90+
def bookNameToBook(bkName) {
7791
def ret
7892
/// compare the upper
7993
bkName = bkName.toUpperCase()
@@ -86,7 +100,7 @@ abstract class AbstractService implements BibleService {
86100
def list = bookList.findAll { bk ->
87101
bk.title.toUpperCase().startsWith(bkName)
88102
}
89-
if (list.size() ==1)
103+
if (list.size() == 1)
90104
ret = list[0]
91105
}
92106
ret
@@ -104,14 +118,22 @@ abstract class AbstractService implements BibleService {
104118
}
105119
}
106120

121+
@Override
122+
VerseRange getChapter(int book, int chapter) {
123+
def bk = getBook(book)
124+
def lastVerse = chapterVerseCount(book, chapter)
125+
def verseSpec = "${bk.title} $chapter:1-$lastVerse"
126+
verseSpecToVerses(verseSpec)
127+
}
128+
107129
@Override
108130
List<Book> getBooks() {
109131
bookList
110132
}
111133

112134
@Override
113135
Book getBook(int bookId) {
114-
bookList[bookId-1]
136+
bookList[bookId - 1]
115137
}
116138

117139
private def verseToSearchResult = { verse ->

‎src/main/groovy/org/swordexplorer/bible/BibleService.groovy‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ package org.swordexplorer.bible
44
*
55
*/
66
interface BibleService {
7+
def chapterVerseCount(bkId, chapter)
8+
9+
def parseVerseSpec(String verseSpec)
10+
711
VerseRange verseSpecToVerses(String verseSpec)
12+
13+
def bookNameToBook(bkName)
14+
815
Verse getVerse(String verseId)
916
List<Verse> getVerses(List<String> verseIds)
1017

11-
List getVersesWithPhrase(words)
18+
VerseRange getChapter(int book, int chapter)
1219

20+
List getVersesWithPhrase(words)
1321
List getVersesWithAnyWords(words)
14-
1522
List getVersesWithAllWords(words)
1623

1724
List<Book> getBooks()
1825
Book getBook(int bookId)
19-
2026
String verseSpecFromVerseId(vid)
2127
}

‎src/main/groovy/org/swordexplorer/bible/Book.groovy‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,30 @@ class Book {
77
int id
88
String title
99
int chapters
10+
11+
/**
12+
* Returns a string representation of the object. In general, the
13+
* {@code toString} method returns a string that
14+
* "textually represents" this object. The result should
15+
* be a concise but informative representation that is easy for a
16+
* person to read.
17+
* It is recommended that all subclasses override this method.
18+
* <p>
19+
* The {@code toString} method for class {@code Object}
20+
* returns a string consisting of the name of the class of which the
21+
* object is an instance, the at-sign character `{@code @}', and
22+
* the unsigned hexadecimal representation of the hash code of the
23+
* object. In other words, this method returns a string equal to the
24+
* value of:
25+
* <blockquote>
26+
* <pre>
27+
* getClass().getName() + '@' + Integer.toHexString(hashCode())
28+
* </pre></blockquote>
29+
*
30+
* @return a string representation of the object.
31+
*/
32+
@Override
33+
String toString() {
34+
this.title
35+
}
1036
}

‎src/main/groovy/org/swordexplorer/bible/VerseRange.groovy‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,29 @@ class VerseRange {
1212
this.verses =verses
1313
}
1414

15+
/**
16+
* Returns a string representation of the object. In general, the
17+
* {@code toString} method returns a string that
18+
* "textually represents" this object. The result should
19+
* be a concise but informative representation that is easy for a
20+
* person to read.
21+
* It is recommended that all subclasses override this method.
22+
* <p>
23+
* The {@code toString} method for class {@code Object}
24+
* returns a string consisting of the name of the class of which the
25+
* object is an instance, the at-sign character `{@code @}', and
26+
* the unsigned hexadecimal representation of the hash code of the
27+
* object. In other words, this method returns a string equal to the
28+
* value of:
29+
* <blockquote>
30+
* <pre>
31+
* getClass().getName() + '@' + Integer.toHexString(hashCode())
32+
* </pre></blockquote>
33+
*
34+
* @return a string representation of the object.
35+
*/
36+
@Override
37+
String toString() {
38+
verseSpec
39+
}
1540
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.swordexplorer.bible
2+
3+
/**
4+
*
5+
*/
6+
class VerseSet {
7+
def verseSpec
8+
List<String> verseIds
9+
10+
VerseSet(String verseSpec, List<String> verseIds) {
11+
this.verseSpec = verseSpec
12+
this.verseIds = verseIds
13+
}
14+
15+
/**
16+
* Returns a string representation of the object. In general, the
17+
* {@code toString} method returns a string that
18+
* "textually represents" this object. The result should
19+
* be a concise but informative representation that is easy for a
20+
* person to read.
21+
* It is recommended that all subclasses override this method.
22+
* <p>
23+
* The {@code toString} method for class {@code Object}
24+
* returns a string consisting of the name of the class of which the
25+
* object is an instance, the at-sign character `{@code @}', and
26+
* the unsigned hexadecimal representation of the hash code of the
27+
* object. In other words, this method returns a string equal to the
28+
* value of:
29+
* <blockquote>
30+
* <pre>
31+
* getClass().getName() + '@' + Integer.toHexString(hashCode())
32+
* </pre></blockquote>
33+
*
34+
* @return a string representation of the object.
35+
*/
36+
@Override
37+
String toString() {
38+
verseSpec
39+
}
40+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.swordexplorer.crossref
2+
3+
import org.swordexplorer.bible.BibleService
4+
5+
/**
6+
* Created by lcollins on 7/31/2014.
7+
*/
8+
class BibleCrossReference {
9+
10+
def BibleCrossReference(BibleService service, List initialXref) {
11+
if (initialXref) {
12+
xref = initialXref
13+
}
14+
15+
}
16+
def xref = []
17+
def relationshipDefs = []
18+
def sample = [
19+
[subjectVerses : [verseSpec: 'Gen 1:1', verseIds: ['01001001']],
20+
relatedVerses : [verseSpec: 'Gen 9:9', verseIds: ['02002002']],
21+
relationshipType: 'Same As', notes: 'This verse refers to the same time as Gen 1:1'
22+
], [subjectVerses : [verseSpec: 'Gen 1:1', verseIds: ['01001001']],
23+
relatedVerses : [verseSpec: 'Gen 9:9', verseIds: ['02002002']],
24+
relationshipType: 'Same As', notes: 'This verse refers to the same time as Gen 1:1'
25+
]];
26+
27+
def addVerseRelationship(subjectVerses, relationshipType, relatedVerses) {
28+
xref.add([
29+
subjectVerses : subjectVerses,
30+
relatedVerses : relatedVerses,
31+
relationshipType: relationshipType])
32+
33+
}
34+
35+
def findVerseRelationshipsBySubjectVerse(subjectVerses) {
36+
xref.findAll { vr ->
37+
matchVerses(subjectVerses, vr.subjectVerses)
38+
}
39+
}
40+
41+
def findVerseRelationshipsByRelatedVerse(relatedVerses) {
42+
xref.findAll { vr ->
43+
matchVerses(relatedVerses, vr.relatedVerses)
44+
}
45+
}
46+
47+
def matchVerses(List verseIdList1, List verseIdList2) {
48+
verseIdList1.intersect(verseIdList2).size() == verseIdList1.size() ||
49+
verseIdList2.intersect(verseIdList1).size() == verseIdList2.size()
50+
}
51+
52+
def verseRelationships() {
53+
xref
54+
}
55+
56+
def relationships() {
57+
relationshipDefs
58+
}
59+
}

‎src/test/groovy/org/swordexplorer/bible/tests/VersesSpec.groovy‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ class VersesSpec extends Specification {
3030
verseRange.verses[5].verse == 9
3131
}
3232

33+
def "verseSpecToVerse '1 Chronicles 16:1-5, 9, 11-14' should return a VerseRange with 10 verses"() {
34+
when:
35+
def verseRange = bookService.verseSpecToVerses("1 Chronicles 16:1-5, 9, 11-15")
36+
37+
then:
38+
verseRange.verses.size() == 11
39+
verseRange.verses[5].verse == 9
40+
}
41+
3342
}

0 commit comments

Comments
 (0)