commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcucchi...@apache.org
Subject svn commit: r1197007 - /commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
Date Thu, 03 Nov 2011 09:07:53 GMT
Author: mcucchiara
Date: Thu Nov  3 09:07:53 2011
New Revision: 1197007

URL: http://svn.apache.org/viewvc?rev=1197007&view=rev
Log:
OGNL-37 - Remove unnecessary int boxing and redundant code.

Modified:
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java?rev=1197007&r1=1197006&r2=1197007&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
(original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
Thu Nov  3 09:07:53 2011
@@ -43,7 +43,7 @@ public class ArrayPropertyAccessor
         {
             if ( name.equals( "length" ) )
             {
-                result = new Integer( Array.getLength( target ) );
+                result = Array.getLength(target);
             }
             else
             {
@@ -65,13 +65,13 @@ public class ArrayPropertyAccessor
                         System.arraycopy( target, 0, result, 0, len );
                         break;
                     case DynamicSubscript.FIRST:
-                        index = new Integer( ( len > 0 ) ? 0 : -1 );
+                        index = ( len > 0 ) ? 0 : -1;
                         break;
                     case DynamicSubscript.MID:
-                        index = new Integer( ( len > 0 ) ? ( len / 2 ) : -1 );
+                        index = ( len > 0 ) ? ( len / 2 ) : -1;
                         break;
                     case DynamicSubscript.LAST:
-                        index = new Integer( ( len > 0 ) ? ( len - 1 ) : -1 );
+                        index = ( len > 0 ) ? ( len - 1 ) : -1;
                         break;
                     default: break;
                 }
@@ -97,20 +97,18 @@ public class ArrayPropertyAccessor
     public void setProperty( Map<String, Object> context, Object target, Object name,
Object value )
         throws OgnlException
     {
-        Object index = name;
-        boolean isNumber = ( index instanceof Number );
+        boolean isNumber = ( name instanceof Number );
 
-        if ( isNumber || ( index instanceof DynamicSubscript ) )
+        if ( isNumber || ( name instanceof DynamicSubscript ) )
         {
             TypeConverter converter = ( (OgnlContext) context ).getTypeConverter();
             Object convertedValue;
 
-            convertedValue =
-                converter.convertValue( context, target, null, name.toString(), value,
-                                        target.getClass().getComponentType() );
+            convertedValue = converter.convertValue( context, target, null, name.toString(),
value,
+                                                     target.getClass().getComponentType()
);
             if ( isNumber )
             {
-                int i = ( (Number) index ).intValue();
+                int i = ( (Number) name ).intValue();
 
                 if ( i >= 0 )
                 {
@@ -121,21 +119,13 @@ public class ArrayPropertyAccessor
             {
                 int len = Array.getLength( target );
 
-                switch ( ( (DynamicSubscript) index ).getFlag() )
+                switch ( ( (DynamicSubscript) name ).getFlag() )
                 {
                     case DynamicSubscript.ALL:
                         System.arraycopy( target, 0, convertedValue, 0, len );
                         return;
-                    case DynamicSubscript.FIRST:
-                        index = new Integer( ( len > 0 ) ? 0 : -1 );
-                        break;
-                    case DynamicSubscript.MID:
-                        index = new Integer( ( len > 0 ) ? ( len / 2 ) : -1 );
+                    default:
                         break;
-                    case DynamicSubscript.LAST:
-                        index = new Integer( ( len > 0 ) ? ( len - 1 ) : -1 );
-                        break;
-                    default: break;
                 }
             }
         }
@@ -147,7 +137,7 @@ public class ArrayPropertyAccessor
             }
             else
             {
-                throw new NoSuchPropertyException( target, index );
+                throw new NoSuchPropertyException( target, name );
             }
         }
     }



Mime
View raw message