Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4939317

(coll) Collection should have a method get()

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      Name: gm110360 Date: 10/17/2003


      A DESCRIPTION OF THE REQUEST :
      This enhancement is slightly related to 4269596.

      >Idealy what should be done is to add a get(Object o) to
      >java.util.Collection. However then all the classes below need to be
      >updated and java would not be backward compatible. THUS MY SUGGESTION
      >IS only to add get methods to AbstractCollection, AbstractSet,
      >AbstractList, ArrayList, Vector, LinkedList, HashSet, and
      >TreeSet. That is DO NOT CHANGE ANY OF THE INTERFACES. Below I have
      >include implementations for AbstractCollection, HashSet, and TreeSet.
      >
      >NOTE! All implementations will be almost identical to the contains()
      >method.
      >
      >THE DECLERATION
      >public Object get(Object o)
      >
      >Which returns e if and only if this set contains at least one element
      >e such that o.equals(e). Otherwise it returns null.
      >
      >
      >Implementation in java.util.AbstractCollection
      >
      >public Object get(Object o) {
      > Iterator e = iterator();
      > if (o != null){
      > while (e.hasNext())
      > if (o.equals(e.next()))
      > return e;
      > }
      > return null;
      >}
      >
      >
      >Implementation in java.util.HashSet
      >
      >public Object get(Object o) {
      > return map.get(o);
      >}
      >
      >
      >Implementation in java.util.TreeSet
      >
      >public Object get(Object o) {
      > return m.get(o);
      >}
      >
      >
      >/Isaac
      >
      ----------------- Original Bug Report -------------------
                                                                                                                                                     
      category : java
      release : 1.4.2
      subcategory : classes_util
      type : rfe
      synopsis : Collection should have a method get()
      description : A DESCRIPTION OF THE REQUEST :
      Collection should have a method get()
                                                                                                                                                     
      It is strange that Collection should have a method contains() but not a method for retrieving the object. This is an essential feature of any
      datastructure!
                                                                                                                                                     
      There are numerous situations in which the object contained in the datastructure is not the same but equal, e.g. as caches! At the moment I
      need a HashSet with a get method but instead I will have to use HashMap.
                                                                                                                                                     
      If the idea is that there might exist some datastructure in which contains() is computationally more easy than retrieval then please add a get
      method to HashSet, TreeSet etc.. A tleast there is no reason to remove such an essential feature from these datastructures.
                                                                                                                                                     
      Thanks.



      JUSTIFICATION :
      The get method is an essentiall feature of any datastructure. It is truely sad that it has been left out of Collection.
      (Incident Review ID: 215641)
      ======================================================================
      ###@###.### 10/28/04 04:27 GMT

        Attachments

          Activity

            People

            • Assignee:
              martin Martin Buchholz
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: