commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1103072 - /incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java
Date Sat, 14 May 2011 12:02:18 GMT
Author: simonetripodi
Date: Sat May 14 12:02:17 2011
New Revision: 1103072

URL: http://svn.apache.org/viewvc?rev=1103072&view=rev
Log:
simplified if-the-else chain in OgnlContext#removed(Object) method
removed IAE that can never thrown

Modified:
    incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java?rev=1103072&r1=1103071&r2=1103072&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java Sat May 14
12:02:17 2011
@@ -600,59 +600,53 @@ public class OgnlContext extends Object 
         return result;
     }
 
-    public Object remove(Object key)
+    public Object remove( Object key )
     {
-        Object result;
+        Object result = null;
 
-        if (RESERVED_KEYS.contains(key)) {
-            if (key.equals(OgnlContext.THIS_CONTEXT_KEY)) {
+        if ( RESERVED_KEYS.contains( key ) )
+        {
+            if ( key.equals( OgnlContext.CONTEXT_CONTEXT_KEY )
+                || key.equals( OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY )
+                || key.equals( OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY ) )
+            {
+                throw new IllegalArgumentException( "can't remove " + OgnlContext.CONTEXT_CONTEXT_KEY
+ " from context" );
+            }
+
+            if ( key.equals( OgnlContext.THIS_CONTEXT_KEY ) )
+            {
                 result = getCurrentObject();
-                setCurrentObject(null);
-            } else {
-                if (key.equals(OgnlContext.ROOT_CONTEXT_KEY)) {
-                    result = getRoot();
-                    setRoot(null);
-                } else {
-                    if (key.equals(OgnlContext.CONTEXT_CONTEXT_KEY)) {
-                        throw new IllegalArgumentException("can't remove " + OgnlContext.CONTEXT_CONTEXT_KEY
-                                + " from context");
-                    } else {
-                        if (key.equals(OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY)) {
-                            throw new IllegalArgumentException("can't remove "
-                                    + OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY + " from
context");
-                        } else {
-                            if (key.equals(OgnlContext.LAST_EVALUATION_CONTEXT_KEY)) {
-                                result = _lastEvaluation;
-                                setLastEvaluation(null);
-                            } else {
-                                if (key.equals(OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY))
{
-                                    throw new IllegalArgumentException("can't remove "
-                                            + OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY
+ " from context");
-                                } else {
-                                    if (key.equals(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY))
{
-                                        result = getClassResolver();
-                                        setClassResolver(null);
-                                    } else {
-                                        if (key.equals(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY))
{
-                                            result = getTypeConverter();
-                                            setTypeConverter(null);
-                                        } else {
-                                            if (key.equals(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY))
{
-                                                result = getMemberAccess();
-                                                setMemberAccess(null);
-                                            } else {
-                                                throw new IllegalArgumentException("unknown
reserved key '" + key + "'");
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
+                setCurrentObject( null );
+            }
+            else if ( key.equals( OgnlContext.ROOT_CONTEXT_KEY ) )
+            {
+                result = getRoot();
+                setRoot( null );
+            }
+            else if ( key.equals( OgnlContext.LAST_EVALUATION_CONTEXT_KEY ) )
+            {
+                result = _lastEvaluation;
+                setLastEvaluation( null );
             }
-        } else {
-            result = _values.remove(key);
+            else if ( key.equals( OgnlContext.CLASS_RESOLVER_CONTEXT_KEY ) )
+            {
+                result = getClassResolver();
+                setClassResolver( null );
+            }
+            else if ( key.equals( OgnlContext.TYPE_CONVERTER_CONTEXT_KEY ) )
+            {
+                result = getTypeConverter();
+                setTypeConverter( null );
+            }
+            else if ( key.equals( OgnlContext.MEMBER_ACCESS_CONTEXT_KEY ) )
+            {
+                result = getMemberAccess();
+                setMemberAccess( null );
+            }
+        }
+        else
+        {
+            result = _values.remove( key );
         }
         return result;
     }



Mime
View raw message