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

(coll) Please provide generalised Map and Set selectors

    Details

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

      Description

      A DESCRIPTION OF THE REQUEST :
      Map and Set selectors, which select the appropriate Map and Set implementation based on their usage criteria and the platform that JVM is executing upon, would enable people to utilise various implementations of Map and Set more efficiently and easily.

      The selectors can responds to programmatically supplied criteria (Sorted, Navigatible, FastSearch, FastAdd, Small etc.) and choose an appropriate implementation that would best suit the required criteria - this can even be platform-specific, e.g. MapImpl1 may be faster on Intel platforms while MapImpl2 is faster on PowerPCs. Having said that, we can now go out and develop lots and lots of fine-tuned variant of Maps and Sets so that the Collections Framework can become immensely powerful.

      Possible Implementation:

      The criteria options mentioned above can be implemented with ease using Enum, with 2 static methods in java.util.Collections:
      - <K extends Object, V extends Object> Map<K,V> newMapInstance(criteria, Class<K> keyClass, Class<V> valueClass)
      - <E extends Object> Set<E> newSetInstance(criteria, Class<E> elementClass)

      Obviously it would also be plausible to implement MapSelector<K,V> and SetSelector<E> as seperate factory classes with static method newInstance(criteria) if there are just too much code to add into Collections or just that it would look cleaner with the Generics.


      JUSTIFICATION :
      We have had the Java Collections Framework for quite some time - and it has proven to be really useful, thanks to the great minds behind!

      And since the interfaces for Map and Set are flexible enough for a great many kinds of variants of implementations upon them, a wide range of applications (be it for speed, space, order etc) are well-covered.

      Map and Set selectors, which select the appropriate Map and Set implementation based on their usage criteria and the platform that JVM is executing upon, would enable people to utilise various implementations of Map and Set more efficiently and easily.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Map<String, String> map = MapSelector<String, String>.newInstance(Criterion.Sorted, Criterion.MinimiseSize, Criterion.ConcurrentAccess);

      Set<Long> set = SetSelector<Long>.newInstance(Criterion.MaximiseSpeed);
      ACTUAL -
      // After looking up the specifications, articles, so on and so forth....
      // Even then I don't think I have made the best choices here!

      Map<String, String> map = new Collections.synchronizedSortedMap(new TreeMap());

      Set<Long> set = new HashSet<Long>();

      CUSTOMER SUBMITTED WORKAROUND :
      See "Actual Behaviour".
      ###@###.### 2005-05-10 16:14:00 GMT

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: