-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
556 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/net/codersky/mcutils/java/tuple/pair/SafeImmutablePair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package net.codersky.mcutils.java.tuple.pair; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* An extension of {@link ImmutablePair} that implements the | ||
* {@link SafePair} interface, meaning that the elements stored | ||
* by this {@link Pair} cannot be {@code null}. | ||
* | ||
* @author xDec0de_ | ||
* | ||
* @param <F> The type of the first element to store. | ||
* @param <S> The type of the second element to store. | ||
* | ||
* @since MCUtils 1.0.0 | ||
* | ||
* @see SafeMutablePair | ||
*/ | ||
public class SafeImmutablePair<F, S> extends ImmutablePair<F, S> implements SafePair<F, S> { | ||
|
||
/** | ||
* Constructs a new {@link SafeImmutablePair} that contains | ||
* two elements which can't be {@code null}. | ||
* | ||
* @param first the first element to store. | ||
* @param second the second element to store. | ||
* | ||
* @throws NullPointerException if either {@code first} | ||
* or {@code second} are {@code null}. | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
public SafeImmutablePair(@Nonnull F first, @Nonnull S second) { | ||
super(Objects.requireNonNull(first), Objects.requireNonNull(second)); | ||
} | ||
|
||
// Doc override // | ||
|
||
/** | ||
* Gets the first element stored in this {@link SafeImmutablePair}, | ||
* which will <b>never</b> be {@code null}. | ||
* | ||
* @return The first element stored in this {@link SafeImmutablePair}, | ||
* never {@code null} | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nonnull | ||
@Override | ||
@SuppressWarnings("DataFlowIssue") | ||
public F getFirst() { | ||
return super.getFirst(); | ||
} | ||
|
||
/** | ||
* Gets the second element stored in this {@link SafeImmutablePair}, | ||
* which will <b>never</b> be {@code null}. | ||
* | ||
* @return The second element stored in this {@link SafeImmutablePair}, | ||
* never {@code null} | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nonnull | ||
@Override | ||
@SuppressWarnings("DataFlowIssue") | ||
public S getSecond() { | ||
return super.getSecond(); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/main/java/net/codersky/mcutils/java/tuple/pair/SafeMutablePair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package net.codersky.mcutils.java.tuple.pair; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* An extension of {@link MutablePair} that implements the | ||
* {@link SafePair} interface, meaning that the elements stored | ||
* by this {@link Pair} cannot be {@code null}. | ||
* | ||
* @author xDec0de_ | ||
* | ||
* @param <F> The type of the first element to store. | ||
* @param <S> The type of the second element to store. | ||
* | ||
* @since MCUtils 1.0.0 | ||
* | ||
* @see SafeImmutablePair | ||
*/ | ||
public class SafeMutablePair<F, S> extends MutablePair<F, S> implements SafePair<F, S> { | ||
|
||
/** | ||
* Constructs a new {@link SafeMutablePair} that contains | ||
* two elements which can't be {@code null}. | ||
* | ||
* @param first the first element to store. | ||
* @param second the second element to store. | ||
* | ||
* @throws NullPointerException if either {@code first} | ||
* or {@code second} are {@code null}. | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
public SafeMutablePair(@Nonnull F first, @Nonnull S second) { | ||
super(Objects.requireNonNull(first), Objects.requireNonNull(second)); | ||
} | ||
|
||
// Doc override // | ||
|
||
/** | ||
* Gets the first element stored in this {@link SafeMutablePair}, | ||
* which will <b>never</b> be {@code null}. | ||
* | ||
* @return The first element stored in this {@link SafeMutablePair}, | ||
* never {@code null} | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nonnull | ||
@Override | ||
@SuppressWarnings("DataFlowIssue") | ||
public F getFirst() { | ||
return super.getFirst(); | ||
} | ||
|
||
/** | ||
* Sets the first element stored on this {@link SafeMutablePair} | ||
* to {@code first}, which can't be {@code null}. | ||
* | ||
* @param first The new value of the first element. | ||
* | ||
* @return {@code first}, for convenience. | ||
* | ||
* @throws NullPointerException if {@code first} is {@code null}. | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nullable | ||
public F setFirst(@Nonnull F first) { | ||
return super.setFirst(Objects.requireNonNull(first)); | ||
} | ||
|
||
/** | ||
* Gets the second element stored in this {@link SafeMutablePair}, | ||
* which will <b>never</b> be {@code null}. | ||
* | ||
* @return The second element stored in this {@link SafeMutablePair}, | ||
* never {@code null} | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nonnull | ||
@Override | ||
@SuppressWarnings("DataFlowIssue") | ||
public S getSecond() { | ||
return super.getSecond(); | ||
} | ||
|
||
/** | ||
* Sets the second element stored on this {@link SafeMutablePair} | ||
* to {@code second}, which can't be {@code null}. | ||
* | ||
* @param second The new value of the second element. | ||
* | ||
* @return {@code second}, for convenience. | ||
* | ||
* @throws NullPointerException if {@code second} is {@code null}. | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nullable | ||
public S setSecond(@Nullable S second) { | ||
return super.setSecond(Objects.requireNonNull(second)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/net/codersky/mcutils/java/tuple/pair/SafePair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.codersky.mcutils.java.tuple.pair; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* An extension of the {@link Pair} interface that requires | ||
* stored elements to <b>never</b> be {@code null}. | ||
* | ||
* @author xDec0de_ | ||
* | ||
* @param <F> The type of the first element to store. | ||
* @param <S> The type of the second element to store. | ||
* | ||
* @since MCUtils 1.0.0 | ||
* | ||
* @see Pair | ||
* @see SafeMutablePair | ||
* @see SafeImmutablePair | ||
*/ | ||
public interface SafePair<F, S> extends Pair<F, S> { | ||
|
||
/** | ||
* Gets the first element stored in this {@link SafePair}, | ||
* which will <b>never</b> be {@code null}. | ||
* | ||
* @return The first element stored in this {@link SafePair}, | ||
* never {@code null} | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nonnull | ||
F getFirst(); | ||
|
||
/** | ||
* Gets the second element stored in this {@link SafePair}, | ||
* which will <b>never</b> be {@code null}. | ||
* | ||
* @return The second element stored in this {@link SafePair}, | ||
* never {@code null} | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@Nonnull | ||
S getSecond(); | ||
} |
Oops, something went wrong.