Package art.cutils.value
Class Pair<F,S>
- java.lang.Object
-
- art.cutils.value.Pair<F,S>
-
- Type Parameters:
F
- first value typeS
- second value type
public final class Pair<F,S> extends Object
A pair of values. Two heads are better than one—sometimes.- Since:
- 2.0
- Author:
- Bobai Kato
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pair<F,S>
clear()
Remove both values to null from thePair
.Pair<F,S>
deleteFirst()
Reset the first value to null.Pair<F,S>
deleteSecond()
Reset the second value to null.static <F,S>
@NotNull Pair<F,S>empty()
Create and empty pair.boolean
equals(Object o)
Pair<F,S>
first(F first)
Use to set the first value.F
getFirst()
Returns the first value.S
getSecond()
Returns the second value.boolean
hasFirst()
Check Pair has the first value.int
hashCode()
boolean
hasSecond()
Check Pair has the second value.boolean
isEmpty()
Returns true if both values are null.boolean
isNotEmpty()
Returns true if both values are not null.boolean
notHaveFirst()
Check Pair not have the first value.boolean
notHaveSecond()
Check Pair doesn't have the second value.static <F,S>
@NotNull Pair<F,S>of(F first, S second)
Creates a pair of values.Pair<F,S>
second(S second)
Use to set the second value.void
setFirstAndSecond(F first, S second)
Use to set the first and second values.@NotNull Pair<S,F>
swap()
Swap the first and second values.@NotNull String
toString()
-
-
-
Method Detail
-
of
@Contract(value="_, _ -> new", pure=true) @NotNull public static <F,S> @NotNull Pair<F,S> of(F first, S second)
Creates a pair of values.- Parameters:
first
- the first value. Can be null.second
- the second value. Can be null.- Returns:
- a pair of values
-
empty
@Contract(value=" -> new", pure=true) @NotNull public static <F,S> @NotNull Pair<F,S> empty()
Create and empty pair.- Type Parameters:
F
- first value typeS
- second value type- Returns:
- new instance of an empty
Pair
-
getFirst
@Contract(pure=true) public F getFirst()
Returns the first value.- Returns:
- the first value
-
first
@Contract(mutates="this") public Pair<F,S> first(F first)
Use to set the first value.- Parameters:
first
- first value- Returns:
- current instance of
Pair
-
setFirstAndSecond
@Contract(mutates="this") public void setFirstAndSecond(F first, S second)
Use to set the first and second values.- Parameters:
first
- first valuesecond
- second value
-
clear
public Pair<F,S> clear()
Remove both values to null from thePair
.- Returns:
- current instance of
Pair
-
deleteFirst
@Contract(mutates="this") public Pair<F,S> deleteFirst()
Reset the first value to null.- Returns:
- current instance of
Pair
-
deleteSecond
@Contract(mutates="this") public Pair<F,S> deleteSecond()
Reset the second value to null.- Returns:
- current instance of
Pair
-
getSecond
@Contract(pure=true) public S getSecond()
Returns the second value.- Returns:
- the second value
-
swap
@Contract(value=" -> new", pure=true) @NotNull public @NotNull Pair<S,F> swap()
Swap the first and second values.- Returns:
- instance of
Pair
with swapped values
-
second
@Contract(mutates="this") public Pair<F,S> second(S second)
Use to set the second value.- Parameters:
second
- second value- Returns:
- current instance of
Pair
-
isNotEmpty
@Contract(pure=true) public boolean isNotEmpty()
Returns true if both values are not null.- Returns:
- true if both values are not null
-
isEmpty
@Contract(pure=true) public boolean isEmpty()
Returns true if both values are null.- Returns:
- true if both values are null
-
notHaveFirst
@Contract(pure=true) public boolean notHaveFirst()
Check Pair not have the first value.- Returns:
- true if the
Pair
has no first value
-
hasFirst
@Contract(pure=true) public boolean hasFirst()
Check Pair has the first value.- Returns:
- true if the
Pair
has first value
-
notHaveSecond
@Contract(pure=true) public boolean notHaveSecond()
Check Pair doesn't have the second value.- Returns:
- true if the
Pair
has no second value
-
hasSecond
@Contract(pure=true) public boolean hasSecond()
Check Pair has the second value.- Returns:
- true if the
Pair
has second value
-
equals
@Contract(value="null -> false", pure=true) public boolean equals(Object o)
-
-