Package com.marcpg.libpg.storing
Class Pair<L,R>
java.lang.Object
com.marcpg.libpg.storing.Pair<L,R>
- Type Parameters:
L
- The left field's typeR
- The right field's type
A pair is just two values that have a defined type.
It's the same as a
Map
, but with only one value.- Since:
- 0.0.1
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Runs some operation on both the left and right side.void
clear()
Clears both the left and right side's values.void
Clears the value of a specific side.boolean
Checks if this pair contains the specified value.Get the field of a specific side from the pair.This gets the heavier side of the pair based on the length when usingObject.toString()
.This gets the heavier side of the pair based on the length when usingObject.toString()
.Gets the side matching the predicate's requirements.boolean
isEmpty()
Check if the pair is empty.boolean
isFull()
Check if the pair is full.left()
Get the left field of the pair.static <L,
R> @NotNull Pair<L, R> of
(L left, R right) Static method to create a new Pair instance.static <L,
R> @NotNull Pair<L, R> Static method to convert aMap.Entry
to a Pair, where the left side is the key and the right side is the value.right()
Get the right field of the pair.void
Set or change both fields of the pair.void
Set or change the left field of the pair.void
Set or change the right field of the pair.toString()
Convert the Pair to a readableString
.
-
Field Details
-
left
The left side of this pair. -
right
The right side of this pair.
-
-
Constructor Details
-
Pair
Construct a pair with both sides already initialized.- Parameters:
left
- The value for the left field.right
- The value for the right field.- Since:
- 0.0.4
-
Pair
public Pair()Construct a pair.- Since:
- 0.0.8
-
-
Method Details
-
setLeft
Set or change the left field of the pair.- Parameters:
l
- The new object for the left field.
-
left
Get the left field of the pair.- Returns:
- The left field.
-
setRight
Set or change the right field of the pair.- Parameters:
r
- The new object for the right field.
-
right
Get the right field of the pair.- Returns:
- The right field.
-
get
- Parameters:
side
- What side of the pair you want to get.- Returns:
- The object that's on the side.
-
set
Set or change both fields of the pair.- Parameters:
right
- The new object for the left field.left
- The new object for the right field.
-
clear
public void clear()Clears both the left and right side's values. -
clear
Clears the value of a specific side.- Parameters:
side
- The side to clear the value at.
-
isEmpty
public boolean isEmpty()Check if the pair is empty. This can also be checked by doing a null-check for the right and left side.- Returns:
- If the pair is empty.
-
isFull
public boolean isFull()Check if the pair is full. This can also be checked by doing a null-check for the right and left side.- Returns:
- If the pair is full.
-
contains
Checks if this pair contains the specified value.- Parameters:
o
- The object that's checked.- Returns:
true
if this pair contains the value,false
otherwise.
-
getHeavierSide
This gets the heavier side of the pair based on the length when usingObject.toString()
.- Returns:
- The heavier side of the pair.
- See Also:
-
getHeavierObject
This gets the heavier side of the pair based on the length when usingObject.toString()
.- Returns:
- The heavier object of the pair.
- See Also:
-
both
Runs some operation on both the left and right side.- Parameters:
operation
- The operation to run.- Since:
- 0.0.5
-
getIf
Gets the side matching the predicate's requirements.
If both operations match the requirement, it will return the left side.- Parameters:
operation
- What to check for.- Returns:
- The side matching the requirements (prioritizing the left size).
- Since:
- 0.0.5
-
toString
Convert the Pair to a readableString
.
It uses the simple scheme: `{"right":[right field
], "left":[left field
]}`. -
of
Static method to create a new Pair instance.- Type Parameters:
L
- The left value's type.R
- The right value's type.- Parameters:
left
- The value for the left field.right
- The value for the right field.- Returns:
- A new Pair instance with the set values.
- Since:
- 0.0.4
-
ofEntry
Static method to convert aMap.Entry
to a Pair, where the left side is the key and the right side is the value.- Type Parameters:
L
- The left value's, so map-entry's key, type.R
- The right value's, so map-entry's value, type.- Parameters:
entry
- The Map.Entry to convert to a Pair.- Returns:
- A new Pair instance with the same objects as the Entry.
-