[jsword-svn] common/java/core/org/crosswire/common/util s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sun May 8 18:28:44 MST 2005


Update of /cvs/jsword/common/java/core/org/crosswire/common/util
In directory www.crosswire.org:/tmp/cvs-serv5945/java/core/org/crosswire/common/util

Modified Files:
	NetUtil.java StringUtil.java EventListenerList.java 
	Convert.java 
Added Files:
	EmptyIterator.java 
Log Message:
Moved unused code to limbo.
Upgraded support-tools: checkstyle, pmd and findbugs to most recent.
Addressed over 100 issues reported by findbugs and checkstyle.
Resulted in major refactoring of GBFFilter.
Net result is that code size is significantly smaller.

Index: EventListenerList.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/EventListenerList.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** EventListenerList.java	24 Jan 2005 23:22:06 -0000	1.7
--- EventListenerList.java	9 May 2005 01:28:42 -0000	1.8
***************
*** 244,257 ****
      {
          Object[] lList = listenerList;
!         String s = "EventListenerList: "; //$NON-NLS-1$
!         s += lList.length / 2 + " listeners: "; //$NON-NLS-1$
  
          for (int i = 0; i <= lList.length - 2; i += 2)
          {
!             s += " type " + ((Class) lList[i]).getName(); //$NON-NLS-1$
!             s += " listener " + lList[i + 1]; //$NON-NLS-1$
          }
  
!         return s;
      }
  
--- 244,260 ----
      {
          Object[] lList = listenerList;
!         StringBuffer s = new StringBuffer("EventListenerList: "); //$NON-NLS-1$
!         s.append(lList.length / 2);
!         s.append(" listeners: "); //$NON-NLS-1$
  
          for (int i = 0; i <= lList.length - 2; i += 2)
          {
!             s.append(" type "); //$NON-NLS-1$
!             s.append(((Class) lList[i]).getName());
!             s.append(" listener "); //$NON-NLS-1$
!             s.append(lList[i + 1]);
          }
  
!         return s.toString();
      }
  

Index: Convert.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/Convert.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Convert.java	28 Nov 2004 21:36:31 -0000	1.4
--- Convert.java	9 May 2005 01:28:42 -0000	1.5
***************
*** 206,232 ****
      public static String map2String(Map commands)
      {
!         Iterator it = commands.keySet().iterator();
          StringBuffer retcode = new StringBuffer();
  
          while (it.hasNext())
          {
!             String key = ""; //$NON-NLS-1$
!             String value = ""; //$NON-NLS-1$
! 
!             try
!             {
!                 key = (String) it.next();
!                 value = (String) commands.get(key);
  
!                 retcode.append(key);
!                 retcode.append('=');
!                 retcode.append(value);
!                 retcode.append(' ');
!             }
!             catch (ClassCastException ex)
!             {
!                 log.warn("non-String member found: key=" + key + " value=" + value); //$NON-NLS-1$ //$NON-NLS-2$
!                 Reporter.informUser(Convert.class, ex);
!             }
          }
  
--- 206,220 ----
      public static String map2String(Map commands)
      {
!         Iterator it = commands.entrySet().iterator();
          StringBuffer retcode = new StringBuffer();
  
          while (it.hasNext())
          {
!             Map.Entry entry = (Map.Entry) it.next();
  
!             retcode.append(entry.getKey());
!             retcode.append('=');
!             retcode.append(entry.getValue());
!             retcode.append(' ');
          }
  

Index: StringUtil.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/StringUtil.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** StringUtil.java	28 Feb 2005 02:21:31 -0000	1.6
--- StringUtil.java	9 May 2005 01:28:42 -0000	1.7
***************
*** 200,204 ****
       * @param separatorChar  the character used as the delimiter,
       *  <code>null</code> splits on whitespace
!      * @return an array of parsed Strings, <code>null</code> if null String input
       * @since 2.0
       */
--- 200,204 ----
       * @param separatorChar  the character used as the delimiter,
       *  <code>null</code> splits on whitespace
!      * @return an array of parsed Strings
       * @since 2.0
       */
***************
*** 209,213 ****
          if (str == null)
          {
!             return null;
          }
          int len = str.length();
--- 209,213 ----
          if (str == null)
          {
!             return EMPTY_STRING_ARRAY;
          }
          int len = str.length();
***************
*** 264,268 ****
       * @param separatorChar  the character used as the delimiter,
       *  <code>null</code> splits on whitespace
!      * @return an array of parsed Strings, <code>null</code> if null String input
       * @since 2.0
       */
--- 264,268 ----
       * @param separatorChar  the character used as the delimiter,
       *  <code>null</code> splits on whitespace
!      * @return an array of parsed Strings
       * @since 2.0
       */
***************
*** 273,277 ****
          if (str == null)
          {
!             return null;
          }
          int len = str.length();
--- 273,277 ----
          if (str == null)
          {
!             return EMPTY_STRING_ARRAY;
          }
          int len = str.length();
***************
*** 356,360 ****
       * @param max  the maximum number of elements to include in the
       *  array. A zero or negative value implies no limit
!      * @return an array of parsed Strings, <code>null</code> if null String input
       */
      public static String[] split(String str, String separatorChars, int max)
--- 356,360 ----
       * @param max  the maximum number of elements to include in the
       *  array. A zero or negative value implies no limit
!      * @return an array of parsed Strings
       */
      public static String[] split(String str, String separatorChars, int max)
***************
*** 366,370 ****
          if (str == null)
          {
!             return null;
          }
          int len = str.length();
--- 366,370 ----
          if (str == null)
          {
!             return EMPTY_STRING_ARRAY;
          }
          int len = str.length();

Index: NetUtil.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/NetUtil.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** NetUtil.java	5 Apr 2005 00:33:22 -0000	1.18
--- NetUtil.java	9 May 2005 01:28:42 -0000	1.19
***************
*** 240,243 ****
--- 240,244 ----
       * @param url The original URL to the file.
       * @return The URL as a file
+      * @throws IOException 
       */
      public static File getAsFile(URL url) throws IOException
***************
*** 266,279 ****
  
          // copy the contents of the URL to the file
!         OutputStream output = new FileOutputStream(workingFile);
!         InputStream input = url.openStream();
! 
!         byte[] data = new byte[512];
!         for (int read = 0; read != -1; read = input.read(data))
          {
!             output.write(data, 0, read);
          }
-         input.close();
-         output.close();
  
          // return the new file in URL form
--- 267,299 ----
  
          // copy the contents of the URL to the file
!         OutputStream output = null;
!         InputStream input = null;
!         try
          {
!             output = new FileOutputStream(workingFile);
!             input = url.openStream();
!             byte[] data = new byte[512];
!             for (int read = 0; read != -1; read = input.read(data))
!             {
!                 output.write(data, 0, read);
!             }
!         }
!         finally
!         {
!             try
!             {
!                 if (input != null)
!                 {
!                     input.close();
!                 }
!             }
!             finally
!             {
!                 if (output != null)
!                 {
!                     output.close();
!                 }
!             }
          }
  
          // return the new file in URL form

--- NEW FILE: EmptyIterator.java ---
/**
 * Distribution Licence:
 * JSword 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
 * 
 * The copyright to this program is held by it's authors.
 */
package org.crosswire.common.util;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * An <code>EmptyIterator</code> is an <code>Iterator</code> that iterates
 * over nothing.
 * 
 * @see gnu.gpl.Licence for license details.
 *      The copyright to this program is held by it's authors.
 * @author DM Smith [ dmsmith555 at yahoo dot com]
 * @version $Id: EmptyIterator.java,v 1.1 2005/05/09 01:28:42 dmsmith Exp $
 */
public class EmptyIterator implements Iterator
{

    /**
     * Construct an <code>EmptyIterator</code>.
     */
    public EmptyIterator()
    {
    }

    /* (non-Javadoc)
     * @see java.util.Iterator#remove()
     */
    public void remove()
    {
        throw new UnsupportedOperationException();
    }

    /* (non-Javadoc)
     * @see java.util.Iterator#hasNext()
     */
    public boolean hasNext()
    {
        return false;
    }

    /* (non-Javadoc)
     * @see java.util.Iterator#next()
     */
    public Object next()
    {
        throw new NoSuchElementException();
    }

}



More information about the jsword-svn mailing list