Skip to content

Commit 30e1ca5

Browse files
authored
update javadoc for collection module (#59)
1 parent bef7bcc commit 30e1ca5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2393
-86
lines changed

rlib-collections/src/main/java/javasabr/rlib/collections/array/Array.java

Lines changed: 234 additions & 51 deletions
Large diffs are not rendered by default.

rlib-collections/src/main/java/javasabr/rlib/collections/array/ArrayBuilder.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,82 @@
44
import lombok.AccessLevel;
55
import lombok.experimental.FieldDefaults;
66

7+
/**
8+
* A builder for constructing immutable {@link Array} instances.
9+
*
10+
* @param <E> the type of elements in the array being built
11+
* @since 10.0.0
12+
*/
713
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
814
public final class ArrayBuilder<E> {
915

1016
MutableArray<E> elements;
1117

18+
/**
19+
* Creates a new array builder with the specified component type.
20+
*
21+
* @param type the component type of the array
22+
* @since 10.0.0
23+
*/
1224
public ArrayBuilder(Class<? super E> type) {
1325
this.elements = ArrayFactory.mutableArray(type);
1426
}
1527

28+
/**
29+
* Adds an element to the array being built.
30+
*
31+
* @param element the element to add
32+
* @return this builder for method chaining
33+
* @since 10.0.0
34+
*/
1635
public ArrayBuilder<E> add(E element) {
1736
elements.add(element);
1837
return this;
1938
}
2039

40+
/**
41+
* Adds multiple elements to the array being built.
42+
*
43+
* @param other the elements to add
44+
* @return this builder for method chaining
45+
* @since 10.0.0
46+
*/
2147
@SafeVarargs
2248
public final ArrayBuilder<E> add(E... other) {
2349
elements.addAll(other);
2450
return this;
2551
}
2652

53+
/**
54+
* Adds all elements from a collection to the array being built.
55+
*
56+
* @param other the collection of elements to add
57+
* @return this builder for method chaining
58+
* @since 10.0.0
59+
*/
2760
public ArrayBuilder<E> add(Collection<E> other) {
2861
elements.addAll(other);
2962
return this;
3063
}
3164

65+
/**
66+
* Adds all elements from an array to the array being built.
67+
*
68+
* @param other the array of elements to add
69+
* @return this builder for method chaining
70+
* @since 10.0.0
71+
*/
3272
public ArrayBuilder<E> add(Array<E> other) {
3373
elements.addAll(other);
3474
return this;
3575
}
3676

77+
/**
78+
* Builds and returns an immutable array containing all added elements.
79+
*
80+
* @return an immutable array containing all added elements
81+
* @since 10.0.0
82+
*/
3783
public Array<E> build() {
3884
return Array.copyOf(elements);
3985
}

rlib-collections/src/main/java/javasabr/rlib/collections/array/ArrayCollectors.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
import java.util.stream.Collector.Characteristics;
1313
import lombok.experimental.UtilityClass;
1414

15+
/**
16+
* Provides {@link Collector} implementations for collecting stream elements into {@link Array} instances.
17+
*
18+
* @since 10.0.0
19+
*/
1520
@UtilityClass
1621
public class ArrayCollectors {
1722

@@ -96,10 +101,26 @@ public Set<Characteristics> characteristics() {
96101
};
97102
}
98103

104+
/**
105+
* Returns a collector that accumulates elements into a mutable array.
106+
*
107+
* @param <T> the type of elements
108+
* @param type the component type of the array
109+
* @return a collector that collects elements into a mutable array
110+
* @since 10.0.0
111+
*/
99112
public static <T> Collector<T, MutableArray<T>, MutableArray<T>> toMutableArray(Class<? super T> type) {
100113
return mutableCollector(type, ArrayFactory::mutableArray);
101114
}
102115

116+
/**
117+
* Returns a collector that accumulates elements into an immutable array.
118+
*
119+
* @param <T> the type of elements
120+
* @param type the component type of the array
121+
* @return a collector that collects elements into an immutable array
122+
* @since 10.0.0
123+
*/
103124
public static <T> Collector<T, MutableArray<T>, Array<T>> toArray(Class<? super T> type) {
104125
return collector(type, ArrayFactory::mutableArray);
105126
}

rlib-collections/src/main/java/javasabr/rlib/collections/array/ArrayFactory.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,80 @@
88
import javasabr.rlib.common.util.ClassUtils;
99
import lombok.experimental.UtilityClass;
1010

11+
/**
12+
* Factory for creating various array implementations.
13+
*
14+
* @since 10.0.0
15+
*/
1116
@UtilityClass
1217
public class ArrayFactory {
1318

19+
/**
20+
* Creates a new mutable array of the specified type.
21+
*
22+
* @param <E> the type of elements
23+
* @param type the component type of the array
24+
* @return a new mutable array
25+
* @since 10.0.0
26+
*/
1427
public static <E> MutableArray<E> mutableArray(Class<? super E> type) {
1528
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type));
1629
}
1730

31+
/**
32+
* Creates a new mutable int array.
33+
*
34+
* @return a new mutable int array
35+
* @since 10.0.0
36+
*/
1837
public static MutableIntArray mutableIntArray() {
1938
return new DefaultMutableIntArray();
2039
}
2140

41+
/**
42+
* Creates a new mutable long array.
43+
*
44+
* @return a new mutable long array
45+
* @since 10.0.0
46+
*/
2247
public static MutableLongArray mutableLongArray() {
2348
return new DefaultMutableLongArray();
2449
}
2550

51+
/**
52+
* Creates a new mutable array of the specified type with initial capacity.
53+
*
54+
* @param <E> the type of elements
55+
* @param type the component type of the array
56+
* @param capacity the initial capacity
57+
* @return a new mutable array
58+
* @since 10.0.0
59+
*/
2660
public static <E> MutableArray<E> mutableArray(Class<? super E> type, int capacity) {
2761
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type), capacity);
2862
}
2963

3064

65+
/**
66+
* Creates a new copy-on-modify array of the specified type.
67+
*
68+
* @param <E> the type of elements
69+
* @param type the component type of the array
70+
* @return a new copy-on-modify array
71+
* @since 10.0.0
72+
*/
3173
public static <E> MutableArray<E> copyOnModifyArray(Class<? super E> type) {
3274
return new CopyOnWriteMutableArray<>(type);
3375
}
3476

77+
/**
78+
* Creates a new thread-safe array backed by a stamped lock.
79+
*
80+
* @param <E> the type of elements
81+
* @param type the component type of the array
82+
* @return a new lockable array
83+
* @since 10.0.0
84+
*/
3585
public static <E> LockableArray<E> stampedLockBasedArray(Class<? super E> type) {
3686
return new StampedLockBasedArray<>(type);
3787
}

rlib-collections/src/main/java/javasabr/rlib/collections/array/ArrayIterationFunctions.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,89 @@
77
import javasabr.rlib.functions.TriConsumer;
88
import org.jspecify.annotations.Nullable;
99

10+
/**
11+
* Provides iteration functions for arrays with support for additional arguments.
12+
*
13+
* @param <E> the type of elements in the array
14+
* @since 10.0.0
15+
*/
1016
public interface ArrayIterationFunctions<E> {
1117

18+
/**
19+
* Returns iteration functions with reversed argument order.
20+
*
21+
* @return reversed argument iteration functions
22+
* @since 10.0.0
23+
*/
1224
ReversedArgsArrayIterationFunctions<E> reversedArgs();
1325

26+
/**
27+
* Finds any element matching the filter predicate.
28+
*
29+
* @param <A> the type of the argument
30+
* @param arg1 the argument to pass to the filter
31+
* @param filter the predicate to match elements
32+
* @return the matching element or null
33+
* @since 10.0.0
34+
*/
1435
@Nullable
1536
<A> E findAny(A arg1, BiPredicate<? super E, A> filter);
1637

38+
/**
39+
* Finds any element matching the filter predicate with an int argument.
40+
*
41+
* @param arg1 the int argument to pass to the filter
42+
* @param filter the predicate to match elements
43+
* @return the matching element or null
44+
* @since 10.0.0
45+
*/
1746
@Nullable
1847
E findAny(int arg1, ObjIntPredicate<? super E> filter);
1948

49+
/**
50+
* Performs an action for each element with an additional argument.
51+
*
52+
* @param <A> the type of the argument
53+
* @param arg1 the argument to pass to the consumer
54+
* @param consumer the action to perform
55+
* @return this for method chaining
56+
* @since 10.0.0
57+
*/
2058
<A> ArrayIterationFunctions<E> forEach(A arg1, BiConsumer<? super E, A> consumer);
2159

60+
/**
61+
* Performs an action for each element with two additional arguments.
62+
*
63+
* @param <A> the type of the first argument
64+
* @param <B> the type of the second argument
65+
* @param arg1 the first argument to pass to the consumer
66+
* @param arg2 the second argument to pass to the consumer
67+
* @param consumer the action to perform
68+
* @return this for method chaining
69+
* @since 10.0.0
70+
*/
2271
<A, B> ArrayIterationFunctions<E> forEach(A arg1, B arg2, TriConsumer<? super E, A, B> consumer);
2372

73+
/**
74+
* Performs an action for each element with an object and long argument.
75+
*
76+
* @param <A> the type of the first argument
77+
* @param arg1 the first argument to pass to the consumer
78+
* @param arg2 the long argument to pass to the consumer
79+
* @param consumer the action to perform
80+
* @return this for method chaining
81+
* @since 10.0.0
82+
*/
2483
<A> ArrayIterationFunctions<E> forEach(A arg1, long arg2, ObjObjLongConsumer<? super E, A> consumer);
2584

85+
/**
86+
* Returns whether any element matches the filter predicate.
87+
*
88+
* @param <A> the type of the argument
89+
* @param arg1 the argument to pass to the filter
90+
* @param filter the predicate to match elements
91+
* @return true if any element matches
92+
* @since 10.0.0
93+
*/
2694
<A> boolean anyMatch(A arg1, BiPredicate<? super E, A> filter);
2795
}

0 commit comments

Comments
 (0)