Skip to content

Commit b9ec2de

Browse files
authored
Array/Try/Multimap JavaDocs overhaul (#2996)
1 parent b341a5f commit b9ec2de

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

vavr/src/main/java/io/vavr/collection/AbstractMultimap.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
import static io.vavr.API.Tuple;
3131

3232
/**
33-
* An {@link Multimap} implementation (not intended to be public).
33+
* An abstract base implementation of the {@link Multimap} interface that provides
34+
* common functionality for concrete Multimap implementations. This class is not
35+
* intended to be public and serves as a foundation for specialized Multimap types.
3436
*
3537
* @param <K> Key type
3638
* @param <V> Value type
37-
* @param <M> Multimap type
39+
* @param <M> Concrete Multimap type extending this class
3840
* @author Ruslan Sennov
3941
*/
4042
abstract class AbstractMultimap<K, V, M extends Multimap<K, V>> implements Multimap<K, V> {
@@ -45,18 +47,57 @@ abstract class AbstractMultimap<K, V, M extends Multimap<K, V>> implements Multi
4547
protected final SerializableSupplier<Traversable<?>> emptyContainer;
4648
private final ContainerType containerType;
4749

50+
/**
51+
* Creates a new AbstractMultimap with the specified backing map, container type, and empty container supplier.
52+
*
53+
* @param back The backing map that stores the key-value pairs
54+
* @param containerType The type of container used to store multiple values for a key
55+
* @param emptyContainer A supplier that creates empty containers for new key entries
56+
*/
4857
AbstractMultimap(Map<K, Traversable<V>> back, ContainerType containerType, SerializableSupplier<Traversable<?>> emptyContainer) {
4958
this.back = back;
5059
this.containerType = containerType;
5160
this.emptyContainer = emptyContainer;
5261
}
5362

63+
/**
64+
* Returns an empty Map instance specific to the implementing class.
65+
*
66+
* @param <K2> Key type of the empty map
67+
* @param <V2> Value type of the empty map
68+
* @return An empty Map instance
69+
*/
5470
protected abstract <K2, V2> Map<K2, V2> emptyMapSupplier();
5571

72+
/**
73+
* Returns an empty Multimap instance specific to the implementing class.
74+
*
75+
* @param <K2> Key type of the empty multimap
76+
* @param <V2> Value type of the empty multimap
77+
* @return An empty Multimap instance
78+
*/
5679
protected abstract <K2, V2> Multimap<K2, V2> emptyInstance();
5780

81+
/**
82+
* Creates a new Multimap instance from the given backing map.
83+
*
84+
* @param <K2> Key type of the new multimap
85+
* @param <V2> Value type of the new multimap
86+
* @param back The backing map to create the multimap from
87+
* @return A new Multimap instance containing the entries from the backing map
88+
*/
5889
protected abstract <K2, V2> Multimap<K2, V2> createFromMap(Map<K2, Traversable<V2>> back);
5990

91+
/**
92+
* Creates a new Multimap from the given entries by grouping values by their keys.
93+
* For each key, a new container is created using the emptyContainer supplier,
94+
* and values are added using the containerType's add operation.
95+
*
96+
* @param <K2> Key type of the new multimap
97+
* @param <V2> Value type of the new multimap
98+
* @param entries The entries to create the multimap from
99+
* @return A new Multimap containing all the entries with values grouped by keys
100+
*/
60101
@SuppressWarnings("unchecked")
61102
private <K2, V2> Multimap<K2, V2> createFromEntries(Iterable<? extends Tuple2<? extends K2, ? extends V2>> entries) {
62103
Map<K2, Traversable<V2>> back = emptyMapSupplier();

vavr/src/main/java/io/vavr/collection/Array.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import static java.util.Arrays.sort;
3434

3535
/**
36-
* Array is a Traversable wrapper for {@code Object[]} containing elements of type {@code T}.
36+
* Array is an immutable Traversable wrapper for {@code Object[]} containing elements of type {@code T}.
3737
*
3838
* @param <T> Component type
3939
* @author Ruslan Sennov, Daniel Dietrich
@@ -120,8 +120,8 @@ public static <T> Array<T> of(T... elements) {
120120
/**
121121
* Creates an Array of the given elements.
122122
* <p>
123-
* The resulting Array has the same iteration order as the given iterable of elements
124-
* if the iteration order of the elements is stable.
123+
* If the iteration order of the given elements is stable, the resulting Array
124+
* will maintain that same order.
125125
*
126126
* @param <T> Component type of the Array.
127127
* @param elements An Iterable of elements.
@@ -654,7 +654,7 @@ public Array<T> asJavaMutable(Consumer<? super java.util.List<T>> action) {
654654
public <R> Array<R> collect(PartialFunction<? super T, ? extends R> partialFunction) {
655655
return ofAll(iterator().<R> collect(partialFunction));
656656
}
657-
657+
658658
@Override
659659
public boolean hasDefiniteSize() {
660660
return true;

vavr/src/main/java/io/vavr/control/Try.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ default <U> Try<U> mapTry(CheckedFunction1<? super T, ? extends U> mapper) {
635635
}
636636
}
637637
}
638-
638+
639639
/**
640640
* Consumes the cause if this is a {@link Try.Failure}.
641641
*
@@ -820,9 +820,10 @@ default <X extends Throwable> Try<T> recover(Class<X> exceptionType, Function<?
820820
}
821821

822822
/**
823-
* Returns {@code this}, if this is a {@code Success} or this is a {@code Failure} and the cause is not assignable
824-
* from {@code cause.getClass()}. Otherwise tries to recover the exception of the failure with {@code f} <b>which returns Try</b>.
825-
* If {@link Try#isFailure()} returned by {@code f} function is <code>true</code> it means that recovery cannot take place due to some circumstances.
823+
* Returns {@code this} if this is a {@code Success}, or if this is a {@code Failure} and the cause is not assignable
824+
* from {@code exceptionType}. Otherwise, attempts to recover from the failure using the provided recovery function {@code f}.
825+
* The recovery function returns a new {@code Try} instance. If the returned {@code Try} is a {@link Try#isFailure()},
826+
* it indicates that the recovery was not successful.
826827
*
827828
* <pre>{@code
828829
* // = Success(13)
@@ -839,8 +840,8 @@ default <X extends Throwable> Try<T> recover(Class<X> exceptionType, Function<?
839840
*
840841
* @param <X> Exception type
841842
* @param exceptionType The specific exception type that should be handled
842-
* @param f A recovery function taking an exception of type {@code X} and returning Try as a result of recovery.
843-
* If Try is {@link Try#isSuccess()} then recovery ends up successfully. Otherwise the function was not able to recover.
843+
* @param f A recovery function that takes an exception of type {@code X} and returns a new Try instance.
844+
* The recovery is considered successful if the returned Try is a {@link Try#isSuccess()}.
844845
* @return a {@code Try}
845846
* @throws NullPointerException if {@code exceptionType} or {@code f} is null
846847
*/
@@ -887,7 +888,7 @@ default <X extends Throwable> Try<T> recoverWith(Class<X> exceptionType, Functio
887888
*/
888889
@GwtIncompatible
889890
default <X extends Throwable> Try<T> recoverWith(Class<X> exceptionType, Try<? extends T> recovered){
890-
Objects.requireNonNull(exceptionType, "exeptionType is null");
891+
Objects.requireNonNull(exceptionType, "exceptionType is null");
891892
Objects.requireNonNull(recovered, "recovered is null");
892893
return (isFailure() && exceptionType.isAssignableFrom(getCause().getClass()))
893894
? narrow(recovered)
@@ -915,7 +916,7 @@ default <X extends Throwable> Try<T> recoverWith(Class<X> exceptionType, Try<?
915916
* @param exceptionType The specific exception type that should be handled
916917
* @param value A value that is used in case of a recovery
917918
* @return a {@code Try}
918-
* @throws NullPointerException if {@code exception} is null
919+
* @throws NullPointerException if {@code exceptionType} is null
919920
*/
920921
@GwtIncompatible
921922
default <X extends Throwable> Try<T> recover(Class<X> exceptionType, T value) {

0 commit comments

Comments
 (0)