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

Generic Range<T> Class

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P5 P5
    • None
    • None
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      JRE 7 shall come with a generic Range<T> class.

      JUSTIFICATION :
      In programming, often there is the problem that a value has to be checked against a range. While this is not hard to solve, it is complex to read, as not only upper and lower limits have to be checked in their value, but also it must get checked whether there actually is a limit (possible bi-unbounded Range) or whether the limits are included or excluded (possible Range left side open, right side excluded, etc.). Also people often have to intersect or merge ranges etc. what results in hard to read (and error prone) code lines. So lots of people already wrote their own Range classes, e. g. well-known Martin Fowler et al.

      It would be just intuitive and straightforward to find the concept of ranges covered by a generic class within the JRE instead of forcing everybody to write his own implementation.

      Martin Fowler's class is more a theoretical construct and not finished.

      Other's classes are not standardized so won't fit for professional use.

      JAI comes with such a class, but that one is neither part of the JRE nor completely generic (and in part too complex to use, as one cannot just write "Range<Integer>(1, 2)" but has to manually provide T's type as a paremeter.

      I've written my own class and copy it into each of my projects, so it seems to be fit for inclusion in the JRE (it even is 100% Junit4 covered). So it won't be a big issue to include it in JRE 7.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      final boolean b = new Range(7, 9).contains(8); // true

      final boolean b = new Range(null, 10).contains(3); // true

      etc. -- You got the point, I think.
      ACTUAL -
      Have to use my own class in every project, or have to trust a thirt party half-baked implementation, or have to link JAI.

            smarks Stuart Marks
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: