[jsword-svn] r1409 - in trunk: jsword/src/main/java/org/crosswire/jsword/book jsword/src/main/java/org/crosswire/jsword/book/basic jsword/src/main/java/org/crosswire/jsword/book/readings jsword/src/main/java/org/crosswire/jsword/book/study jsword/src/main/java/org/crosswire/jsword/book/sword jsword/src/main/java/org/crosswire/jsword/passage jsword-limbo/src/main/java/org/crosswire/bibledesktop/book jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb jsword-limbo/src/main/java/org/crosswire/bibledesktop/reference jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Fri Jun 15 14:57:17 MST 2007


Author: dmsmith
Date: 2007-06-15 14:57:17 -0700 (Fri, 15 Jun 2007)
New Revision: 1409

Added:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/BookProvider.java
Modified:
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/book/CommentaryPane.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/reference/ReferencedPane.java
   trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/BookDriver.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookDriver.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsBookDriver.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsKey.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsMapSet.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsNumber.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDailyDevotion.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZVerseBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageTally.java
Log:
QA changes (checkstyle, findbugs, pmd, ...)
Fixed bugs.
Created BookProvider interface.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -49,7 +49,7 @@
  * @author Joe Walker [joe at eireneh dot com]
  * @author DM Smith [dmsmith at yahoo dot com]
  */
-public class BookData
+public class BookData implements BookProvider
 {
     /**
      * Ctor
@@ -130,7 +130,7 @@
      */
     public Book[] getBooks()
     {
-        return books;
+        return books == null ? null : (Book[]) books.clone();
     }
 
     /**

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookDriver.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookDriver.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookDriver.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -28,18 +28,9 @@
  *      The copyright to this program is held by it's authors.
  * @author Joe Walker [joe at eireneh dot com]
  */
-public interface BookDriver
+public interface BookDriver extends BookProvider
 {
     /**
-     * This method should only be used by Bibles at startup to register the
-     * Bibles known at start time.
-     * Generally there will be a better way of doing whatever you want to do if
-     * you use this method.
-     * @return A list of the known Bibles
-     */
-    Book[] getBooks();
-
-    /**
      * Is this name capable of creating writing data in the correct format
      * as well as reading it?
      * @return true/false to indicate ability to write data

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookProvider.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookProvider.java	                        (rev 0)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookProvider.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -0,0 +1,45 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2007
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id$
+ */
+package org.crosswire.jsword.book;
+
+
+/**
+ * A BookSelectEvent happens whenever a user selects a book.
+ * 
+ * @see gnu.gpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public interface BookProvider
+{
+    /**
+     * Provide books.
+     * @return the books
+     */
+    Book[] getBooks();
+
+    /**
+     * Provide the first book.
+     * @return the first book
+     */
+    Book getFirstBook();
+}


Property changes on: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookProvider.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookDriver.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookDriver.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookDriver.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -66,4 +66,14 @@
     {
         throw new BookException(Msg.DRIVER_READONLY);
     }
+
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.BookProvider#getFirstBook()
+     */
+    public Book getFirstBook()
+    {
+        Book[] books = getBooks();
+        return books == null || books.length == 0 ? null : books[0];
+    }
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsBookDriver.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsBookDriver.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsBookDriver.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -63,9 +63,7 @@
      */
     public Book[] getBooks()
     {
-        Book[] copy = new Book[books.length];
-        System.arraycopy(books, 0, copy, 0, books.length);
-        return copy;
+        return books == null ? null : (Book[]) books.clone();
     }
 
     /* (non-Javadoc)
@@ -93,13 +91,7 @@
         try
         {
             URL index = ResourceUtil.getResource(ReadingsBookDriver.class, "readings.txt"); //$NON-NLS-1$
-            return NetUtil.listByIndexFile(NetUtil.toURI(index), new URIFilter()
-            {
-                public boolean accept(String name)
-                {
-                    return true;
-                }
-            });
+            return NetUtil.listByIndexFile(NetUtil.toURI(index), new ReadingsFilter());
         }
         catch (IOException ex)
         {
@@ -108,6 +100,17 @@
     }
 
     /**
+     * Get all files mentioned by readings.txt
+     */
+    static final class ReadingsFilter implements URIFilter
+    {
+        public boolean accept(String name)
+        {
+            return true;
+        }
+    }
+
+    /**
      * The meta data array
      */
     private Book[] books;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsKey.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsKey.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/readings/ReadingsKey.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -54,7 +54,9 @@
 
         try
         {
-            date = NAME_DF.parse(text);
+            DateFormat nameDF = DateFormat.getDateInstance(DateFormat.MEDIUM);
+            nameDF.setLenient(true);
+            date = nameDF.parse(text);
         }
         catch (ParseException ex)
         {
@@ -68,7 +70,7 @@
      */
     protected ReadingsKey(Date date)
     {
-        super(NAME_DF.format(date), OSIS_DF.format(date));
+        super(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date), new SimpleDateFormat("d.MMMM").format(date)); //$NON-NLS-1$
         this.date = date;
     }
 
@@ -147,12 +149,5 @@
     /**
      * Date formatter
      */
-    private static final DateFormat NAME_DF = DateFormat.getDateInstance(DateFormat.MEDIUM);
-    private static final DateFormat OSIS_DF = new SimpleDateFormat("d.MMMM"); //$NON-NLS-1$
-    static
-    {
-        NAME_DF.setLenient(true);
-    }
-
     private static final MessageFormat KEY_FORMAT = new MessageFormat("{0,number,00}.{1,number,00}"); //$NON-NLS-1$
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsMapSet.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsMapSet.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsMapSet.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -22,6 +22,7 @@
 package org.crosswire.jsword.book.study;
 
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
@@ -62,7 +63,8 @@
             reps = new TreeSet();
             map.put(strongsNumber, reps);
         }
-        reps.add(representation.toLowerCase());
+        // TODO(DMS): change parameter to include the locale of the Book.
+        reps.add(representation.toLowerCase(Locale.getDefault()));
     }
 
     /**

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsNumber.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsNumber.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/study/StrongsNumber.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -91,11 +91,8 @@
      */
     public int hashCode()
     {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + language;
-        result = prime * result + strongsNumber;
-        return result;
+        int result = 31 + language;
+        return 31 * result + strongsNumber;
     }
 
     /* (non-Javadoc)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDailyDevotion.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDailyDevotion.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDailyDevotion.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -42,17 +42,11 @@
         super(sbmd, backend);
     }
 
-
     /* (non-Javadoc)
      * @see org.crosswire.jsword.passage.PreferredKey#getPreferred()
      */
     public Key getPreferred()
     {
-        return new IndexKey(NAME_DF.format(new Date()));
+        return new IndexKey(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()));
     }
-
-    /**
-     * Date formatter, fully internationalized.
-     */
-    private static final DateFormat NAME_DF = DateFormat.getDateInstance(DateFormat.MEDIUM);
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -351,7 +351,7 @@
 
                 decipher(temp);
 
-                uncompressed = CompressorType.fromString(compressType).getCompressor(temp).uncompress();
+                uncompressed = CompressorType.fromString(compressType).getCompressor(temp).uncompress().toByteArray();
 
                 // cache the uncompressed data for next time
                 lastBlockNum = blockNum;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZVerseBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZVerseBackend.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZVerseBackend.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -284,7 +284,7 @@
 
                 decipher(data);
 
-                uncompressed = CompressorType.fromString(compressType).getCompressor(data).uncompress(uncompressedSize);
+                uncompressed = CompressorType.fromString(compressType).getCompressor(data).uncompress(uncompressedSize).toByteArray();
 
                 // cache the uncompressed data for next time
                 lastBlockNum = blockNum;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageTally.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageTally.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageTally.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -1021,11 +1021,8 @@
          */
         public int hashCode()
         {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ord;
-            result = prime * result + tally;
-            return result;
+            int result = 31 + ord;
+            return 31 * result + tally;
         }
 
         /* (non-Javadoc)
@@ -1193,11 +1190,8 @@
          */
         public int hashCode()
         {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + tally;
-            result = prime * result + ((range == null) ? 0 : range.hashCode());
-            return result;
+            int result = 31 + tally;
+            return 31 * result + ((range == null) ? 0 : range.hashCode());
         }
 
         /* (non-Javadoc)

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/book/CommentaryPane.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/book/CommentaryPane.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/book/CommentaryPane.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -36,6 +36,7 @@
 import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
 import org.crosswire.bibledesktop.display.ScrolledBookDataDisplay;
 import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
 import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.Book;
 import org.crosswire.jsword.book.BookFilter;
@@ -223,6 +224,22 @@
     }
 
     /* (non-Javadoc)
+     * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+     */
+    public void addKeyChangeListener(KeyChangeListener listener)
+    {
+        display.addKeyChangeListener(listener);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+     */
+    public void removeKeyChangeListener(KeyChangeListener listener)
+    {
+        display.removeKeyChangeListener(listener);
+    }
+
+    /* (non-Javadoc)
      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
      */
     public void propertyChange(PropertyChangeEvent evt)

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -27,6 +27,7 @@
 
 import org.crosswire.bibledesktop.display.BookDataDisplay;
 import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
 import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.Book;
 import org.crosswire.jsword.passage.Key;
@@ -124,6 +125,20 @@
     }
 
     /* (non-Javadoc)
+     * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+     */
+    public void addKeyChangeListener(KeyChangeListener listener)
+    {
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+     */
+    public void removeKeyChangeListener(KeyChangeListener listener)
+    {
+    }
+
+    /* (non-Javadoc)
      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
      */
     public void propertyChange(PropertyChangeEvent evt)

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/reference/ReferencedPane.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/reference/ReferencedPane.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/reference/ReferencedPane.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -47,6 +47,7 @@
 import org.crosswire.bibledesktop.display.BookDataDisplay;
 import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
 import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
 import org.crosswire.bibledesktop.passage.KeyTreeNode;
 import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.Book;
@@ -203,6 +204,22 @@
     }
 
     /* (non-Javadoc)
+     * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+     */
+    public void addKeyChangeListener(KeyChangeListener listener)
+    {
+        display.addKeyChangeListener(listener);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+     */
+    public void removeKeyChangeListener(KeyChangeListener listener)
+    {
+        display.removeKeyChangeListener(listener);
+    }
+
+    /* (non-Javadoc)
      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
      */
     public void propertyChange(PropertyChangeEvent evt)

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java	2007-06-15 21:55:21 UTC (rev 1408)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java	2007-06-15 21:57:17 UTC (rev 1409)
@@ -47,7 +47,7 @@
 public class JDBCBookDriver extends AbstractBookDriver
 {
     /* (non-Javadoc)
-     * @see org.crosswire.jsword.book.BookDriver#getBooks()
+     * @see org.crosswire.jsword.book.BookProvider#getBooks()
      */
     public Book[] getBooks()
     {




More information about the jsword-svn mailing list