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 void
deleteFirst()
Reset the first value to null.void
deleteSecond()
Reset the second value to null.static <F,S>
@NotNull Pair<F,S>empty()
Create and empty pair.boolean
equals(Object o)
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
notHasFirst()
Check Pair not have the first value.boolean
notHasSecond()
Check Pair not have the second value.static <F,S>
@NotNull Pair<F,S>of(F first, S second)
Creates a pair of values.void
reset()
Reset both values to null.void
setFirst(F first)
Use to set the first value.void
setFirstAndSecond(F first, S second)
Use to set the first and second values.void
setSecond(S second)
Use to set the second value.@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
- first value, can be null.second
- 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 empty pair
-
getFirst
@Contract(pure=true) public F getFirst()
Returns the first value.- Returns:
- the first value
-
setFirst
@Contract(mutates="this") public void setFirst(F first)
Use to set the first value.- Parameters:
first
- first value
-
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
-
reset
public void reset()
Reset both values to null.
-
deleteFirst
@Contract(mutates="this") public void deleteFirst()
Reset the first value to null.
-
deleteSecond
@Contract(mutates="this") public void deleteSecond()
Reset the second value to null.
-
getSecond
@Contract(pure=true) public S getSecond()
Returns the second value.- Returns:
- the second value
-
setSecond
@Contract(mutates="this") public void setSecond(S second)
Use to set the second value.- Parameters:
second
- second value
-
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
-
notHasFirst
@Contract(pure=true) public boolean notHasFirst()
Check Pair not have the first value.- Returns:
- true if Pair has no first value
-
hasFirst
@Contract(pure=true) public boolean hasFirst()
Check Pair has the first value.- Returns:
- true if Pair has first value
-
notHasSecond
@Contract(pure=true) public boolean notHasSecond()
Check Pair not have the second value.- Returns:
- true if Pair has no second value
-
hasSecond
@Contract(pure=true) public boolean hasSecond()
Check Pair has the second value.- Returns:
- true if Pair has second value
-
equals
@Contract(value="null -> false", pure=true) public boolean equals(Object o)
-
-