Class IntInterval

    • Field Detail

      • from

        private final int from
      • to

        private final int to
      • step

        private final int step
      • size

        private transient int size
    • Constructor Detail

      • IntInterval

        private IntInterval​(int from,
                            int to,
                            int step)
    • Method Detail

      • from

        public static IntInterval from​(int newFrom)
        This static from method allows IntInterval to act as a fluent builder for itself. It works in conjunction with the instance methods to(int) and by(int).

        Usage Example:

         IntInterval interval1 = IntInterval.from(1).to(5);         // results in: 1, 2, 3, 4, 5.
         IntInterval interval2 = IntInterval.from(1).to(10).by(2);  // results in: 1, 3, 5, 7, 9.
         
      • to

        public IntInterval to​(int newTo)
        This instance to method allows IntInterval to act as a fluent builder for itself. It works in conjunction with the static method from(int) and instance method by(int).

        Usage Example:

         IntInterval interval1 = IntInterval.from(1).to(5);         // results in: 1, 2, 3, 4, 5.
         IntInterval interval2 = IntInterval.from(1).to(10).by(2);  // results in: 1, 3, 5, 7, 9.
         
      • by

        public IntInterval by​(int newStep)
        This instance by method allows IntInterval to act as a fluent builder for itself. It works in conjunction with the static method from(int) and instance method to(int).

        Usage Example:

         IntInterval interval1 = IntInterval.from(1).to(5);         // results in: 1, 2, 3, 4, 5.
         IntInterval interval2 = IntInterval.from(1).to(10).by(2);  // results in: 1, 3, 5, 7, 9.
         
      • zero

        public static IntInterval zero()
        Returns an IntInterval starting at zero.

        Usage Example:

         IntInterval interval1 = IntInterval.zero().to(5);         // results in: 0, 1, 2, 3, 4, 5.
         IntInterval interval2 = IntInterval.zero().to(10).by(2);  // results in: 0, 2, 4, 6, 8, 10.
         
      • oneTo

        public static IntInterval oneTo​(int count)
        Returns an IntInterval starting from 1 to the specified count value with a step value of 1.
      • oneToBy

        public static IntInterval oneToBy​(int count,
                                          int step)
        Returns an IntInterval starting from 1 to the specified count value with a step value of step.
      • zeroTo

        public static IntInterval zeroTo​(int count)
        Returns an IntInterval starting from 0 to the specified count value with a step value of 1.
      • zeroToBy

        public static IntInterval zeroToBy​(int count,
                                           int step)
        Returns an IntInterval starting from 0 to the specified count value with a step value of step.
      • fromTo

        public static IntInterval fromTo​(int from,
                                         int to)
        Returns an IntInterval starting from the value from to the specified value to with a step value of 1.
      • evensFromTo

        public static IntInterval evensFromTo​(int from,
                                              int to)
        Returns an IntInterval representing the even values from the value from to the value to.
      • oddsFromTo

        public static IntInterval oddsFromTo​(int from,
                                             int to)
        Returns an IntInterval representing the odd values from the value from to the value to.
      • fromToBy

        public static IntInterval fromToBy​(int from,
                                           int to,
                                           int stepBy)
        Returns an IntInterval for the range of integers inclusively between from and to with the specified stepBy value.
      • containsAll

        public boolean containsAll​(int... values)
        Returns true if the IntInterval contains all the specified int values.
        Specified by:
        containsAll in interface IntIterable
      • containsAll

        public boolean containsAll​(IntIterable source)
        Description copied from interface: IntIterable
        Returns true if all of the values specified in the source IntIterable are contained in the IntIterable, and false if they are not.
        Specified by:
        containsAll in interface IntIterable
      • containsNone

        public boolean containsNone​(int... values)
        Returns true if the IntInterval contains none of the specified int values.
        Specified by:
        containsNone in interface IntIterable
      • contains

        public boolean contains​(int value)
        Returns true if the IntInterval contains the specified int value.
        Specified by:
        contains in interface IntIterable
      • goForward

        private boolean goForward()
      • count

        public int count​(IntPredicate predicate)
        Description copied from interface: IntIterable
        Returns a count of the number of elements in the IntIterable that return true for the specified predicate.
        Specified by:
        count in interface IntIterable
      • anySatisfy

        public boolean anySatisfy​(IntPredicate predicate)
        Description copied from interface: IntIterable
        Returns true if any of the elements in the IntIterable return true for the specified predicate, otherwise returns false.
        Specified by:
        anySatisfy in interface IntIterable
      • allSatisfy

        public boolean allSatisfy​(IntPredicate predicate)
        Description copied from interface: IntIterable
        Returns true if all of the elements in the IntIterable return true for the specified predicate, otherwise returns false.
        Specified by:
        allSatisfy in interface IntIterable
      • equals

        public boolean equals​(java.lang.Object otherList)
        Description copied from interface: IntList
        Follows the same general contract as List.equals(Object).
        Specified by:
        equals in interface IntList
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Description copied from interface: IntList
        Follows the same general contract as List.hashCode().
        Specified by:
        hashCode in interface IntList
        Overrides:
        hashCode in class java.lang.Object
      • size

        public int size()
        Returns the size of the interval.
        Specified by:
        size in interface PrimitiveIterable
      • makeString

        public java.lang.String makeString()
        Description copied from interface: PrimitiveIterable
        Returns a string representation of this collection by delegating to PrimitiveIterable.makeString(String) and defaulting the separator parameter to the characters ", " (comma and space).
        Specified by:
        makeString in interface PrimitiveIterable
        Returns:
        a string representation of this collection.
      • makeString

        public java.lang.String makeString​(java.lang.String start,
                                           java.lang.String separator,
                                           java.lang.String end)
        Description copied from interface: PrimitiveIterable
        Returns a string representation of this collection with the elements separated by the specified separator and enclosed between the start and end strings.
        Specified by:
        makeString in interface PrimitiveIterable
        Returns:
        a string representation of this collection.
      • toArray

        public int[] toArray()
        Description copied from interface: IntIterable
        Converts the IntIterable to a primitive int array.
        Specified by:
        toArray in interface IntIterable
      • toArray

        public int[] toArray​(int[] result)
        Description copied from interface: IntIterable
        Converts the IntIterable to a primitive int array. If the collection fits into the provided array it is used to store its elements and is returned from the method, otherwise a new array of the appropriate size is allocated and returned. If the iterable is empty, the target array is returned unchanged.
        Specified by:
        toArray in interface IntIterable
      • chunk

        public RichIterable<IntIterable> chunk​(int size)
        Description copied from interface: IntIterable
        Partitions elements in fixed size chunks.
        Specified by:
        chunk in interface IntIterable
        Parameters:
        size - the number of elements per chunk
        Returns:
        A RichIterable containing IntIterables of size size, except the last will be truncated if the elements don't divide evenly.
      • toString

        public java.lang.String toString()
        Description copied from interface: PrimitiveIterable
        Returns a string with the elements of this iterable separated by commas with spaces and enclosed in square brackets.
         Assert.assertEquals("[]", IntLists.mutable.empty().toString());
         Assert.assertEquals("[1]", IntLists.mutable.with(1).toString());
         Assert.assertEquals("[1, 2, 3]", IntLists.mutable.with(1, 2, 3).toString());
         
        Specified by:
        toString in interface PrimitiveIterable
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this PrimitiveIterable
        See Also:
        AbstractCollection.toString()
      • intIterator

        public IntIterator intIterator()
        Description copied from interface: IntIterable
        Returns a primitive iterator that can be used to iterate over the IntIterable in an imperative style.
        Specified by:
        intIterator in interface IntIterable
      • get

        public int get​(int index)
        Specified by:
        get in interface IntList
      • checkBounds

        private void checkBounds​(java.lang.String name,
                                 int index)
      • lastIndexOf

        public int lastIndexOf​(int value)
        Specified by:
        lastIndexOf in interface IntList
      • sum

        public long sum()
        Specified by:
        sum in interface IntIterable
      • minIfEmpty

        public int minIfEmpty​(int defaultValue)
        Specified by:
        minIfEmpty in interface IntIterable
      • maxIfEmpty

        public int maxIfEmpty​(int defaultValue)
        Specified by:
        maxIfEmpty in interface IntIterable
      • binarySearch

        public int binarySearch​(int value)
        Specified by:
        binarySearch in interface IntList
      • toImmutable

        public ImmutableIntList toImmutable()
        Description copied from interface: IntList
        Returns an immutable copy of this list. If the list is immutable, it returns itself.
        Specified by:
        toImmutable in interface IntList
      • zipInt

        public ImmutableList<IntIntPair> zipInt​(IntIterable iterable)
        Description copied from interface: ImmutableIntList
        Returns an ImmutableList formed from this ImmutableIntList and another IntList by combining corresponding elements in pairs. If one of the two IntLists is longer than the other, its remaining elements are ignored.
        Specified by:
        zipInt in interface ImmutableIntList
        Specified by:
        zipInt in interface IntList
      • zip

        public <T> ImmutableList<IntObjectPair<T>> zip​(java.lang.Iterable<T> iterable)
        Description copied from interface: ImmutableIntList
        Returns an ImmutableList formed from this ImmutableIntList and a ListIterable by combining corresponding elements in pairs. If one of the two Lists is longer than the other, its remaining elements are ignored.
        Specified by:
        zip in interface ImmutableIntList
        Specified by:
        zip in interface IntList
      • spliterator

        public java.util.Spliterator.OfInt spliterator()
        Specified by:
        spliterator in interface IntList
      • readObject

        private void readObject​(java.io.ObjectInputStream ois)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException