svn commit: r682054 - in /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util: FileUtil.java UtilHttp.java UtilMisc.java UtilPlist.java cache/CacheLineTable.java cache/UtilCache.java collections/MapComparator.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r682054 - in /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util: FileUtil.java UtilHttp.java UtilMisc.java UtilPlist.java cache/CacheLineTable.java cache/UtilCache.java collections/MapComparator.java

doogie-3
Author: doogie
Date: Sat Aug  2 14:35:29 2008
New Revision: 682054

URL: http://svn.apache.org/viewvc?rev=682054&view=rev
Log:
More misc. generics/java15 markup.

Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilMisc.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLineTable.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapComparator.java

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java Sat Aug  2 14:35:29 2008
@@ -171,7 +171,7 @@
         return readTextFile(file, newline);
     }
 
-    public static void searchFiles(List fileList, File path, FilenameFilter filter, boolean includeSubfolders) throws IOException {
+    public static void searchFiles(List<File> fileList, File path, FilenameFilter filter, boolean includeSubfolders) throws IOException {
         // Get filtered files in the current path
         File[] files = path.listFiles(filter);
         

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Sat Aug  2 14:35:29 2008
@@ -82,7 +82,7 @@
      * -- this method will only use the skip names for session and servlet context attributes
      * @return The resulting Map
      */
-    public static Map<String, Object> getCombinedMap(HttpServletRequest request, Set<String> namesToSkip) {
+    public static Map<String, Object> getCombinedMap(HttpServletRequest request, Set<? extends String> namesToSkip) {
         FastMap<String, Object> combinedMap = FastMap.newInstance();
         combinedMap.putAll(getServletContextMap(request, namesToSkip)); // bottom level application attributes
         combinedMap.putAll(getSessionMap(request, namesToSkip));        // session overrides application
@@ -104,7 +104,7 @@
      * Create a map from a HttpServletRequest (parameters) object
      * @return The resulting Map
      */
-    public static Map<String, Object> getParameterMap(HttpServletRequest request, Set<String> namesToSkip) {
+    public static Map<String, Object> getParameterMap(HttpServletRequest request, Set<? extends String> namesToSkip) {
         Map<String, Object> paramMap = FastMap.newInstance();
 
         // add all the actual HTTP request parameters
@@ -191,7 +191,7 @@
      * Create a map from a HttpRequest (attributes) object
      * @return The resulting Map
      */
-    public static Map<String, Object> getAttributeMap(HttpServletRequest request, Set<String> namesToSkip) {
+    public static Map<String, Object> getAttributeMap(HttpServletRequest request, Set<? extends String> namesToSkip) {
         Map<String, Object> attributeMap = FastMap.newInstance();
 
         // look at all request attributes
@@ -225,7 +225,7 @@
      * Create a map from a HttpSession object
      * @return The resulting Map
      */
-    public static Map<String, Object> getSessionMap(HttpServletRequest request, Set<String> namesToSkip) {
+    public static Map<String, Object> getSessionMap(HttpServletRequest request, Set<? extends String> namesToSkip) {
         Map<String, Object> sessionMap = FastMap.newInstance();
         HttpSession session = request.getSession();
 
@@ -260,7 +260,7 @@
      * Create a map from a ServletContext object
      * @return The resulting Map
      */
-    public static Map<String, Object> getServletContextMap(HttpServletRequest request, Set<String> namesToSkip) {
+    public static Map<String, Object> getServletContextMap(HttpServletRequest request, Set<? extends String> namesToSkip) {
         Map<String, Object> servletCtxMap = FastMap.newInstance();
 
         // look at all servlet context attributes
@@ -287,31 +287,30 @@
         return makeParamMapWithPrefix(request, null, prefix, suffix);
     }
 
-    public static Map<String, Object> makeParamMapWithPrefix(HttpServletRequest request, Map<String, Object> additionalFields, String prefix, String suffix) {
+    public static Map<String, Object> makeParamMapWithPrefix(HttpServletRequest request, Map<String, ? extends Object> additionalFields, String prefix, String suffix) {
         return makeParamMapWithPrefix(getParameterMap(request), additionalFields, prefix, suffix);
     }
 
-    public static Map<String, Object> makeParamMapWithPrefix(Map<String, Object> context, Map<String, Object> additionalFields, String prefix, String suffix) {
+    public static Map<String, Object> makeParamMapWithPrefix(Map<String, ? extends Object> context, Map<String, ? extends Object> additionalFields, String prefix, String suffix) {
         Map<String, Object> paramMap = new HashMap<String, Object>();
-        Iterator parameterNames = context.keySet().iterator();
-        while (parameterNames.hasNext()) {
-            String parameterName = (String) parameterNames.next();
+        for (Map.Entry<String, ? extends Object> entry: context.entrySet()) {
+            String parameterName = entry.getKey();
             if (parameterName.startsWith(prefix)) {
                 if (suffix != null && suffix.length() > 0) {
                     if (parameterName.endsWith(suffix)) {
                         String key = parameterName.substring(prefix.length(), parameterName.length() - (suffix.length()));
-                        String value = (String)context.get(parameterName);
+                        String value = (String)entry.getValue();
                         paramMap.put(key, value);
                     }
                 } else {
                     String key = parameterName.substring(prefix.length());
-                    String value = (String)context.get(parameterName);
+                    String value = (String)entry.getValue();
                     paramMap.put(key, value);
                 }
             }
         }
         if (additionalFields != null) {
-            for (Map.Entry<String, Object> entry: additionalFields.entrySet()) {
+            for (Map.Entry<String, ? extends Object> entry: additionalFields.entrySet()) {
                 String fieldName = entry.getKey();
                 if (fieldName.startsWith(prefix)) {
                     if (suffix != null && suffix.length() > 0) {
@@ -377,7 +376,7 @@
         return makeParamListWithSuffix(request, null, suffix, prefix);
     }
 
-    public static List<Object> makeParamListWithSuffix(HttpServletRequest request, Map<String, Object> additionalFields, String suffix, String prefix) {
+    public static List<Object> makeParamListWithSuffix(HttpServletRequest request, Map<String, ? extends Object> additionalFields, String suffix, String prefix) {
         List<Object> paramList = new ArrayList<Object>();
         Enumeration parameterNames = request.getParameterNames();
         while (parameterNames.hasMoreElements()) {
@@ -395,7 +394,7 @@
             }
         }
         if (additionalFields != null) {
-            for (Map.Entry<String, Object> entry: additionalFields.entrySet()) {
+            for (Map.Entry<String, ? extends Object> entry: additionalFields.entrySet()) {
                 String fieldName = entry.getKey();
                 if (fieldName.endsWith(suffix)) {
                     if (prefix != null && prefix.length() > 0) {
@@ -628,15 +627,15 @@
     }
 
     /** URL Encodes a Map of arguements */
-    public static String urlEncodeArgs(Map<String, Object> args) {
+    public static String urlEncodeArgs(Map<String, ? extends Object> args) {
      return urlEncodeArgs(args, true);
     }
 
     /** URL Encodes a Map of arguements */
-    public static String urlEncodeArgs(Map<String, Object> args, boolean useExpandedEntites) {
+    public static String urlEncodeArgs(Map<String, ? extends Object> args, boolean useExpandedEntites) {
         StringBuilder buf = new StringBuilder();
         if (args != null) {
-            for (Map.Entry<String, Object> entry: args.entrySet()) {
+            for (Map.Entry<String, ? extends Object> entry: args.entrySet()) {
                 String name = entry.getKey();
                 Object value = entry.getValue();
                 String valueStr = null;
@@ -1171,13 +1170,12 @@
     }
     /** Returns the number or rows submitted by a multi form.
      */
-    public static int getMultiFormRowCount(Map requestMap) {
+    public static int getMultiFormRowCount(Map<String, ?> requestMap) {
         // The number of multi form rows is computed selecting the maximum index
         int rowCount = 0;
-        Set<String> parameterNames = requestMap.keySet();
         String maxRowIndex = "";
         int rowDelimiterLength = UtilHttp.MULTI_ROW_DELIMITER.length();
-        for (String parameterName: parameterNames) {
+        for (String parameterName: requestMap.keySet()) {
             int rowDelimiterIndex = (parameterName != null? parameterName.indexOf(UtilHttp.MULTI_ROW_DELIMITER): -1);
             if (rowDelimiterIndex > 0) {
                 String thisRowIndex = parameterName.substring(rowDelimiterIndex + rowDelimiterLength);

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilMisc.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilMisc.java Sat Aug  2 14:35:29 2008
@@ -146,6 +146,7 @@
      * Create a map from passed nameX, valueX parameters
      * @return The resulting Map
      */
+    @SuppressWarnings("unchecked")
     public static <K, V> Map<String, V> toMap(Object... data) {
         if (data == null) {
             return null;
@@ -681,6 +682,7 @@
             this.values[3] = value4;
         }
 
+        @SuppressWarnings("unchecked")
         protected void makeRealMap() {
             realMapIfNeeded = FastMap.newInstance();
             for (int i = 0; i < names.length; i++) {
@@ -733,6 +735,7 @@
             }
         }
 
+        @SuppressWarnings("unchecked")
         public V get(Object obj) {
             if (realMapIfNeeded != null) {
                 return realMapIfNeeded.get(obj);

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilPlist.java Sat Aug  2 14:35:29 2008
@@ -29,6 +29,9 @@
 import java.util.List;
 import java.util.Map;
 
+import static org.ofbiz.base.util.UtilGenerics.checkList;
+import static org.ofbiz.base.util.UtilGenerics.checkMap;
+
 /**
  * File Utilities
  *
@@ -46,9 +49,11 @@
         writer.print(" = ");
         if (value instanceof Map) {
             writer.println();
-            writePlistPropertyMap((Map<String, Object>) value, indentLevel, writer, false);
+            Map<String, Object> map = checkMap(value);
+            writePlistPropertyMap(map, indentLevel, writer, false);
         } else if (value instanceof List) {
-            writePlistPropertyValueList((List<Object>) value, indentLevel, writer);
+            List<Object> list = checkList(value);
+            writePlistPropertyValueList(list, indentLevel, writer);
         } else {
             writer.print(value);
             writer.println(";");
@@ -75,7 +80,7 @@
         while (propertyValueIter.hasNext()) {
             Object propertyValue = propertyValueIter.next();
             if (propertyValue instanceof Map) {
-                Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
+                Map<String, Object> propertyMap = checkMap(propertyValue);
                 writePlistPropertyMap(propertyMap, indentLevel + 1, writer, propertyValueIter.hasNext());
             } else {
                 writer.print(propertyValue);
@@ -93,9 +98,11 @@
         writer.print(name);
         writer.println("</key>");
         if (value instanceof Map) {
-            writePlistPropertyMapXml((Map<String, Object>) value, indentLevel, writer);
+            Map<String, Object> map = checkMap(value);
+            writePlistPropertyMapXml(map, indentLevel, writer);
         } else if (value instanceof List) {
-            writePlistPropertyValueListXml((List<Object>) value, indentLevel, writer);
+            List<Object> list = checkList(value);
+            writePlistPropertyValueListXml(list, indentLevel, writer);
         } else {
             for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);
             writer.print("<string>");
@@ -121,7 +128,7 @@
         while (propertyValueIter.hasNext()) {
             Object propertyValue = propertyValueIter.next();
             if (propertyValue instanceof Map) {
-                Map<String, Object> propertyMap = (Map<String, Object>) propertyValue;
+                Map<String, Object> propertyMap = checkMap(propertyValue);
                 writePlistPropertyMapXml(propertyMap, indentLevel, writer);
             } else {
                 for (int i = 0; i < indentLevel; i++) writer.print(indentFourString);

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLineTable.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLineTable.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLineTable.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/CacheLineTable.java Sat Aug  2 14:35:29 2008
@@ -85,6 +85,35 @@
         this.setLru(maxInMemory);
     }
 
+    @SuppressWarnings("unchecked")
+    private CacheLine<V> getFileTable(Object key) throws IOException {
+        return (CacheLine<V>) fileTable.get(key);
+    }
+
+
+    @SuppressWarnings("unchecked")
+    private void addAllFileTableValues(List<CacheLine<V>> values) throws IOException {
+        jdbm.helper.FastIterator iter = fileTable.values();
+        Object value = iter.next();
+        while (value != null) {
+            values.add((CacheLine<V>) value);
+            value = iter.next();
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void addAllFileTableKeys(Set<K> keys) throws IOException {
+        jdbm.helper.FastIterator iter = fileTable.keys();
+        Object key = null;
+        while ((key = iter.next()) != null) {
+            if (key instanceof ObjectType.NullObject) {
+                keys.add(null);
+            } else {
+                keys.add((K) key);
+            }
+        }
+    }
+
     public synchronized CacheLine<V> put(K key, CacheLine<V> value) {
         CacheLine<V> oldValue;
         if (key == null) {
@@ -101,7 +130,7 @@
         }
         if (fileTable != null) {
             try {
-                if (oldValue == null) oldValue = (CacheLine<V>) fileTable.get(key);
+                if (oldValue == null) oldValue = getFileTable(key);
                 fileTable.put(key != null ? key : ObjectType.NULL, value);                
                 CacheLineTable.jdbmMgr.commit();
             } catch (IOException e) {
@@ -132,7 +161,7 @@
         if (value == null) {
             if (fileTable != null) {
                 try {
-                    value = (CacheLine<V>) fileTable.get(key != null ? key : ObjectType.NULL);
+                    value = getFileTable(key != null ? key : ObjectType.NULL);
                 } catch (IOException e) {
                     Debug.logError(e, module);
                 }
@@ -171,12 +200,7 @@
 
         if (fileTable != null) {
             try {
-                jdbm.helper.FastIterator iter = fileTable.values();
-                Object value = iter.next();
-                while (value != null) {
-                    values.add((CacheLine<V>) value);
-                    value = iter.next();
-                }
+                addAllFileTableValues(values);
             } catch (IOException e) {
                 Debug.logError(e, module);
             }
@@ -198,15 +222,7 @@
 
         if (fileTable != null) {
             try {
-                jdbm.helper.FastIterator iter = fileTable.keys();
-                Object key = null;
-                while ((key = iter.next()) != null) {
-                    if (key instanceof ObjectType.NullObject) {
-                        keys.add(null);
-                    } else {
-                        keys.add((K) key);
-                    }
-                }
+                addAllFileTableKeys(keys);
             } catch (IOException e) {
                 Debug.logError(e, module);
             }

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/cache/UtilCache.java Sat Aug  2 14:35:29 2008
@@ -373,6 +373,7 @@
     }
     
     /** This is used for internal remove calls because we only want to count external calls */
+    @SuppressWarnings("unchecked")
     protected synchronized V removeInternal(Object key, boolean countRemove) {        
         CacheLine<V> line = cacheLineTable.remove(key);
         if (line != null) {
@@ -665,6 +666,7 @@
         cache.clear();
     }
 
+    @SuppressWarnings("unchecked")
     public static <K, V> UtilCache<K, V> findCache(String cacheName) {
         synchronized (UtilCache.utilCacheTable) {
             return (UtilCache<K, V>) UtilCache.utilCacheTable.get(cacheName);

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapComparator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapComparator.java?rev=682054&r1=682053&r2=682054&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapComparator.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapComparator.java Sat Aug  2 14:35:29 2008
@@ -24,6 +24,7 @@
 import java.util.Map;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilGenerics;
 
 /**
  * MapComparator.java
@@ -105,9 +106,8 @@
             if (compareResult == 0) {
                 try {
                     // the map values in question MUST implement the Comparable interface, if not we'll throw an exception
-                    Comparable comp1 = (Comparable) o1;
-                    Comparable comp2 = (Comparable) o2;
-                    compareResult = comp1.compareTo(comp2);
+                    Comparable<Object> comp1 = UtilGenerics.cast(o1);
+                    compareResult = comp1.compareTo(o2);
                 } catch (Exception e) {
                     String errorMessage = "Error sorting list of Maps: " + e.toString();
                     Debug.logError(e, errorMessage, module);