Skip to content

Commit

Permalink
fix reactor#1135 Document (im)mutability of Tuple2 toList() vs iterat…
Browse files Browse the repository at this point in the history
…or()
  • Loading branch information
simonbasle authored Mar 21, 2018
1 parent 9dac17d commit 58c7c50
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions reactor-core/src/main/java/reactor/util/function/Tuple2.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,37 @@ public Object get(int index) {
}

/**
* Turn this {@literal Tuples} into a plain Object list.
* Turn this {@code Tuple} into a {@link List List<Object>}.
* The list isn't tied to this Tuple but is a <strong>copy</strong> with limited
* mutability ({@code add} and {@code remove} are not supported, but {@code set} is).
*
* @return A new Object list.
* @return A copy of the tuple as a new {@link List List&lt;Object&gt;}.
*/
public List<Object> toList() {
return Arrays.asList(toArray());
}

/**
* Turn this {@literal Tuples} into a plain Object array.
* Turn this {@code Tuple} into a plain {@code Object[]}.
* The array isn't tied to this Tuple but is a <strong>copy</strong>.
*
* @return A new Object array.
* @return A copy of the tuple as a new {@link Object Object[]}.
*/
public Object[] toArray() {
return new Object[]{t1, t2};
}

/**
* Return an <strong>immutable</strong> {@link Iterator Iterator&lt;Object&gt;} around
* the content of this {@code Tuple}.
*
* @implNote As an {@link Iterator} is always tied to its {@link Iterable} source by
* definition, the iterator cannot be mutable without the iterable also being mutable.
* Since {@link Tuples} are <strong>immutable</strong>, so is the {@link Iterator}
* returned by this method.
*
* @return An unmodifiable {@link Iterator} over the elements in this Tuple.
*/
@Override
public Iterator<Object> iterator() {
return Collections.unmodifiableList(toList()).iterator();
Expand Down

0 comments on commit 58c7c50

Please sign in to comment.