Harmony
  1. Harmony
  2. HARMONY-4203

[classlib][luni][java6] New feature of java.util.PriorityQueue for java6

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      I've added the new feature of java.util.PriorityQueue for java6:
      1. the behavior of remove method is changed, and some relative test cases is added
      2. some methods in "java.util.AbstractCollection" of java5 are moved into java.util.PriorityQueue (push down) of java6, also with some relative test cases:
      public boolean contains(Object object)
      public Object[] toArray()
      public <T> T[] toArray(T[] array)

        Activity

        Hide
        Robert Hu added a comment -

        Please try this patch.
        Thanks a lot!

        Show
        Robert Hu added a comment - Please try this patch. Thanks a lot!
        Hide
        Tim Ellison added a comment -

        Robert, can you confirm that these are Java 6 specific?

        Show
        Tim Ellison added a comment - Robert, can you confirm that these are Java 6 specific?
        Hide
        Robert Hu added a comment -

        Tim. I think at least half of this patch is Java 6 specific.
        #1 (change of "remove" method) is a different behavior in Java 6, you can also apply this patch into Java 5 trunk and you can see the updated PriorityQueueTest can passes on RI 6 but fails on RI 5. So, it is Java 6 specific.
        #2 may be also a feature of Java 5. But according to the spec, there's no doc of methods "contains(Object object),toArray(),toArray(T[] array)" of PriorityQueue in Java 5. In Java 5, these 3 methods are maked as "Methods inherited from sub class XXX". We can see that they're "pulled down" to the class PriorityQueue in Java 6.

        So, I think we have two choices now, one is to apply this patch only into Java 6 branch, the other is to split it into 2 patches, one for Java 5 including the 3 inherited methods and one for Java 6 including only the update of "remove" mehtod and related test cases.

        Tim, any idea? Thanks a lot!

        Show
        Robert Hu added a comment - Tim. I think at least half of this patch is Java 6 specific. #1 (change of "remove" method) is a different behavior in Java 6, you can also apply this patch into Java 5 trunk and you can see the updated PriorityQueueTest can passes on RI 6 but fails on RI 5. So, it is Java 6 specific. #2 may be also a feature of Java 5. But according to the spec, there's no doc of methods "contains(Object object),toArray(),toArray(T[] array)" of PriorityQueue in Java 5. In Java 5, these 3 methods are maked as "Methods inherited from sub class XXX". We can see that they're "pulled down" to the class PriorityQueue in Java 6. So, I think we have two choices now, one is to apply this patch only into Java 6 branch, the other is to split it into 2 patches, one for Java 5 including the 3 inherited methods and one for Java 6 including only the update of "remove" mehtod and related test cases. Tim, any idea? Thanks a lot!
        Hide
        Tim Ellison added a comment -

        Sorry for being unclear.

        I was wondering specifically if the changes you propose for PriorityQueue#remove(Object) are also applicable for Java 5? It looks like it to me.

        i.e.

        @@ -230,17 +231,13 @@
        if (o == null)

        { return false; }
        • int targetIndex;
        • for (targetIndex = 0; targetIndex < size; targetIndex++) {
        • if (0 == this.compare((E) o, elements[targetIndex])) {
        • break;
          + for (int i = 0; i < size; i++)
          Unknown macro: {+ if (elements[i].equals(o)) { + removeAt(i); + return true; } }
        • if (size == 0 || size == targetIndex) { - return false; - }
        • removeAt(targetIndex);
        • return true;
          + return false;
          }
        Show
        Tim Ellison added a comment - Sorry for being unclear. I was wondering specifically if the changes you propose for PriorityQueue#remove(Object) are also applicable for Java 5? It looks like it to me. i.e. @@ -230,17 +231,13 @@ if (o == null) { return false; } int targetIndex; for (targetIndex = 0; targetIndex < size; targetIndex++) { if (0 == this.compare((E) o, elements [targetIndex] )) { break; + for (int i = 0; i < size; i++) Unknown macro: {+ if (elements[i].equals(o)) { + removeAt(i); + return true; } } if (size == 0 || size == targetIndex) { - return false; - } removeAt(targetIndex); return true; + return false; }
        Hide
        Robert Hu added a comment -

        No, the changes for PriorityQueue#remove(Object) are NOT applicable for Java 5, it is only for Java 6.
        The added test case could show this.
        Thanks a lot!

        Show
        Robert Hu added a comment - No, the changes for PriorityQueue#remove(Object) are NOT applicable for Java 5, it is only for Java 6. The added test case could show this. Thanks a lot!
        Hide
        Tim Ellison added a comment -

        Thanks Robert.

        Patch applied to LUNI module at repo revision r549073.

        Please check it was applied as you expected.

        Show
        Tim Ellison added a comment - Thanks Robert. Patch applied to LUNI module at repo revision r549073. Please check it was applied as you expected.
        Hide
        Robert Hu added a comment -

        Verified.
        Sorry for the inconvenience caused.
        Thanks a lot!

        Show
        Robert Hu added a comment - Verified. Sorry for the inconvenience caused. Thanks a lot!

          People

          • Assignee:
            Tim Ellison
            Reporter:
            Robert Hu
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development