Coverage Report - org.crosswire.jsword.bridge.BibleScope
 
Classes in this File Line Coverage Branch Coverage Complexity
BibleScope
0%
0/36
0%
0/14
2.286
 
 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, 2008 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.bridge;
 21  
 
 22  
 import org.crosswire.jsword.book.Book;
 23  
 import org.crosswire.jsword.book.BookCategory;
 24  
 import org.crosswire.jsword.book.Books;
 25  
 import org.crosswire.jsword.passage.Key;
 26  
 import org.crosswire.jsword.versification.BookName;
 27  
 
 28  
 /**
 29  
  * Determines the scope of the Bible. That is, the verses that are in the Bible
 30  
  * and the verses that are not. This is based upon the KJV versification.
 31  
  * 
 32  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 33  
  * @author DM Smith
 34  
  */
 35  
 public class BibleScope {
 36  
 
 37  0
     public BibleScope(Book book) {
 38  0
         this.book = book;
 39  0
     }
 40  
 
 41  
     /**
 42  
      * Get a key containing all the verses that are in this Bible.
 43  
      * 
 44  
      * @return verses that are in scope
 45  
      */
 46  
     public Key getInScope() {
 47  0
         computeScope();
 48  0
         return inScope;
 49  
     }
 50  
 
 51  
     /**
 52  
      * Get a key containing all the verses that are not in this Bible.
 53  
      * 
 54  
      * @return verses that are out of scope
 55  
      */
 56  
     public Key getOutOfScope() {
 57  0
         computeScope();
 58  0
         return outScope;
 59  
     }
 60  
 
 61  
     private void computeScope() {
 62  0
         if (inScope == null) {
 63  0
             Key all = book.getGlobalKeyList();
 64  0
             inScope = book.createEmptyKeyList();
 65  0
             outScope = book.createEmptyKeyList();
 66  0
             for (Key key : all) {
 67  0
                 if (book.contains(key)) {
 68  0
                     inScope.addAll(key);
 69  
                 } else {
 70  0
                     outScope.addAll(key);
 71  
                 }
 72  
             }
 73  
         }
 74  0
     }
 75  
 
 76  
     public static void report(Book b) {
 77  0
         if (!b.getBookCategory().equals(BookCategory.BIBLE) && !b.getBookCategory().equals(BookCategory.COMMENTARY)) {
 78  0
             System.err.println(b.getInitials() + " is not a Bible or Commentary");
 79  
             // System.exit(1);
 80  
         }
 81  
 
 82  0
         BibleScope scope = new BibleScope(b);
 83  0
         BookName.setFullBookName(false); // use short names
 84  0
         System.out.println('[' + b.getInitials() + ']');
 85  0
         System.out.println("InScope=" + scope.getInScope().getOsisRef());
 86  0
         System.out.println("OutScope=" + scope.getOutOfScope().getOsisRef());
 87  0
     }
 88  
 
 89  
     private Book book;
 90  
 
 91  
     /**
 92  
      * Call with <operation> book. Where operation can be one of:
 93  
      * <ul>
 94  
      * <li>check - returns "TRUE" or "FALSE" indicating whether the index exists
 95  
      * or not</li>
 96  
      * <li>create - (re)create the index</li>
 97  
      * <li>delete - delete the index if it exists</li>
 98  
      * </ul>
 99  
      * And book is the initials of a book, e.g. KJV.
 100  
      * 
 101  
      * @param args
 102  
      */
 103  
     public static void main(String[] args) {
 104  0
         if (args.length != 1) {
 105  0
             usage();
 106  0
             return;
 107  
         }
 108  
 
 109  0
         System.err.println("BibleScope " + args[0]);
 110  
 
 111  0
         Book b = Books.installed().getBook(args[0]);
 112  0
         if (b == null) {
 113  0
             System.err.println("Book not found");
 114  0
             return;
 115  
         }
 116  
 
 117  0
         report(b);
 118  
 
 119  
         // List books =
 120  
         // Books.installed().getBooks(BookFilters.getCommentaries());
 121  
         // Iterator iter = books.iterator();
 122  
         // while (iter.hasNext())
 123  
         // {
 124  
         // try {
 125  
         // report((Book) iter.next());
 126  
         // } catch (Exception e) {
 127  
         // System.out.println("exception " + e.toString());
 128  
         // }
 129  
         // System.out.println();
 130  
         // }
 131  0
     }
 132  
 
 133  
     public static void usage() {
 134  0
         System.err.println("Usage: BibleScope book");
 135  0
     }
 136  
 
 137  
     private Key inScope;
 138  
     private Key outScope;
 139  
 }