harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r556564 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/PropertyDescriptor.java main/java/org/apache/harmony/beans/BeansUtils.java test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
Date Mon, 16 Jul 2007 09:10:01 GMT
Author: tonywu
Date: Mon Jul 16 02:09:58 2007
New Revision: 556564

URL: http://svn.apache.org/viewvc?view=rev&rev=556564
Log:
Add method hashCode() for PropertyDescriptor

Added:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/BeansUtils.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=556564&r1=556563&r2=556564
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
Mon Jul 16 02:09:58 2007
@@ -21,6 +21,8 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.Vector;
+
+import org.apache.harmony.beans.BeansUtils;
 import org.apache.harmony.beans.internal.nls.Messages;
 
 public class PropertyDescriptor extends FeatureDescriptor {
@@ -171,6 +173,15 @@
                     && constrainedPropertyAreEqual;
         }
         return result;
+    }
+    
+    @Override
+    public int hashCode() {
+        return BeansUtils.getHashCode(getter) + BeansUtils.getHashCode(setter)
+                + BeansUtils.getHashCode(getPropertyType())
+                + BeansUtils.getHashCode(getPropertyEditorClass())
+                + BeansUtils.getHashCode(isBound())
+                + BeansUtils.getHashCode(isConstrained());
     }
 
     public void setPropertyEditorClass(Class<?> propertyEditorClass) {

Added: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/BeansUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/BeansUtils.java?view=auto&rev=556564
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/BeansUtils.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/BeansUtils.java
Mon Jul 16 02:09:58 2007
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.beans;
+
+public class BeansUtils {
+    
+    public static final int getHashCode(Object o) {
+        return o != null ? o.hashCode() : 0;
+    }
+    
+    public static final int getHashCode(boolean b) {
+        return b?1:0;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/BeansUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java?view=diff&rev=556564&r1=556563&r2=556564
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
Mon Jul 16 02:09:58 2007
@@ -1129,5 +1129,25 @@
         public InvalidPropertyEditor2() {
         }
     }
+    
+    //Regression Test
+    
+    private class MockBean {
+        int a;
+        public int getA() {
+            return a;
+        }
 
+        public void setA(int a) {
+            this.a = a;
+        }
+    }
+    
+    public void testHashCode() throws IntrospectionException,
+            SecurityException, NoSuchMethodException {
+        PropertyDescriptor pd1 = new PropertyDescriptor("a",MockBean.class);
+        PropertyDescriptor pd2 = new PropertyDescriptor("a",MockBean.class);
+        assertEquals(pd1, pd2);
+        assertEquals(pd1.hashCode(), pd2.hashCode());
+    }
 }



Mime
View raw message