commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1103067 - /incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java
Date Sat, 14 May 2011 11:53:51 GMT
Author: simonetripodi
Date: Sat May 14 11:53:51 2011
New Revision: 1103067

URL: http://svn.apache.org/viewvc?rev=1103067&view=rev
Log:
simplified if-the-else chain in OgnlContext#put(Object,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=1103067&r1=1103066&r2=1103067&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
11:53:51 2011
@@ -540,61 +540,63 @@ public class OgnlContext extends Object 
         return result;
     }
 
-    public Object put(Object key, Object value)
+    public Object put( Object key, Object value )
     {
-        Object result;
-        
-        if (RESERVED_KEYS.contains(key)) {
-            if (key.equals(OgnlContext.THIS_CONTEXT_KEY)) {
+        Object result = null;
+
+        if ( RESERVED_KEYS.contains( key ) )
+        {
+            if ( key.equals( OgnlContext.CONTEXT_CONTEXT_KEY ) )
+            {
+                throw new IllegalArgumentException( "can't change " + OgnlContext.CONTEXT_CONTEXT_KEY
+ " in context" );
+            }
+
+            if ( key.equals( OgnlContext.THIS_CONTEXT_KEY ) )
+            {
                 result = getCurrentObject();
-                setCurrentObject(value);
-            } else {
-                if (key.equals(OgnlContext.ROOT_CONTEXT_KEY)) {
-                    result = getRoot();
-                    setRoot(value);
-                } else {
-                    if (key.equals(OgnlContext.CONTEXT_CONTEXT_KEY)) {
-                        throw new IllegalArgumentException("can't change " + OgnlContext.CONTEXT_CONTEXT_KEY
-                                + " in context");
-                    } else {
-                        if (key.equals(OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY)) {
-                            result = getTraceEvaluations() ? Boolean.TRUE : Boolean.FALSE;
-                            setTraceEvaluations(OgnlOps.booleanValue(value));
-                        } else {
-                            if (key.equals(OgnlContext.LAST_EVALUATION_CONTEXT_KEY)) {
-                                result = getLastEvaluation();
-                                _lastEvaluation = (Evaluation) value;
-                            } else {
-                                if (key.equals(OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY))
{
-                                    result = getKeepLastEvaluation() ? Boolean.TRUE : Boolean.FALSE;
-                                    setKeepLastEvaluation(OgnlOps.booleanValue(value));
-                                } else {
-                                    if (key.equals(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY))
{
-                                        result = getClassResolver();
-                                        setClassResolver((ClassResolver) value);
-                                    } else {
-                                        if (key.equals(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY))
{
-                                            result = getTypeConverter();
-                                            setTypeConverter((TypeConverter) value);
-                                        } else {
-                                            if (key.equals(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY))
{
-                                                result = getMemberAccess();
-                                                setMemberAccess((MemberAccess) value);
-                                            } else {
-                                                throw new IllegalArgumentException("unknown
reserved key '" + key + "'");
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
+                setCurrentObject( value );
+            }
+            else if ( key.equals( OgnlContext.ROOT_CONTEXT_KEY ) )
+            {
+                result = getRoot();
+                setRoot( value );
+            }
+            else if ( key.equals( OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY ) )
+            {
+                result = getTraceEvaluations() ? Boolean.TRUE : Boolean.FALSE;
+                setTraceEvaluations( OgnlOps.booleanValue( value ) );
+            }
+            else if ( key.equals( OgnlContext.LAST_EVALUATION_CONTEXT_KEY ) )
+            {
+                result = getLastEvaluation();
+                _lastEvaluation = (Evaluation) value;
+            }
+            else if ( key.equals( OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY ) )
+            {
+                result = getKeepLastEvaluation() ? Boolean.TRUE : Boolean.FALSE;
+                setKeepLastEvaluation( OgnlOps.booleanValue( value ) );
+            }
+            else if ( key.equals( OgnlContext.CLASS_RESOLVER_CONTEXT_KEY ) )
+            {
+                result = getClassResolver();
+                setClassResolver( (ClassResolver) value );
+            }
+            else if ( key.equals( OgnlContext.TYPE_CONVERTER_CONTEXT_KEY ) )
+            {
+                result = getTypeConverter();
+                setTypeConverter( (TypeConverter) value );
+            }
+            else if ( key.equals( OgnlContext.MEMBER_ACCESS_CONTEXT_KEY ) )
+            {
+                result = getMemberAccess();
+                setMemberAccess( (MemberAccess) value );
             }
-        } else {
-            result = _values.put(key, value);
         }
-        
+        else
+        {
+            result = _values.put( key, value );
+        }
+
         return result;
     }
 



Mime
View raw message