Class RangeOfInt

    • Method Detail

      • of

        @NotNull
        public static @NotNull RangeOfInt of​(@NotNull
                                             @NotNull Number s,
                                             @NotNull
                                             @NotNull Number e)
      • of

        @NotNull
        public static @NotNull RangeOfInt of​(@NotNull
                                             @NotNull Number e)
      • contains

        public boolean contains​(int i)
        Returns true if the number is within the bounds of this range (low end incluive, high end exclusive). In math terms, returns true if the argument is [low, high). False otherwise. This is an efficient method when the compiler can see that it's being passed a primitive int, but contains(Object o) delegates to this method when it's passed a reasonable and unambiguous argument.
      • contains

        public boolean contains​(Object o)
        Though this overrides List.contains(Object o), it is effectively a convenience method for calling contains(int i). Therefore, it only accepts Integers, Longs, BigIntegers, and Strings that parse as signed decimal Integers. It does not accept Numbers since they can't easily be checked for truncation and floating-point might not round properly with respect to bounds, or might not make sense if you are using your range to define a set of integers. Handles truncation (returns false) for the types it accepts. Throws exceptions for types it does not accept. Thanks for all the help from codereview.stackexchange: http://codereview.stackexchange.com/questions/100846/rounding-and-truncation-in-intrange-containsobject-o
        Specified by:
        contains in interface Collection<Integer>
        Specified by:
        contains in interface List<Integer>
        Specified by:
        contains in interface UnmodList<Integer>
        Parameters:
        o - an Integer, Long, BigInteger, or String that parses as a signed decimal Integer.
        Returns:
        true if the number is within the bounds of this range (high end is exclusive). False otherwise.
        Throws:
        IllegalArgumentException - if the argument is not an Integer, Long, BigInteger, or String.
        NumberFormatException - if a String argument cannot be parsed using Integer.valueOf().
      • indexOf

        public int indexOf​(Object o)
        Unlike most implementations of List, this method has excellent O(1) performance! The default implementation of this method has O(this.size()) performance. If you call this much, you probably want to use a Map<Integer,T> instead for O(1) performance.
        Specified by:
        indexOf in interface List<Integer>
        Specified by:
        indexOf in interface UnmodList<Integer>
      • lastIndexOf

        public int lastIndexOf​(Object o)
        Unlike most implementations of List, this method has excellent O(1) performance! The default implementation of this method has O(this.size()) performance.
        Specified by:
        lastIndexOf in interface List<Integer>
        Specified by:
        lastIndexOf in interface UnmodList<Integer>
      • size

        public int size()
        Description copied from interface: Sized
        Returns the number of items in this collection or iterable.
        Specified by:
        size in interface Collection<Integer>
        Specified by:
        size in interface List<Integer>
        Specified by:
        size in interface Sized
      • listIterator

        @NotNull
        public @NotNull UnmodListIterator<Integer> listIterator​(int startIdx)
        Subclasses should override this when they can do so more efficiently. Iterates from start of range (inclusive) up-to, but excluding, the end of the range. I'm not sure this is a good idea, but Python, Clojure, Scala, and just about everything in Java expects similar behavior.
        Specified by:
        listIterator in interface List<Integer>
        Specified by:
        listIterator in interface UnmodList<Integer>