Package civitas.celestis.util.tuple
Class Int2
java.lang.Object
civitas.celestis.util.tuple.Int2
- All Implemented Interfaces:
BaseTuple<Integer>,IntTuple,Serializable
An immutable type containing two primitive
ints.- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]array()Returns an array containing the components of this tuple in their proper order.boxed()Returns a tuple containing the components of this tuple in their boxed form.booleancontains(int v) Checks if this tuple contains the provided valuev.booleanChecks if this tuple contains multiple values.booleanChecks for equality between this tuple and the provided objectobj.intget(int i) Returns theith component of this tuple.inthashCode()Returns the hash code of this instance.booleanisZero()Returns whether this tuple represents zero.list()Returns an unmodifiable list containing the components of this tuple in their proper order.Applies the provided mapper functionfto each component of this tuple, then returns a new tuple containing the return values of the functionf.<F> Tuple<F>mapToObj(IntFunction<? extends F> f) Applies the provided mapper functionfto each component of this tuple, then returns a new tuple containing the return values of the functionf.intsize()Returns the size of this tuple.stream()Returns a stream whose source is the elements of this tuple.toString()Serializes this tuple into a string.intx()Returns the X component of this tuple.inty()Returns the Y component of this tuple.
-
Field Details
-
x
protected final int xThe X component of this tuple. -
y
protected final int yThe Y component of this tuple.
-
-
Constructor Details
-
Int2
public Int2(int x, int y) Creates a newInt2.- Parameters:
x- The X component of this tupley- The Y component of this tuple
-
Int2
public Int2(@Nonnull int[] components) Creates a newInt2.- Parameters:
components- An array containing the components of this tuple in XY order- Throws:
IllegalArgumentException- When the provided array's length is not2
-
Int2
Creates a newInt2.- Parameters:
t- The tuple of which to copy component values from- Throws:
IllegalArgumentException- When the provided tuplet's size is not2
-
-
Method Details
-
size
public int size()Returns the size of this tuple. (the number of components it has) -
isZero
public boolean isZero()Returns whether this tuple represents zero. (whether every component is zero) -
contains
public boolean contains(int v) Checks if this tuple contains the provided valuev. -
containsAll
Checks if this tuple contains multiple values.- Specified by:
containsAllin interfaceIntTuple- Parameters:
i- The iterable object of which to check for containment- Returns:
trueif this tuple contains every component of the iterable object
-
get
Returns theith component of this tuple.- Specified by:
getin interfaceIntTuple- Parameters:
i- The index of the component to get- Returns:
- The
ith component of this tuple - Throws:
IndexOutOfBoundsException- When the indexiis out of bounds
-
x
public int x()Returns the X component of this tuple.- Returns:
- The X component of this tuple
-
y
public int y()Returns the Y component of this tuple.- Returns:
- The Y component of this tuple
-
map
Applies the provided mapper functionfto each component of this tuple, then returns a new tuple containing the return values of the functionf. -
mapToObj
Applies the provided mapper functionfto each component of this tuple, then returns a new tuple containing the return values of the functionf. -
array
@Nonnull public int[] array()Returns an array containing the components of this tuple in their proper order. -
stream
Returns a stream whose source is the elements of this tuple. -
list
Returns an unmodifiable list containing the components of this tuple in their proper order. -
boxed
Returns a tuple containing the components of this tuple in their boxed form. -
equals
Checks for equality between this tuple and the provided objectobj. -
toString
Serializes this tuple into a string. -
hashCode
public int hashCode()Returns the hash code of this instance.
-