garydgregory commented on code in PR #1461:
URL: https://github.com/apache/commons-lang/pull/1461#discussion_r2415107050
##########
src/main/java/org/apache/commons/lang3/tuple/MutablePair.java:
##########
@@ -72,6 +72,23 @@ public static <L, R> MutablePair<L, R> of(final L left,
final R right) {
return new MutablePair<>(left, right);
}
+ /**
+ * Creates a mutable pair from an existing pair.
+ *
+ * <p>This factory allows the pair to be created using inference to
+ * obtain the generic types.</p>
+ *
+ * @param <L> the left element type.
+ * @param <R> the right element type.
+ * @param pair the existing pair.
+ * @return a pair formed from the two parameters, not null.
+ * @throws NullPointerException if {@code pair} is null.
+ */
+ public static <L,R> MutablePair<L,R> copyOf(final Pair<L,R> pair) {
Review Comment:
The method name should match the existing style, so `ofNonNull()`.
Type the input as an interface like `MutablePair.of(Entry<L, R>)`
##########
src/main/java/org/apache/commons/lang3/tuple/MutablePair.java:
##########
@@ -72,6 +72,23 @@ public static <L, R> MutablePair<L, R> of(final L left,
final R right) {
return new MutablePair<>(left, right);
}
+ /**
+ * Creates a mutable pair from an existing pair.
+ *
+ * <p>This factory allows the pair to be created using inference to
+ * obtain the generic types.</p>
+ *
+ * @param <L> the left element type.
+ * @param <R> the right element type.
+ * @param pair the existing pair.
+ * @return a pair formed from the two parameters, not null.
+ * @throws NullPointerException if {@code pair} is null.
+ */
Review Comment:
Add Javadoc `@since` tag.
##########
src/main/java/org/apache/commons/lang3/tuple/MutablePair.java:
##########
@@ -72,6 +72,23 @@ public static <L, R> MutablePair<L, R> of(final L left,
final R right) {
return new MutablePair<>(left, right);
}
+ /**
+ * Creates a mutable pair from an existing pair.
+ *
+ * <p>This factory allows the pair to be created using inference to
+ * obtain the generic types.</p>
+ *
+ * @param <L> the left element type.
+ * @param <R> the right element type.
+ * @param pair the existing pair.
+ * @return a pair formed from the two parameters, not null.
+ * @throws NullPointerException if {@code pair} is null.
+ */
+ public static <L,R> MutablePair<L,R> copyOf(final Pair<L,R> pair) {
+ Objects.requireNonNull(pair, "pair");
+ return new MutablePair<>(pair.getLeft(), pair.getRight());
Review Comment:
Delegate to `MutablePair.of(Entry<L, R>)` after calling
`Objects.requireNonNull()` like this:
```java
public static <L, R> MutablePair<L, R> ofNonNull(final Map.Entry<L, R>
pair) {
return of(Objects.requireNonNull(pair, "pair"));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]