harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r598652 - in /harmony/enhanced/classlib/trunk/modules/accessibility/src: main/java/javax/accessibility/ test/api/java/common/javax/accessibility/
Date Tue, 27 Nov 2007 14:38:20 GMT
Author: tellison
Date: Tue Nov 27 06:38:19 2007
New Revision: 598652

URL: http://svn.apache.org/viewvc?rev=598652&view=rev
Log:
Fix for HARMONY-2457 ([classlib][accessibility] javax.accessibility.AccessibleRelationSet.relations
field is different on Harmony and RI)

Modified:
    harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleRelationSet.java
    harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleStateSet.java
    harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleRelationSetTest.java
    harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleStateSetTest.java

Modified: harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleRelationSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleRelationSet.java?rev=598652&r1=598651&r2=598652&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleRelationSet.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleRelationSet.java
Tue Nov 27 06:38:19 2007
@@ -26,34 +26,58 @@
 import java.util.Vector;
 
 public class AccessibleRelationSet {
+
     protected Vector<AccessibleRelation> relations;
 
     public AccessibleRelationSet() {
-        initStorage();
+        super();
     }
 
     public AccessibleRelationSet(final AccessibleRelation[] relations) {
-        initStorage(relations.length);
-        addAll(relations);
+        if (relations.length != 0) {
+            this.relations = new Vector<AccessibleRelation>(relations.length);
+            for (AccessibleRelation relation : relations) {
+                add(relation);
+            }
+        }
     }
 
-    public boolean add(final AccessibleRelation relation) {
+    public boolean add(AccessibleRelation relation) {
         initStorage();
-        if (contains(relation.key)) {
-            return false;
+
+        AccessibleRelation currentRelation = get(relation.getKey());
+        if (currentRelation == null) {
+            relations.addElement(relation);
+            return true;
+        }
+
+        Object[] currentTarget = currentRelation.getTarget();
+        int combinedLength = currentTarget.length + relation.getTarget().length;
+        Object[] combinedTarget = new Object[combinedLength];
+
+        for (int i = 0; i < currentTarget.length; i++) {
+            combinedTarget[i] = currentTarget[i];
+        }
+        int index = 0;
+        for (int i = currentTarget.length; i < combinedLength; i++) {
+            combinedTarget[i] = relation.getTarget()[index++];
         }
-        relations.add(relation);
+
+        currentRelation.setTarget(combinedTarget);
+
         return true;
     }
 
-    public void addAll(final AccessibleRelation[] relations) {
-        initStorage(relations.length);
-        for (AccessibleRelation element : relations) {
-            add(element);
+    public void addAll(AccessibleRelation[] relations) {
+        if (relations.length != 0) {
+            initStorage();
+            for (AccessibleRelation relation : relations) {
+                add(relation);
+            }
         }
     }
 
-    public boolean remove(final AccessibleRelation relation) {
+    public boolean remove(AccessibleRelation relation) {
         return relations != null && relations.remove(relation);
     }
 
@@ -67,16 +91,16 @@
         return relations == null ? 0 : relations.size();
     }
 
-    public boolean contains(final String key) {
+    public boolean contains(String key) {
         return get(key) != null;
     }
 
-    public AccessibleRelation get(final String key) {
+    public AccessibleRelation get(String key) {
         if (relations == null) {
             return null;
         }
         for (AccessibleRelation rel : relations) {
-            if(key.equals(rel.key)) {
+            if (key.equals(rel.key)) {
                 return rel;
             }
         }
@@ -84,8 +108,8 @@
     }
 
     public AccessibleRelation[] toArray() {
-        return relations == null ? new AccessibleRelation[0] :
-            relations.toArray(new AccessibleRelation[relations.size()]);
+        return relations == null ? new AccessibleRelation[0] : relations
+                .toArray(new AccessibleRelation[relations.size()]);
     }
 
     @Override
@@ -94,7 +118,8 @@
             return ""; //$NON-NLS-1$
         }
         StringBuffer result = new StringBuffer();
-        for (Iterator<AccessibleRelation> it = relations.iterator(); it.hasNext();
) {
+        for (Iterator<AccessibleRelation> it = relations.iterator(); it
+                .hasNext();) {
             result.append(it.next());
             if (it.hasNext()) {
                 result.append(","); //$NON-NLS-1$
@@ -103,15 +128,8 @@
         return result.toString();
     }
 
-
-    private void initStorage(final int capacity) {
-        if(relations == null) {
-            relations = new Vector<AccessibleRelation>(capacity);
-        }
-    }
-
     private void initStorage() {
-        if(relations == null) {
+        if (relations == null) {
             relations = new Vector<AccessibleRelation>();
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleStateSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleStateSet.java?rev=598652&r1=598651&r2=598652&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleStateSet.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/accessibility/src/main/java/javax/accessibility/AccessibleStateSet.java
Tue Nov 27 06:38:19 2007
@@ -26,15 +26,24 @@
 import java.util.Vector;
 
 public class AccessibleStateSet {
+
     protected Vector<AccessibleState> states;
 
     public AccessibleStateSet() {
-        initStorage();
+        super();
     }
 
-    public AccessibleStateSet(final AccessibleState[] states) {
-        initStorage(states.length);
-        addAll(states);
+    public AccessibleStateSet(AccessibleState[] states) {
+        super();
+        if (states.length == 0) {
+            return;
+        }
+        this.states = new Vector<AccessibleState>(states.length);
+        for (AccessibleState element : states) {
+            if (!this.states.contains(element)) {
+                this.states.addElement(element);
+            }
+        }
     }
 
     public boolean add(final AccessibleState state) {
@@ -47,17 +56,22 @@
     }
 
     public void addAll(final AccessibleState[] states) {
+        if (states.length == 0) {
+            return;
+        }
         initStorage(states.length);
         for (AccessibleState element : states) {
-            add(element);
+            if (!this.states.contains(element)) {
+                this.states.addElement(element);
+            }
         }
     }
 
-    public boolean contains(final AccessibleState state) {
+    public boolean contains(AccessibleState state) {
         return states == null ? false : states.contains(state);
     }
 
-    public boolean remove(final AccessibleState state) {
+    public boolean remove(AccessibleState state) {
         return states == null ? false : states.remove(state);
     }
 
@@ -68,17 +82,17 @@
     }
 
     public AccessibleState[] toArray() {
-        return states == null ? new AccessibleState[0] :
-            states.toArray(new AccessibleState[states.size()]);
+        return states == null ? new AccessibleState[0] : states
+                .toArray(new AccessibleState[states.size()]);
     }
 
     @Override
     public String toString() {
         if (states == null) {
-            return "null"; //$NON-NLS-1$
+            return null;
         }
         StringBuffer str = new StringBuffer();
-        for (Iterator<AccessibleState> it = states.iterator(); it.hasNext(); ) {
+        for (Iterator<AccessibleState> it = states.iterator(); it.hasNext();) {
             str.append(it.next().toString());
             if (it.hasNext()) {
                 str.append(","); //$NON-NLS-1$
@@ -99,4 +113,3 @@
         }
     }
 }
-

Modified: harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleRelationSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleRelationSetTest.java?rev=598652&r1=598651&r2=598652&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleRelationSetTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleRelationSetTest.java
Tue Nov 27 06:38:19 2007
@@ -17,6 +17,8 @@
 
 package javax.accessibility;
 
+import java.util.Vector;
+
 import junit.framework.TestCase;
 
 public class AccessibleRelationSetTest extends TestCase {
@@ -50,13 +52,17 @@
     }
 
     public void testAddContains() {
-        assertTrue("Should contain added item", set.contains(AccessibleRelation.CONTROLLED_BY));
-        assertTrue("Should contain added item", set.contains(AccessibleRelation.MEMBER_OF));
+        assertTrue("Should contain added item", set
+                .contains(AccessibleRelation.CONTROLLED_BY));
+        assertTrue("Should contain added item", set
+                .contains(AccessibleRelation.MEMBER_OF));
 
-        AccessibleRelation relation = new AccessibleRelation(AccessibleRelation.CONTROLLER_FOR);
+        AccessibleRelation relation = new AccessibleRelation(
+                AccessibleRelation.CONTROLLER_FOR);
+        assertTrue(set.add(relation));
         assertTrue(set.add(relation));
-        assertFalse(set.add(relation));
-        assertTrue("Should contain added item", set.contains(AccessibleRelation.CONTROLLER_FOR));
+        assertTrue("Should contain added item", set
+                .contains(AccessibleRelation.CONTROLLER_FOR));
         assertFalse("Should not contain not added item", set
                 .contains(AccessibleRelation.LABEL_FOR));
 
@@ -78,8 +84,8 @@
     public void testDupes() {
         AccessibleRelation dupeRelation = new AccessibleRelation(
                 AccessibleRelation.CONTROLLED_BY);
-        assertFalse("Should not add duplicate item", set.add(dupeRelation));
-        assertFalse("Should not add duplicate item", set.add(relations[0]));
+        assertTrue("Add duplicate item", set.add(dupeRelation));
+        assertTrue("Add duplicate item", set.add(relations[0]));
         assertNotSame(dupeRelation, set.get(AccessibleRelation.CONTROLLED_BY));
         assertSame(relations[0], set.get(AccessibleRelation.CONTROLLED_BY));
         set.remove(set.get(AccessibleRelation.CONTROLLED_BY));
@@ -87,8 +93,8 @@
         set.relations = null;
         set.addAll(relations);
         set.addAll(relations);
-        assertEquals("Should not add duplicate items in addAll", relations.length,
-                set.relations.size());
+        assertEquals("Should not add duplicate items in addAll",
+                relations.length, set.relations.size());
     }
 
     public void testGet() {
@@ -111,12 +117,29 @@
 
     public void testToString() {
         String stateSetString = set.toString();
-        assertTrue("String representation should contain elements representation",
+        assertTrue(
+                "String representation should contain elements representation",
                 stateSetString.indexOf(relations[0].toString()) >= 0);
-        assertTrue("String representation should contain elements representation",
+        assertTrue(
+                "String representation should contain elements representation",
                 stateSetString.indexOf(relations[1].toString()) >= 0);
 
         set.relations = null;
         set.toString();
+    }
+
+    // Regression for HARMONY-2457
+    public void test_constructor() {
+        TestAccessibleRelationSet obj = new TestAccessibleRelationSet();
+        assertNull(obj.relations);
+    }
+
+    static class TestAccessibleRelationSet extends AccessibleRelationSet {
+        Vector relations;
+
+        TestAccessibleRelationSet() {
+            super();
+            relations = super.relations;
+        }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleStateSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleStateSetTest.java?rev=598652&r1=598651&r2=598652&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleStateSetTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/accessibility/src/test/api/java/common/javax/accessibility/AccessibleStateSetTest.java
Tue Nov 27 06:38:19 2007
@@ -18,6 +18,7 @@
 package javax.accessibility;
 
 import java.util.Arrays;
+import java.util.Vector;
 
 import junit.framework.TestCase;
 
@@ -29,7 +30,8 @@
     @Override
     public void setUp() {
         stateSet = new AccessibleStateSet();
-        statesArray = new AccessibleState[] { AccessibleState.ACTIVE, AccessibleState.ARMED
};
+        statesArray = new AccessibleState[] { AccessibleState.ACTIVE,
+                AccessibleState.ARMED };
         stateSet.addAll(statesArray);
     }
 
@@ -40,7 +42,8 @@
     }
 
     public void testAccessibleStateSet() throws Exception {
-        AccessibleState[] statesArray = { AccessibleState.ACTIVE, AccessibleState.ARMED };
+        AccessibleState[] statesArray = { AccessibleState.ACTIVE,
+                AccessibleState.ARMED };
         stateSet = new AccessibleStateSet(statesArray);
         assertNotNull(stateSet.states);
 
@@ -52,8 +55,10 @@
     }
 
     public void testAddContains() throws Exception {
-        assertTrue("Must contain added state", stateSet.contains(AccessibleState.ACTIVE));
-        assertTrue("Must contain added state", stateSet.contains(AccessibleState.ARMED));
+        assertTrue("Must contain added state", stateSet
+                .contains(AccessibleState.ACTIVE));
+        assertTrue("Must contain added state", stateSet
+                .contains(AccessibleState.ARMED));
         boolean added = stateSet.add(AccessibleState.ACTIVE);
         assertEquals("Should not add duplicate item", 2, stateSet.states.size());
         assertFalse("Should not add duplicate item", added);
@@ -73,8 +78,8 @@
     public void testAddAll() {
         stateSet.addAll(statesArray);
         stateSet.addAll(statesArray);
-        assertEquals("Should not add duplicate items", statesArray.length, stateSet.states
-                .size());
+        assertEquals("Should not add duplicate items", statesArray.length,
+                stateSet.states.size());
 
         try {
             stateSet.addAll(null);
@@ -87,7 +92,8 @@
         boolean removed = stateSet.remove(AccessibleState.ICONIFIED);
         assertFalse("Should not remove non-existing item", removed);
         removed = stateSet.remove(AccessibleState.ACTIVE);
-        assertFalse("Should remove existing item", stateSet.contains(AccessibleState.ACTIVE));
+        assertFalse("Should remove existing item", stateSet
+                .contains(AccessibleState.ACTIVE));
         assertTrue("Should remove existing item", removed);
     }
 
@@ -102,9 +108,11 @@
 
     public void testToString() throws Exception {
         String stateSetString = stateSet.toString();
-        assertTrue("String representation should contain elements representation",
+        assertTrue(
+                "String representation should contain elements representation",
                 stateSetString.indexOf(AccessibleState.ACTIVE.toString()) >= 0);
-        assertTrue("String representation should contain elements representation",
+        assertTrue(
+                "String representation should contain elements representation",
                 stateSetString.indexOf(AccessibleState.ARMED.toString()) >= 0);
 
         stateSet.states = null;
@@ -129,4 +137,20 @@
         stateSet.states = null;
         Arrays.asList(stateSet.toArray());
     }
+
+    // Regression for HARMONY-2457
+    public void test_constructor() {
+        TestAccessibleStateSet obj = new TestAccessibleStateSet();
+        assertNull(obj.states);
+    }
+
+    static class TestAccessibleStateSet extends AccessibleStateSet {
+        Vector states;
+
+        TestAccessibleStateSet() {
+            super();
+            states = super.states;
+        }
+    }
+
 }



Mime
View raw message