You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/16 03:11:39 UTC

svn commit: r754808 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang: ./ exception/ text/ time/

Author: sebb
Date: Mon Mar 16 02:11:38 2009
New Revision: 754808

URL: http://svn.apache.org/viewvc?rev=754808&view=rev
Log:
Genericize some more classes

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/ClassUtils.java Mon Mar 16 02:11:38 2009
@@ -256,12 +256,12 @@
      * @return the <code>List</code> of superclasses in order going up from this one
      *  <code>null</code> if null input
      */
-    public static List getAllSuperclasses(Class cls) {
+    public static List<Class<?>> getAllSuperclasses(Class<?> cls) {
         if (cls == null) {
             return null;
         }
-        List classes = new ArrayList();
-        Class superclass = cls.getSuperclass();
+        List<Class<?>> classes = new ArrayList<Class<?>>();
+        Class<?> superclass = cls.getSuperclass();
         while (superclass != null) {
             classes.add(superclass);
             superclass = superclass.getSuperclass();

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/NotImplementedException.java Mon Mar 16 02:11:38 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.lang;
 
-import java.io.PrintStream;
-import java.io.PrintWriter;
 
 /**
  * <p>Thrown to indicate that a block of code has not been implemented.
@@ -44,6 +42,7 @@
  * @since 2.0
  * @version $Id$
  */
+//@Immutable
 public class NotImplementedException extends UnsupportedOperationException {
 
     private static final String DEFAULT_MESSAGE = "Code is not implemented";
@@ -104,7 +103,7 @@
      * @param clazz
      *            the <code>Class</code> that has not implemented the method
      */
-    public NotImplementedException(Class clazz) {
+    public NotImplementedException(Class<?> clazz) {
         super(clazz == null ? DEFAULT_MESSAGE : DEFAULT_MESSAGE + " in " + clazz);
     }
 

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java Mon Mar 16 02:11:38 2009
@@ -121,7 +121,7 @@
      */
     public static void addCauseMethodName(String methodName) {
         if (StringUtils.isNotEmpty(methodName) && !isCauseMethodName(methodName)) {            
-            List list = getCauseMethodNameList();
+            List<String> list = getCauseMethodNameList();
             if (list.add(methodName)) {
                 synchronized(CAUSE_METHOD_NAMES) {
                     CAUSE_METHOD_NAMES = toArray(list);
@@ -140,7 +140,7 @@
      */
     public static void removeCauseMethodName(String methodName) {
         if (StringUtils.isNotEmpty(methodName)) {
-            List list = getCauseMethodNameList();
+            List<String> list = getCauseMethodNameList();
             if (list.remove(methodName)) {
                 synchronized(CAUSE_METHOD_NAMES) {
                     CAUSE_METHOD_NAMES = toArray(list);
@@ -212,8 +212,8 @@
      * @param list a list to transform.
      * @return the given list as a <code>String[]</code>.
      */
-    private static String[] toArray(List list) {
-        return (String[]) list.toArray(new String[list.size()]);
+    private static String[] toArray(List<String> list) {
+        return list.toArray(new String[list.size()]);
     }
 
     /**
@@ -221,9 +221,9 @@
      *
      * @return {@link #CAUSE_METHOD_NAMES} as a List.
      */
-    private static ArrayList getCauseMethodNameList() {
+    private static ArrayList<String> getCauseMethodNameList() {
         synchronized(CAUSE_METHOD_NAMES) {
-            return new ArrayList(Arrays.asList(CAUSE_METHOD_NAMES));
+            return new ArrayList<String>(Arrays.asList(CAUSE_METHOD_NAMES));
         }
     }
 
@@ -343,7 +343,7 @@
      *  <code>null</code> if none found or null throwable input
      */
     public static Throwable getRootCause(Throwable throwable) {
-        List list = getThrowableList(throwable);
+        List<Throwable> list = getThrowableList(throwable);
         return (list.size() < 2 ? null : (Throwable)list.get(list.size() - 1));
     }
 
@@ -462,7 +462,7 @@
             return true;
         }
 
-        Class cls = throwable.getClass();
+        Class<? extends Throwable> cls = throwable.getClass();
         synchronized(CAUSE_METHOD_NAMES) {
             for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) {
                 try {
@@ -533,8 +533,8 @@
      * @return the array of throwables, never null
      */
     public static Throwable[] getThrowables(Throwable throwable) {
-        List list = getThrowableList(throwable);
-        return (Throwable[]) list.toArray(new Throwable[list.size()]);
+        List<Throwable> list = getThrowableList(throwable);
+        return list.toArray(new Throwable[list.size()]);
     }
 
     /**
@@ -556,8 +556,8 @@
      * @return the list of throwables, never null
      * @since Commons Lang 2.2
      */
-    public static List getThrowableList(Throwable throwable) {
-        List list = new ArrayList();
+    public static List<Throwable> getThrowableList(Throwable throwable) {
+        List<Throwable> list = new ArrayList<Throwable>();
         while (throwable != null && list.contains(throwable) == false) {
             list.add(throwable);
             throwable = ExceptionUtils.getCause(throwable);
@@ -580,7 +580,7 @@
      * @param clazz  the class to search for, subclasses do not match, null returns -1
      * @return the index into the throwable chain, -1 if no match or null input
      */
-    public static int indexOfThrowable(Throwable throwable, Class clazz) {
+    public static int indexOfThrowable(Throwable throwable, Class<?> clazz) {
         return indexOf(throwable, clazz, 0, false);
     }
 
@@ -603,7 +603,7 @@
      *  negative treated as zero, larger than chain size returns -1
      * @return the index into the throwable chain, -1 if no match or null input
      */
-    public static int indexOfThrowable(Throwable throwable, Class clazz, int fromIndex) {
+    public static int indexOfThrowable(Throwable throwable, Class<?> clazz, int fromIndex) {
         return indexOf(throwable, clazz, fromIndex, false);
     }
 
@@ -623,7 +623,7 @@
      * @return the index into the throwable chain, -1 if no match or null input
      * @since 2.1
      */
-    public static int indexOfType(Throwable throwable, Class type) {
+    public static int indexOfType(Throwable throwable, Class<?> type) {
         return indexOf(throwable, type, 0, true);
     }
 
@@ -647,7 +647,7 @@
      * @return the index into the throwable chain, -1 if no match or null input
      * @since 2.1
      */
-    public static int indexOfType(Throwable throwable, Class type, int fromIndex) {
+    public static int indexOfType(Throwable throwable, Class<?> type, int fromIndex) {
         return indexOf(throwable, type, fromIndex, true);
     }
 
@@ -662,7 +662,7 @@
      * using references
      * @return index of the <code>type</code> within throwables nested withing the specified <code>throwable</code>
      */
-    private static int indexOf(Throwable throwable, Class type, int fromIndex, boolean subclass) {
+    private static int indexOf(Throwable throwable, Class<?> type, int fromIndex, boolean subclass) {
         if (throwable == null || type == null) {
             return -1;
         }
@@ -798,10 +798,10 @@
         }
         Throwable throwables[] = getThrowables(throwable);
         int count = throwables.length;
-        ArrayList frames = new ArrayList();
-        List nextTrace = getStackFrameList(throwables[count - 1]);
+        ArrayList<String> frames = new ArrayList<String>();
+        List<String> nextTrace = getStackFrameList(throwables[count - 1]);
         for (int i = count; --i >= 0;) {
-            List trace = nextTrace;
+            List<String> trace = nextTrace;
             if (i != 0) {
                 nextTrace = getStackFrameList(throwables[i - 1]);
                 removeCommonFrames(trace, nextTrace);
@@ -815,7 +815,7 @@
                 frames.add(trace.get(j));
             }
         }
-        return (String[]) frames.toArray(new String[0]);
+        return frames.toArray(new String[0]);
     }
 
     /**
@@ -826,7 +826,7 @@
      * @throws IllegalArgumentException if either argument is null
      * @since 2.0
      */
-    public static void removeCommonFrames(List causeFrames, List wrapperFrames) {
+    public static void removeCommonFrames(List<String> causeFrames, List<String> wrapperFrames) {
         if (causeFrames == null || wrapperFrames == null) {
             throw new IllegalArgumentException("The List must not be null");
         }
@@ -835,8 +835,8 @@
         while (causeFrameIndex >= 0 && wrapperFrameIndex >= 0) {
             // Remove the frame from the cause trace if it is the same
             // as in the wrapper trace
-            String causeFrame = (String) causeFrames.get(causeFrameIndex);
-            String wrapperFrame = (String) wrapperFrames.get(wrapperFrameIndex);
+            String causeFrame = causeFrames.get(causeFrameIndex);
+            String wrapperFrame = wrapperFrames.get(wrapperFrameIndex);
             if (causeFrame.equals(wrapperFrame)) {
                 causeFrames.remove(causeFrameIndex);
             }
@@ -921,7 +921,7 @@
     static String[] getStackFrames(String stackTrace) {
         String linebreak = SystemUtils.LINE_SEPARATOR;
         StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
-        List list = new ArrayList();
+        List<String> list = new ArrayList<String>();
         while (frames.hasMoreTokens()) {
             list.add(frames.nextToken());
         }
@@ -940,11 +940,11 @@
      * @param t is any throwable
      * @return List of stack frames
      */
-    static List getStackFrameList(Throwable t) {
+    static List<String> getStackFrameList(Throwable t) {
         String stackTrace = getStackTrace(t);
         String linebreak = SystemUtils.LINE_SEPARATOR;
         StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
-        List list = new ArrayList();
+        List<String> list = new ArrayList<String>();
         boolean traceStarted = false;
         while (frames.hasMoreTokens()) {
             String token = frames.nextToken();

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/ExtendedMessageFormat.java Mon Mar 16 02:11:38 2009
@@ -78,7 +78,7 @@
     private static final char QUOTE = '\'';
 
     private String toPattern;
-    private Map registry;
+    private final Map<String, FormatFactory> registry;
 
     /**
      * Create a new ExtendedMessageFormat for the default locale.
@@ -108,7 +108,7 @@
      * @param registry Registry of format factories:  Map<String, FormatFactory>
      * @throws IllegalArgumentException in case of a bad pattern.
      */
-    public ExtendedMessageFormat(String pattern, Map registry) {
+    public ExtendedMessageFormat(String pattern, Map<String, FormatFactory> registry) {
         this(pattern, Locale.getDefault(), registry);
     }
 
@@ -120,7 +120,7 @@
      * @param registry Registry of format factories:  Map<String, FormatFactory>
      * @throws IllegalArgumentException in case of a bad pattern.
      */
-    public ExtendedMessageFormat(String pattern, Locale locale, Map registry) {
+    public ExtendedMessageFormat(String pattern, Locale locale, Map<String, FormatFactory> registry) {
         super(DUMMY_PATTERN);
         setLocale(locale);
         this.registry = registry;
@@ -147,8 +147,8 @@
             toPattern = super.toPattern();
             return;
         }
-        ArrayList foundFormats = new ArrayList();
-        ArrayList foundDescriptions = new ArrayList();
+        ArrayList<Format> foundFormats = new ArrayList<Format>();
+        ArrayList<String> foundDescriptions = new ArrayList<String>();
         StringBuffer stripCustom = new StringBuffer(pattern.length());
 
         ParsePosition pos = new ParsePosition(0);
@@ -197,8 +197,8 @@
             // only loop over what we know we have, as MessageFormat on Java 1.3 
             // seems to provide an extra format element:
             int i = 0;
-            for (Iterator it = foundFormats.iterator(); it.hasNext(); i++) {
-                Format f = (Format) it.next();
+            for (Iterator<Format> it = foundFormats.iterator(); it.hasNext(); i++) {
+                Format f = it.next();
                 if (f != null) {
                     origFormats[i] = f;
                 }
@@ -258,7 +258,7 @@
                 name = desc.substring(0, i).trim();
                 args = desc.substring(i + 1).trim();
             }
-            FormatFactory factory = (FormatFactory) registry.get(name);
+            FormatFactory factory = registry.get(name);
             if (factory != null) {
                 return factory.getFormat(name, args, getLocale());
             }
@@ -347,7 +347,7 @@
      * @param customPatterns The custom patterns to re-insert, if any
      * @return full pattern
      */
-    private String insertFormats(String pattern, ArrayList customPatterns) {
+    private String insertFormats(String pattern, ArrayList<String> customPatterns) {
         if (!containsElements(customPatterns)) {
             return pattern;
         }
@@ -367,7 +367,7 @@
                     fe++;
                     sb.append(START_FE).append(
                             readArgumentIndex(pattern, next(pos)));
-                    String customPattern = (String) customPatterns.get(fe);
+                    String customPattern = customPatterns.get(fe);
                     if (customPattern != null) {
                         sb.append(START_FMT).append(customPattern);
                     }
@@ -467,11 +467,11 @@
      * @param coll to check
      * @return <code>true</code> if some Object was found, <code>false</code> otherwise.
      */
-    private boolean containsElements(Collection coll) {
+    private boolean containsElements(Collection<?> coll) {
         if (coll == null || coll.size() == 0) {
             return false;
         }
-        for (Iterator iter = coll.iterator(); iter.hasNext();) {
+        for (Iterator<?> iter = coll.iterator(); iter.hasNext();) {
             if (iter.next() != null) {
                 return true;
             }

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java Mon Mar 16 02:11:38 2009
@@ -85,7 +85,7 @@
  * @since 2.2
  * @version $Id$
  */
-public class StrTokenizer implements ListIterator, Cloneable {
+public class StrTokenizer implements ListIterator<String>, Cloneable {
 
     private static final StrTokenizer CSV_TOKENIZER_PROTOTYPE;
     private static final StrTokenizer TSV_TOKENIZER_PROTOTYPE;
@@ -529,7 +529,7 @@
      *
      * @return the next String token
      */
-    public Object next() {
+    public String next() {
         if (hasNext()) {
             return tokens[tokenPos++];
         }
@@ -560,7 +560,7 @@
      *
      * @return the previous token
      */
-    public Object previous() {
+    public String previous() {
         if (hasPrevious()) {
             return tokens[--tokenPos];
         }
@@ -590,7 +590,7 @@
      * @param obj this parameter ignored.
      * @throws UnsupportedOperationException always
      */
-    public void set(Object obj) {
+    public void set(String obj) {
         throw new UnsupportedOperationException("set() is unsupported");
     }
 
@@ -599,7 +599,7 @@
      * @param obj this parameter ignored.
      * @throws UnsupportedOperationException always
      */
-    public void add(Object obj) {
+    public void add(String obj) {
         throw new UnsupportedOperationException("add() is unsupported");
     }
 

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DateUtils.java Mon Mar 16 02:11:38 2009
@@ -261,7 +261,7 @@
      * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
      * @return the parsed date
      * @throws IllegalArgumentException if the date string or pattern array is null
-     * @throws ParseException if none of the date patterns were suitable
+     * @throws ParseException if none of the date patterns were suitable (or there were none)
      */
     public static Date parseDate(String str, String[] parsePatterns) throws ParseException {
         if (str == null || parsePatterns == null) {
@@ -925,7 +925,7 @@
      * @throws IllegalArgumentException if the date is <code>null</code>
      * @throws IllegalArgumentException if the rangeStyle is invalid
      */
-    public static Iterator iterator(Date focus, int rangeStyle) {
+    public static Iterator<Calendar> iterator(Date focus, int rangeStyle) {
         if (focus == null) {
             throw new IllegalArgumentException("The date must not be null");
         }
@@ -958,7 +958,7 @@
      * @throws IllegalArgumentException if the date is <code>null</code>
      * @throws IllegalArgumentException if the rangeStyle is invalid
      */
-    public static Iterator iterator(Calendar focus, int rangeStyle) {
+    public static Iterator<Calendar> iterator(Calendar focus, int rangeStyle) {
         if (focus == null) {
             throw new IllegalArgumentException("The date must not be null");
         }
@@ -1049,7 +1049,7 @@
      * @throws ClassCastException if the object type is
      *  not a <code>Date</code> or <code>Calendar</code>
      */
-    public static Iterator iterator(Object focus, int rangeStyle) {
+    public static Iterator<?> iterator(Object focus, int rangeStyle) {
         if (focus == null) {
             throw new IllegalArgumentException("The date must not be null");
         }
@@ -1565,7 +1565,7 @@
     /**
      * <p>Date iterator.</p>
      */
-    static class DateIterator implements Iterator {
+    static class DateIterator implements Iterator<Calendar> {
         private final Calendar endFinal;
         private final Calendar spot;
         
@@ -1596,12 +1596,12 @@
          *
          * @return Object calendar for the next date
          */
-        public Object next() {
+        public Calendar next() {
             if (spot.equals(endFinal)) {
                 throw new NoSuchElementException();
             }
             spot.add(Calendar.DATE, 1);
-            return spot.clone();
+            return (Calendar) spot.clone();
         }
 
         /**

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java?rev=754808&r1=754807&r2=754808&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/DurationFormatUtils.java Mon Mar 16 02:11:38 2009
@@ -485,11 +485,11 @@
      * Parses a classic date format string into Tokens
      *
      * @param format to parse
-     * @return Token[] of tokens
+     * @return array of Token[]
      */
     static Token[] lexx(String format) {
         char[] array = format.toCharArray();
-        ArrayList list = new ArrayList(array.length);
+        ArrayList<Token> list = new ArrayList<Token>(array.length);
 
         boolean inLiteral = false;
         StringBuffer buffer = null;
@@ -498,7 +498,7 @@
         for(int i=0; i<sz; i++) {
             char ch = array[i];
             if(inLiteral && ch != '\'') {
-                buffer.append(ch);
+                buffer.append(ch); // buffer can't be null if inLiteral is true
                 continue;
             }
             Object value = null;
@@ -540,7 +540,7 @@
                 buffer = null; 
             }
         }
-        return (Token[]) list.toArray( new Token[list.size()] );
+        return list.toArray( new Token[list.size()] );
     }
 
     /**