commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1163814 - in /commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web: portlet/PortletSessionScopeMap.java servlet/ServletSessionScopeMap.java
Date Wed, 31 Aug 2011 20:50:07 GMT
Author: mbenson
Date: Wed Aug 31 20:50:06 2011
New Revision: 1163814

URL: http://svn.apache.org/viewvc?rev=1163814&view=rev
Log:
code simplifications; merge 'if (foo) return true; else return false;' type constructs; remove
unnecessary parens; remove unnecessary elses

Modified:
    commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
    commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java

Modified: commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java?rev=1163814&r1=1163813&r2=1163814&view=diff
==============================================================================
--- commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
(original)
+++ commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
Wed Aug 31 20:50:06 2011
@@ -60,27 +60,23 @@ final class PortletSessionScopeMap imple
 
 
     public boolean containsKey(Object key) {
-        if (sessionExists()) {
-            return (session.getAttribute(key(key)) != null);
-        } else {
-            return false;
-        }
+        return sessionExists() && session.getAttribute(key(key)) != null;
     }
 
 
     public boolean containsValue(Object value) {
         if (value == null || !sessionExists()) {
-            return (false);
+            return false;
         }
         Enumeration<String> keys =
         session.getAttributeNames(PortletSession.PORTLET_SCOPE);
         while (keys.hasMoreElements()) {
             Object next = session.getAttribute(keys.nextElement());
             if (value.equals(next)) {
-                return (true);
+                return true;
             }
         }
-        return (false);
+        return false;
     }
 
 
@@ -95,43 +91,33 @@ final class PortletSessionScopeMap imple
                 set.add(new MapEntry<String, Object>(key, session.getAttribute(key),
true));
             }
         }
-        return (set);
+        return set;
     }
 
 
     public boolean equals(Object o) {
-        if (sessionExists()) {
-            return (session.equals(o));
-        } else {
-            return false;
-        }
+        return sessionExists() && session.equals(o);
     }
 
 
     public Object get(Object key) {
         if (sessionExists()) {
-            return (session.getAttribute(key(key)));
-        } else {
-            return null;
+            return session.getAttribute(key(key));
         }
+        return null;
     }
 
 
     public int hashCode() {
         if (sessionExists()) {
-            return (session.hashCode());
-        } else {
-            return 0;
+            return session.hashCode();
         }
+        return 0;
     }
 
 
     public boolean isEmpty() {
-        if (sessionExists() &&
-            session.getAttributeNames().hasMoreElements()) {
-            return false;
-        }
-        return true;
+        return !sessionExists() || !session.getAttributeNames().hasMoreElements();
     }
 
 
@@ -144,13 +130,13 @@ final class PortletSessionScopeMap imple
                 set.add(keys.nextElement());
             }
         }
-        return (set);
+        return set;
     }
 
 
     public Object put(String key, Object value) {
         if (value == null) {
-            return (remove(key));
+            return remove(key);
         }
 
         // Ensure the Session is created, if it
@@ -163,7 +149,7 @@ final class PortletSessionScopeMap imple
         String skey = key(key);
         Object previous = session.getAttribute(skey);
         session.setAttribute(skey, value);
-        return (previous);
+        return previous;
     }
 
 
@@ -179,10 +165,9 @@ final class PortletSessionScopeMap imple
             String skey = key(key);
             Object previous = session.getAttribute(skey);
             session.removeAttribute(skey);
-            return (previous);
-        } else {
-            return (null);
+            return previous;
         }
+        return null;
     }
 
 
@@ -196,7 +181,7 @@ final class PortletSessionScopeMap imple
                 n++;
             }
         }
-        return (n);
+        return n;
     }
 
 
@@ -209,18 +194,18 @@ final class PortletSessionScopeMap imple
                 list.add(session.getAttribute(keys.nextElement()));
             }
         }
-        return (list);
+        return list;
     }
 
 
     private String key(Object key) {
         if (key == null) {
             throw new IllegalArgumentException();
-        } else if (key instanceof String) {
-            return ((String) key);
-        } else {
-            return (key.toString());
         }
+        if (key instanceof String) {
+            return (String) key;
+        }
+        return key.toString();
     }
 
     private boolean sessionExists() {
@@ -230,10 +215,7 @@ final class PortletSessionScopeMap imple
                 request = null;
             }
         }
-        if (session != null) {
-            return true;
-        }
-        return false;
+        return session != null;
     }
 
 }

Modified: commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java?rev=1163814&r1=1163813&r2=1163814&view=diff
==============================================================================
--- commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
(original)
+++ commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
Wed Aug 31 20:50:06 2011
@@ -60,26 +60,22 @@ final class ServletSessionScopeMap imple
 
 
     public boolean containsKey(Object key) {
-        if (sessionExists()) {
-            return (session.getAttribute(key(key)) != null);
-        } else {
-            return false;
-        }
+        return sessionExists() && session.getAttribute(key(key)) != null;
     }
 
 
     public boolean containsValue(Object value) {
         if (value == null || !sessionExists()) {
-            return (false);
+            return false;
         }
         Enumeration<String> keys = session.getAttributeNames();
         while (keys.hasMoreElements()) {
             Object next = session.getAttribute(keys.nextElement());
             if (value.equals(next)) {
-                return (true);
+                return true;
             }
         }
-        return (false);
+        return false;
     }
 
 
@@ -93,43 +89,33 @@ final class ServletSessionScopeMap imple
                 set.add(new MapEntry(key, session.getAttribute(key), true));
             }
         }
-        return (set);
+        return set;
     }
 
 
     public boolean equals(Object o) {
-        if (sessionExists()) {
-            return (session.equals(o));
-        } else {
-            return false;
-        }
+        return sessionExists() && session.equals(o);
     }
 
 
     public Object get(Object key) {
         if (sessionExists()) {
-            return (session.getAttribute(key(key)));
-        } else {
-            return null;
+            return session.getAttribute(key(key));
         }
+        return null;
     }
 
 
     public int hashCode() {
         if (sessionExists()) {
-            return (session.hashCode());
-        } else {
-            return 0;
+            return session.hashCode();
         }
+        return 0;
     }
 
 
     public boolean isEmpty() {
-        if (sessionExists() &&
-            session.getAttributeNames().hasMoreElements()) {
-            return false;
-        }
-        return true;
+        return !sessionExists() || !session.getAttributeNames().hasMoreElements() ;
     }
 
 
@@ -141,13 +127,13 @@ final class ServletSessionScopeMap imple
                 set.add(keys.nextElement());
             }
         }
-        return (set);
+        return set;
     }
 
 
     public Object put(String key, Object value) {
         if (value == null) {
-            return (remove(key));
+            return remove(key);
         }
 
         // Ensure the Session is created, if it
@@ -159,7 +145,7 @@ final class ServletSessionScopeMap imple
 
         Object previous = session.getAttribute(key);
         session.setAttribute(key, value);
-        return (previous);
+        return previous;
     }
 
 
@@ -175,10 +161,9 @@ final class ServletSessionScopeMap imple
             String skey = key(key);
             Object previous = session.getAttribute(skey);
             session.removeAttribute(skey);
-            return (previous);
-        } else {
-            return (null);
+            return previous;
         }
+        return null;
     }
 
 
@@ -191,7 +176,7 @@ final class ServletSessionScopeMap imple
                 n++;
             }
         }
-        return (n);
+        return n;
     }
 
 
@@ -203,18 +188,18 @@ final class ServletSessionScopeMap imple
                 list.add(session.getAttribute(keys.nextElement()));
             }
         }
-        return (list);
+        return list;
     }
 
 
     private String key(Object key) {
         if (key == null) {
             throw new IllegalArgumentException();
-        } else if (key instanceof String) {
-            return ((String) key);
-        } else {
-            return (key.toString());
         }
+        if (key instanceof String) {
+            return (String) key;
+        }
+        return key.toString();
     }
 
     private boolean sessionExists() {
@@ -224,10 +209,7 @@ final class ServletSessionScopeMap imple
                 request = null;
             }
         }
-        if (session != null) {
-            return true;
-        }
-        return false;
+        return session != null;
     }
 
 }



Mime
View raw message