Top Description Inners Fields Constructors Methods
io.github.darvil.utils

public Class Range

extends Object
implements Iterable<Integer>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
org.jetbrains.annotations.NotNull, java.util.Iterator

A range class to contain a start and end value, or a single value. Both non-negative.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final Range
ANY

A range between 0 and infinity.

public static final Range
AT_LEAST_ONE

A range between 1 and infinity.

private final int
private final boolean
isInfinite

Whether the range is infinite.

public static final Range
NONE

A range of 0.

public static final Range
NONE_OR_ONE

A range between 0 and 1.

public static final Range
ONE

A range of 1.

private final int

Constructor Summary

AccessConstructor and Description
private
Range(int
The start value
start
,
int
The end value, or -1 for infinity
end
)

Creates a new range with the given start and end values.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the value is in the range
contains
(int
The value to check
value
,
boolean
Whether the start value is inclusive
startInclusive
,
boolean
Whether the end value is inclusive
endInclusive
)

Returns true if the given value is in the range.

public boolean

Returns:

true if the value is in the range
containsExclusive
(int
The value to check
value
)

Returns true if the given value is in the range, exclusive.

public boolean

Returns:

true if the value is in the range
containsInclusive
(int
The value to check
value
)

Returns true if the given value is in the range, inclusive.

public int
end()

Returns the end value, or Integer#MAX_VALUE if the range is infinite.

public static @NotNull Range.RangeBuilder
from(int start)

Creates a new range builder with the given start value.

public @NotNull String

Returns:

The string representation
getMessage
(@NotNull String
The kind of thing the range is for, such as "time" or "argument"
kind
)

Returns a string representation of the range, such as "from 3 to 5 times", or "3 times".

public @NotNull String

Returns:

The string representation
getRepresentation
()

Returns a string representation of the range, such as "{3, 5}" or "{3}".

public boolean
isInfinite()

Returns true if the end value is infinity.

public boolean
isSimple()

Returns true if this is representing a single value.

public boolean
isZero()

Returns true if the range is 0.

public @NotNull Iterator<Integer>

Returns:

The iterator
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator that iterates over the range.

public @NotNull Iterator<Integer>

Returns:

The iterator
iterator
(boolean
Whether the start value is inclusive
startInclusive
,
boolean
Whether the end value is inclusive
endInclusive
)

Returns an iterator that iterates over the range.

public static @NotNull Range
of(int value)

Creates a new single-value range with the given value.

public @NotNull Range

Returns:

The new range
offset
(int
The offset to apply
offset
)

Offsets both the start and end values by the given offset.

public int
start()

Returns the start value.

public int[]

Returns:

The array
toArray
()

Returns an array of all the values in the range, inclusive.

public int[]

Returns:

The array
toArray
(boolean
Whether the start value is inclusive
startInclusive
,
boolean
Whether the end value is inclusive
endInclusive
)

Returns an array of all the values in the range.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ANYback to summary
public static final Range ANY

A range between 0 and infinity.

AT_LEAST_ONEback to summary
public static final Range AT_LEAST_ONE

A range between 1 and infinity.

endback to summary
private final int end
isInfiniteback to summary
private final boolean isInfinite

Whether the range is infinite.

NONEback to summary
public static final Range NONE

A range of 0.

NONE_OR_ONEback to summary
public static final Range NONE_OR_ONE

A range between 0 and 1.

ONEback to summary
public static final Range ONE

A range of 1.

startback to summary
private final int start

Constructor Detail

Rangeback to summary
private Range(int start, int end)

Creates a new range with the given start and end values. If the end value is -1, the range end value will be infinity.

Parameters
start:int

The start value

end:int

The end value, or -1 for infinity

Method Detail

containsback to summary
public boolean contains(int value, boolean startInclusive, boolean endInclusive)

Returns true if the given value is in the range.

Parameters
value:int

The value to check

startInclusive:boolean

Whether the start value is inclusive

endInclusive:boolean

Whether the end value is inclusive

Returns:boolean

true if the value is in the range

containsExclusiveback to summary
public boolean containsExclusive(int value)

Returns true if the given value is in the range, exclusive.

Parameters
value:int

The value to check

Returns:boolean

true if the value is in the range

containsInclusiveback to summary
public boolean containsInclusive(int value)

Returns true if the given value is in the range, inclusive.

Parameters
value:int

The value to check

Returns:boolean

true if the value is in the range

endback to summary
public int end()

Returns the end value, or Integer#MAX_VALUE if the range is infinite.

fromback to summary
public static @NotNull Range.RangeBuilder from(int start)

Creates a new range builder with the given start value.

Annotations
@NotNull
getMessageback to summary
public @NotNull String getMessage(@NotNull String kind)

Returns a string representation of the range, such as "from 3 to 5 times", or "3 times".

Parameters
kind:@NotNull String

The kind of thing the range is for, such as "time" or "argument"

Returns:@NotNull String

The string representation

Annotations
@NotNull
getRepresentationback to summary
public @NotNull String getRepresentation()

Returns a string representation of the range, such as "{3, 5}" or "{3}". If the end value is Short#MAX_VALUE, it will be represented as "...".

Returns:@NotNull String

The string representation

Annotations
@NotNull
isInfiniteback to summary
public boolean isInfinite()

Returns true if the end value is infinity.

isSimpleback to summary
public boolean isSimple()

Returns true if this is representing a single value.

isZeroback to summary
public boolean isZero()

Returns true if the range is 0.

iteratorback to summary
public @NotNull Iterator<Integer> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator that iterates over the range. Both the start and end values are inclusive.

Returns:@NotNull Iterator<Integer>

The iterator

Annotations
@Override
@NotNull
See Also
iterator(boolean, boolean)
iteratorback to summary
public @NotNull Iterator<Integer> iterator(boolean startInclusive, boolean endInclusive)

Returns an iterator that iterates over the range.

Parameters
startInclusive:boolean

Whether the start value is inclusive

endInclusive:boolean

Whether the end value is inclusive

Returns:@NotNull Iterator<Integer>

The iterator

Annotations
@NotNull
ofback to summary
public static @NotNull Range of(int value)

Creates a new single-value range with the given value.

Annotations
@NotNull
offsetback to summary
public @NotNull Range offset(int offset)

Offsets both the start and end values by the given offset. The range will be infinite if it was infinite before.

Parameters
offset:int

The offset to apply

Returns:@NotNull Range

The new range

Annotations
@NotNull
startback to summary
public int start()

Returns the start value.

toArrayback to summary
public int[] toArray()

Returns an array of all the values in the range, inclusive.

If the range is infinite, an UnsupportedOperationException will be thrown.

Returns:int[]

The array

Exceptions
UnsupportedOperationException:
if the range is infinite
See Also
toArray(boolean, boolean)
toArrayback to summary
public int[] toArray(boolean startInclusive, boolean endInclusive)

Returns an array of all the values in the range.

If the range is infinite, an UnsupportedOperationException will be thrown.

The array will always contain at least one element.
Parameters
startInclusive:boolean

Whether the start value is inclusive

endInclusive:boolean

Whether the end value is inclusive

Returns:int[]

The array

Exceptions
UnsupportedOperationException:
if the range is infinite
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
io.github.darvil.utils back to summary

public Class Range.RangeBuilder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private final int

Constructor Summary

AccessConstructor and Description
private
RangeBuilder(int start)

Method Summary

Modifier and TypeMethod and Description
private @NotNull Range
build()

Builds the range.

public @NotNull Range
to(int end)

Sets the end value.

public @NotNull Range
toInfinity()

Sets the end value to infinity.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

endback to summary
private int end
startback to summary
private final int start

Constructor Detail

RangeBuilderback to summary
private RangeBuilder(int start)

Method Detail

buildback to summary
private @NotNull Range build()

Builds the range.

Annotations
@NotNull
toback to summary
public @NotNull Range to(int end)

Sets the end value.

Annotations
@NotNull
toInfinityback to summary
public @NotNull Range toInfinity()

Sets the end value to infinity.

Annotations
@NotNull