java.lang.Object
de.s42.base.functional.Pair<FirstType,SecondType>
- Typparameter:
FirstType
-SecondType
-
A pair of 2 values. Both types can be null. It provides handy access.
- Autor:
- Benjamin Schiller
-
Feldübersicht
Modifizierer und TypFeldBeschreibungprivate final FirstType
Stores the first final.private final SecondType
Stores the second final. -
Konstruktorübersicht
ModifiziererKonstruktorBeschreibungprivate
Pair
(FirstType first, SecondType second) Constructs a pair of first and second. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
each
(Consumer<FirstType> actionFirst, Consumer<SecondType> actionSecond) Calls the action if first is not null with first as parameter.static <FirstType,
SecondType>
Pair<FirstType, SecondType> empty()
Create an empty Pair with both of the given values being null.boolean
Either is equal if first and second are equal.first()
Returns the optional of first valuefirstOrElse
(FirstType other) Returns first if first is not null or other if first is null.Returns a Optional of first or throws a exception if first is null.int
hashCode()
The combined hashcode of first and second.void
Calls the action if first is not null with first as parameter.void
ifSecond
(Consumer<SecondType> action) Calls the action if second is not null with second as parameter.boolean
isFirst()
Returns true if first is not null.boolean
isSecond()
Returns true if second is not null.static <FirstType,
SecondType>
Pair<FirstType, SecondType> of
(FirstType first, SecondType second) Create a Pair with both of the given values being non null.static <FirstType,
SecondType>
Pair<FirstType, SecondType> ofFirst
(FirstType first) Create a Pair with first set and second being nullstatic <FirstType,
SecondType>
Pair<FirstType, SecondType> ofNullable
(FirstType first, SecondType second) Create a Pair with both of the given values being null or non null.static <FirstType,
SecondType>
Pair<FirstType, SecondType> ofSecond
(SecondType second) Create a Pair with second set and first being nullsecond()
Returns the optional of second valuesecondOrElse
(SecondType other) Returns second if second is not null or other if second is null.Returns a Optional of second or throws a exception if second is null.Stream
<?> stream()
Allows to get a stream to streaming first then second (only contains them if non null)toString()
Returns a string in the form '[first, second]'
-
Felddetails
-
first
Stores the first final. -
second
Stores the second final.
-
-
Konstruktordetails
-
Pair
Constructs a pair of first and second. Both values may be null- Parameter:
first
- First valuesecond
- Second value
-
-
Methodendetails
-
empty
Create an empty Pair with both of the given values being null.- Typparameter:
FirstType
- Type of the first valueSecondType
- Type of the second value- Gibt zurück:
- An empty Pair
-
of
public static <FirstType,SecondType> Pair<FirstType,SecondType> of(FirstType first, SecondType second) throws NullPointerException Create a Pair with both of the given values being non null.- Typparameter:
FirstType
- Type of the first valueSecondType
- Type of the second value- Parameter:
first
- First valuesecond
- Second value- Gibt zurück:
- Pair of type <FirstType, SecondType>
- Löst aus:
NullPointerException
- if either of first or second is null
-
ofFirst
public static <FirstType,SecondType> Pair<FirstType,SecondType> ofFirst(FirstType first) throws NullPointerException Create a Pair with first set and second being null- Typparameter:
FirstType
- Type of the first valueSecondType
- Type of the second value- Parameter:
first
- First value- Gibt zurück:
- Pair of type <FirstType, SecondType>
- Löst aus:
NullPointerException
- if first is null
-
ofSecond
public static <FirstType,SecondType> Pair<FirstType,SecondType> ofSecond(SecondType second) throws NullPointerException Create a Pair with second set and first being null- Typparameter:
FirstType
- Type of the first valueSecondType
- Type of the second value- Parameter:
second
- Second value- Gibt zurück:
- Pair of type <FirstType, SecondType>
- Löst aus:
NullPointerException
- if second is null
-
ofNullable
public static <FirstType,SecondType> Pair<FirstType,SecondType> ofNullable(FirstType first, SecondType second) Create a Pair with both of the given values being null or non null.- Typparameter:
FirstType
- Type of the first valueSecondType
- Type of the second value- Parameter:
first
- First valuesecond
- Second value- Gibt zurück:
- Either of type <FirstType, SecondType>
-
each
Calls the action if first is not null with first as parameter.- Parameter:
actionFirst
- Called if first is not nullactionSecond
- Called if second is not null
-
ifFirst
-
ifSecond
Calls the action if second is not null with second as parameter.- Parameter:
action
- Called if second is not null
-
isFirst
public boolean isFirst()Returns true if first is not null.- Gibt zurück:
- True if first is not null
-
isSecond
public boolean isSecond()Returns true if second is not null.- Gibt zurück:
- True if second is not null
-
first
-
firstOrThrow
Returns a Optional of first or throws a exception if first is null.- Gibt zurück:
- Optional of first or throws a exception if first is null
- Löst aus:
NullPointerException
- If first is null
-
firstOrElse
-
second
Returns the optional of second value- Gibt zurück:
- Optional of second value
-
secondOrThrow
Returns a Optional of second or throws a exception if second is null.- Gibt zurück:
- Optional of second or throws a exception if second is null
- Löst aus:
NullPointerException
- If second is null
-
secondOrElse
Returns second if second is not null or other if second is null.- Parameter:
other
- Value that will be returned if second is null- Gibt zurück:
- Second if second is not null or other if second is null
-
stream
Allows to get a stream to streaming first then second (only contains them if non null)- Gibt zurück:
- A stream that streams first then second
-
toString
-
hashCode
-
equals
-