struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r724074 - /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java
Date Sun, 07 Dec 2008 04:51:34 GMT
Author: wesw
Date: Sat Dec  6 20:51:34 2008
New Revision: 724074

URL: http://svn.apache.org/viewvc?rev=724074&view=rev
Log:
Cleanup in JakartaMultiPartRequest, using generics. Per WW-2908, thanks for the patch Mathias

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java?rev=724074&r1=724073&r2=724074&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java
Sat Dec  6 20:51:34 2008
@@ -47,18 +47,19 @@
 
 /**
  * Multipart form data request adapter for Jakarta Commons Fileupload package.
- *
  */
 public class JakartaMultiPartRequest implements MultiPartRequest {
     
     static final Logger LOG = LoggerFactory.getLogger(MultiPartRequest.class);
     
     // maps parameter name -> List of FileItem objects
-    private Map<String,List<FileItem>> files = new HashMap<String,List<FileItem>>();
+    private final Map<String,List<FileItem>> files = new HashMap<String,List<FileItem>>();
+
     // maps parameter name -> List of param values
-    private Map<String,List<String>> params = new HashMap<String,List<String>>();
+    private final Map<String,List<String>> params = new HashMap<String,List<String>>();
+
     // any errors while processing this request
-    private List<String> errors = new ArrayList<String>();
+    private final List<String> errors = new ArrayList<String>();
     
     private long maxSize;
     
@@ -151,38 +152,36 @@
      * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getContentType(java.lang.String)
      */
     public String[] getContentType(String fieldName) {
-        List items = (List) files.get(fieldName);
+        List<FileItem> items = files.get(fieldName);
 
         if (items == null) {
             return null;
         }
 
         List<String> contentTypes = new ArrayList<String>(items.size());
-        for (int i = 0; i < items.size(); i++) {
-            FileItem fileItem = (FileItem) items.get(i);
+        for (FileItem fileItem : items) {
             contentTypes.add(fileItem.getContentType());
         }
 
-        return (String[]) contentTypes.toArray(new String[contentTypes.size()]);
+        return contentTypes.toArray(new String[contentTypes.size()]);
     }
 
     /* (non-Javadoc)
      * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFile(java.lang.String)
      */
     public File[] getFile(String fieldName) {
-        List items = (List) files.get(fieldName);
+        List<FileItem> items = files.get(fieldName);
 
         if (items == null) {
             return null;
         }
 
         List<File> fileList = new ArrayList<File>(items.size());
-        for (int i = 0; i < items.size(); i++) {
-            DiskFileItem fileItem = (DiskFileItem) items.get(i);
-            fileList.add(fileItem.getStoreLocation());
+        for (FileItem fileItem : items) {
+            fileList.add(((DiskFileItem) fileItem).getStoreLocation());
         }
 
-        return (File[]) fileList.toArray(new File[fileList.size()]);
+        return fileList.toArray(new File[fileList.size()]);
     }
 
     /* (non-Javadoc)
@@ -196,40 +195,38 @@
         }
 
         List<String> fileNames = new ArrayList<String>(items.size());
-        for (int i = 0; i < items.size(); i++) {
-            DiskFileItem fileItem = (DiskFileItem) items.get(i);
+        for (FileItem fileItem : items) {
             fileNames.add(getCanonicalName(fileItem.getName()));
         }
 
-        return (String[]) fileNames.toArray(new String[fileNames.size()]);
+        return fileNames.toArray(new String[fileNames.size()]);
     }
 
     /* (non-Javadoc)
      * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFilesystemName(java.lang.String)
      */
     public String[] getFilesystemName(String fieldName) {
-        List items = (List) files.get(fieldName);
+        List<FileItem> items = files.get(fieldName);
 
         if (items == null) {
             return null;
         }
 
         List<String> fileNames = new ArrayList<String>(items.size());
-        for (int i = 0; i < items.size(); i++) {
-            DiskFileItem fileItem = (DiskFileItem) items.get(i);
-            fileNames.add(fileItem.getStoreLocation().getName());
+        for (FileItem fileItem : items) {
+            fileNames.add(((DiskFileItem) fileItem).getStoreLocation().getName());
         }
 
-        return (String[]) fileNames.toArray(new String[fileNames.size()]);
+        return fileNames.toArray(new String[fileNames.size()]);
     }
 
     /* (non-Javadoc)
      * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getParameter(java.lang.String)
      */
     public String getParameter(String name) {
-        List v = (List) params.get(name);
+        List<String> v = params.get(name);
         if (v != null && v.size() > 0) {
-            return (String) v.get(0);
+            return v.get(0);
         }
 
         return null;
@@ -248,7 +245,7 @@
     public String[] getParameterValues(String name) {
         List<String> v = params.get(name);
         if (v != null && v.size() > 0) {
-            return (String[]) v.toArray(new String[v.size()]);
+            return v.toArray(new String[v.size()]);
         }
 
         return null;



Mime
View raw message