Class LongInterval

    • Field Detail

      • from

        private final long from
      • to

        private final long to
      • step

        private final long step
      • size

        private final int size
    • Constructor Detail

      • LongInterval

        private LongInterval​(long from,
                             long to,
                             long step)
    • Method Detail

      • from

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

        Usage Example:

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

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

        Usage Example:

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

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

        Usage Example:

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

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

        Usage Example:

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

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

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

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

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

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

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

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

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

        public boolean containsAll​(long... values)
        Returns true if the LongInterval contains all the specified long values.
        Specified by:
        containsAll in interface LongIterable
      • containsAll

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

        public boolean containsNone​(int... values)
        Returns true if the LongInterval contains none of the specified long values.
      • contains

        public boolean contains​(long value)
        Returns true if the LongInterval contains the specified long value.
        Specified by:
        contains in interface LongIterable
      • forEachWithLongIndex

        public void forEachWithLongIndex​(LongLongProcedure procedure)
      • goForward

        private boolean goForward()
      • count

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

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

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

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

        public int hashCode()
        Description copied from interface: LongList
        Follows the same general contract as List.hashCode().
        Specified by:
        hashCode in interface LongList
        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 long[] toArray()
        Description copied from interface: LongIterable
        Converts the LongIterable to a primitive long array.
        Specified by:
        toArray in interface LongIterable
      • toArray

        public long[] toArray​(long[] result)
        Description copied from interface: LongIterable
        Converts the LongIterable to a primitive long 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 LongIterable
      • chunk

        public RichIterable<LongIterable> chunk​(int size)
        Description copied from interface: LongIterable
        Partitions elements in fixed size chunks.
        Specified by:
        chunk in interface LongIterable
        Parameters:
        size - the number of elements per chunk
        Returns:
        A RichIterable containing LongIterables 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()
      • longIterator

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

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

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

        public int lastIndexOf​(long value)
        Specified by:
        lastIndexOf in interface LongList
      • minIfEmpty

        public long minIfEmpty​(long defaultValue)
        Specified by:
        minIfEmpty in interface LongIterable
      • maxIfEmpty

        public long maxIfEmpty​(long defaultValue)
        Specified by:
        maxIfEmpty in interface LongIterable
      • binarySearch

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

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

        public <T> ImmutableList<LongObjectPair<T>> zip​(java.lang.Iterable<T> iterable)
        Description copied from interface: ImmutableLongList
        Returns an ImmutableList formed from this ImmutableLongList 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 ImmutableLongList
        Specified by:
        zip in interface LongList
      • spliterator

        public java.util.Spliterator.OfLong spliterator()
        Specified by:
        spliterator in interface LongList