Commons Lang
  1. Commons Lang
  2. LANG-386

LeftOf/RightOfNumber in Range convenience methods necessary

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 3.0
    • Component/s: lang.*
    • Labels:
      None

      Description

      I've using Ranges recently and found then insufficent in methods.
      I cand check if my numbers is in the Range or not but I cant check on which side of the Range it is.
      This is my idea:

      Range range = new Range(0,5);

      boolean outsided = range.leftOfInteger(-5);
      outsided equals true
      boolean outsided = range.leftOfInteger(5);
      outsided equals tfase

      same applies for rightOf

      another convenience method would be:

      create 3 final static int field:

      Range.LEFT_OF = -1;
      Range.INSIDE = 0;
      Range.RIGHT_OF = 1;

      range.positionOfInteger(-2) returns LEFT_OF
      and so forth

      it is some refactoring of contains and the upper methods.

      it would increase functionality

        Issue Links

          Activity

          Hide
          Henri Yandell added a comment -

          Sounds interesting. Naming feels a little tricky; in the above you've got your results back to front (for my reading of the name). ie:

          false = range.leftOfInteger(-5);
          true = range.leftOfInteger(5);

          ie) Range is left of Integer.

          Also possibly should use lessThan/greaterThan semantics rather than left/right.

          The 3 static int field and positionOfInteger suggests the style of Comparable interface.

          As long as we maintain the existing API, I'm all for adding methods to define greater/lesser and a compareTo style method. Patches welcome

          Show
          Henri Yandell added a comment - Sounds interesting. Naming feels a little tricky; in the above you've got your results back to front (for my reading of the name). ie: false = range.leftOfInteger(-5); true = range.leftOfInteger(5); ie) Range is left of Integer. Also possibly should use lessThan/greaterThan semantics rather than left/right. The 3 static int field and positionOfInteger suggests the style of Comparable interface. As long as we maintain the existing API, I'm all for adding methods to define greater/lesser and a compareTo style method. Patches welcome
          Hide
          Henri Yandell added a comment -

          elementBefore and elementAfter methods have been added as a part of LANG-551.

          No positionOf type method as yet.

          Show
          Henri Yandell added a comment - elementBefore and elementAfter methods have been added as a part of LANG-551 . No positionOf type method as yet.
          Hide
          Henri Yandell added a comment -

          positionOfInteger added to the new generic Range class as elementCompareTo.

          Show
          Henri Yandell added a comment - positionOfInteger added to the new generic Range class as elementCompareTo.

            People

            • Assignee:
              Unassigned
              Reporter:
              Michael Osipov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development