Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit fc25c1d

Browse files
authored
Merge pull request #29 from alexengrig/fix/18
Fixes #18
2 parents dc94347 + 689f9cf commit fc25c1d

File tree

1 file changed

+175
-7
lines changed
  • src/main/java/io/github/alexengrig/lambdax/collection

1 file changed

+175
-7
lines changed

src/main/java/io/github/alexengrig/lambdax/collection/SetX.java

+175-7
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,245 @@
2424
import java.util.function.Predicate;
2525

2626
/**
27-
* This utility class contains useful lambdas for {@link Set}
27+
* This utility class contains useful lambdas for {@link java.util.Set}.
2828
*
2929
* @author Grig Alex
30-
* @see Set
31-
* @see Collection
32-
* @see Consumer
33-
* @see Function
34-
* @see IntFunction
35-
* @see Predicate
30+
* @version 0.1.1
31+
* @see java.util.Collection
32+
* @see java.util.Set
33+
* @see java.util.function.Consumer
34+
* @see java.util.function.Function
35+
* @see java.util.function.IntFunction
36+
* @see java.util.function.Predicate
3637
* @since 0.1.0
3738
*/
3839
public final class SetX {
3940
private SetX() {
4041
}
4142

43+
/**
44+
* <p>Returns the carrying of {@link java.util.Set#contains(Object)}:
45+
* item -&gt; set -&gt; set.contains(item).</p>
46+
*
47+
* @param item an element of {@link E} that is passed as the argument to {@link java.util.Set#contains(Object)}
48+
* @param <E> a type of elements in a set.
49+
* @return a {@link java.util.function.Predicate}.
50+
* @see java.util.Set#contains(Object)
51+
* @see java.util.function.Predicate
52+
* @since 0.1.0
53+
*/
4254
public static <E> Predicate<Set<? extends E>> contains(E item) {
4355
return s -> s.contains(item);
4456
}
4557

58+
/**
59+
* <p>Returns the carrying of {@link java.util.Set#containsAll(Collection)}:
60+
* all -&gt; set -&gt; set.containsAll(all).</p>
61+
*
62+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#containsAll(Collection)}
63+
* @param <E> a type of elements in a set.
64+
* @return a {@link java.util.function.Predicate}.
65+
* @see java.util.Set#containsAll(Collection)
66+
* @see java.util.function.Predicate
67+
* @since 0.1.0
68+
*/
4669
public static <E> Predicate<Set<? extends E>> containsAll(Collection<? extends E> all) {
4770
return s -> s.containsAll(all);
4871
}
4972

73+
/**
74+
* <p>Returns the carrying of {@link java.util.Set#add(Object)}:
75+
* item -&gt; set -&gt; set.add(item).</p>
76+
*
77+
* @param item an element of {@link E} that is passed as the argument to {@link java.util.Set#add(Object)}
78+
* @param <E> a type of elements in a set.
79+
* @return a {@link java.util.function.Predicate}.
80+
* @see java.util.Set#add(Object)
81+
* @see java.util.function.Predicate
82+
* @since 0.1.0
83+
*/
5084
public static <E> Predicate<Set<? super E>> add(E item) {
5185
return s -> s.add(item);
5286
}
5387

88+
/**
89+
* <p>Returns the carrying of {@link java.util.Set#addAll(Collection)}:
90+
* all -&gt; set -&gt; set.addAll(all).</p>
91+
*
92+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#addAll(Collection)}
93+
* @param <E> a type of elements in a set.
94+
* @return a {@link java.util.function.Predicate}.
95+
* @see java.util.Set#addAll(Collection)
96+
* @see java.util.function.Predicate
97+
* @since 0.1.0
98+
*/
5499
public static <E> Predicate<Set<? super E>> addAll(Collection<? extends E> all) {
55100
return s -> s.addAll(all);
56101
}
57102

103+
/**
104+
* <p>Returns the carrying of {@link java.util.Set#add(Object)}:
105+
* item -&gt; set -&gt; set.add(item).</p>
106+
*
107+
* @param item an element of {@link E} that is passed as the argument to {@link java.util.Set#add(Object)}
108+
* @param <E> a type of elements in a set.
109+
* @return a {@link java.util.function.Consumer}.
110+
* @see java.util.Set#add(Object)
111+
* @see java.util.function.Consumer
112+
* @since 0.1.0
113+
*/
58114
public static <E> Consumer<Set<? super E>> onlyAdd(E item) {
59115
return s -> s.add(item);
60116
}
61117

118+
/**
119+
* <p>Returns the carrying of {@link java.util.Set#addAll(Collection)}:
120+
* all -&gt; set -&gt; set.addAll(all).</p>
121+
*
122+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#addAll(Collection)}
123+
* @param <E> a type of elements in a set.
124+
* @return a {@link java.util.function.Consumer}.
125+
* @see java.util.Set#addAll(Collection)
126+
* @see java.util.function.Consumer
127+
* @since 0.1.0
128+
*/
62129
public static <E> Consumer<Set<? super E>> onlyAddAll(Collection<? extends E> all) {
63130
return s -> s.addAll(all);
64131
}
65132

133+
/**
134+
* <p>Returns the carrying of {@link java.util.Set#remove(Object)}:
135+
* item -&gt; set -&gt; set.remove(item).</p>
136+
*
137+
* @param item an element of {@link E} that is passed as the argument to {@link java.util.Set#remove(Object)}
138+
* @param <E> a type of elements in a set.
139+
* @return a {@link java.util.function.Predicate}.
140+
* @see java.util.Set#remove(Object)
141+
* @see java.util.function.Predicate
142+
* @since 0.1.0
143+
*/
66144
public static <E> Predicate<Set<? super E>> remove(E item) {
67145
return s -> s.remove(item);
68146
}
69147

148+
/**
149+
* <p>Returns the carrying of {@link java.util.Set#removeAll(Collection)}:
150+
* all -&gt; set -&gt; set.removeAll(all).</p>
151+
*
152+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#removeAll(Collection)}
153+
* @param <E> a type of elements in a set.
154+
* @return a {@link java.util.function.Predicate}.
155+
* @see java.util.Set#removeAll(Collection)
156+
* @see java.util.function.Predicate
157+
* @since 0.1.0
158+
*/
70159
public static <E> Predicate<Set<? super E>> removeAll(Collection<? extends E> all) {
71160
return s -> s.removeAll(all);
72161
}
73162

163+
/**
164+
* <p>Returns the carrying of {@link java.util.Set#remove(Object)}:
165+
* item -&gt; set -&gt; set.remove(item).</p>
166+
*
167+
* @param item an element of {@link E} that is passed as the argument to {@link java.util.Set#remove(Object)}
168+
* @param <E> a type of elements in a set.
169+
* @return a {@link java.util.function.Consumer}.
170+
* @see java.util.Set#remove(Object)
171+
* @see java.util.function.Consumer
172+
* @since 0.1.0
173+
*/
74174
public static <E> Consumer<Set<? super E>> onlyRemove(E item) {
75175
return s -> s.remove(item);
76176
}
77177

178+
/**
179+
* <p>Returns the carrying of {@link java.util.Set#removeAll(Collection)}:
180+
* all -&gt; set -&gt; set.removeAll(all).</p>
181+
*
182+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#removeAll(Collection)}
183+
* @param <E> a type of elements in a set.
184+
* @return a {@link java.util.function.Consumer}.
185+
* @see java.util.Set#removeAll(Collection)
186+
* @see java.util.function.Consumer
187+
* @since 0.1.0
188+
*/
78189
public static <E> Consumer<Set<? super E>> onlyRemoveAll(Collection<? extends E> all) {
79190
return s -> s.removeAll(all);
80191
}
81192

193+
/**
194+
* <p>Returns the carrying of {@link java.util.Set#retainAll(Collection)}:
195+
* all -&gt; set -&gt; set.retainAll(all).</p>
196+
*
197+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#retainAll(Collection)}
198+
* @param <E> a type of elements in a set.
199+
* @return a {@link java.util.function.Predicate}.
200+
* @see java.util.Set#retainAll(Collection)
201+
* @see java.util.function.Predicate
202+
* @since 0.1.0
203+
*/
82204
public static <E> Predicate<Set<? super E>> retainAll(Collection<? extends E> all) {
83205
return s -> s.retainAll(all);
84206
}
85207

208+
/**
209+
* <p>Returns the carrying of {@link java.util.Set#retainAll(Collection)}:
210+
* all -&gt; set -&gt; set.retainAll(all).</p>
211+
*
212+
* @param all a {@link java.util.Collection} that is passed as the argument to {@link java.util.Set#retainAll(Collection)}
213+
* @param <E> a type of elements in a set.
214+
* @return a {@link java.util.function.Consumer}.
215+
* @see java.util.Set#retainAll(Collection)
216+
* @see java.util.function.Consumer
217+
* @since 0.1.0
218+
*/
86219
public static <E> Consumer<Set<? super E>> onlyRetainAll(Collection<? extends E> all) {
87220
return s -> s.retainAll(all);
88221
}
89222

223+
/**
224+
* <p>Returns the carrying of {@link java.util.Set#toArray(Object[])}}:
225+
* array -&gt; set -&gt; set.toArray(array).</p>
226+
*
227+
* @param array an array of {@link E} objects that is passed as the argument to {@link java.util.Set#toArray(Object[])}
228+
* @param <E> a type of elements in a set.
229+
* @return a {@link java.util.function.Function}.
230+
* @see java.util.Set#toArray(Object[])
231+
* @see java.util.function.Function
232+
* @since 0.1.0
233+
*/
90234
public static <E> Function<Set<? extends E>, E[]> toArray(E[] array) {
91235
return c -> c.toArray(array);
92236
}
93237

238+
/**
239+
* <p>Returns the carrying of {@link java.util.Set#toArray(Object[])}}:
240+
* arrayGenerator -&gt; set -&gt; set.toArray(arrayGenerator.apply(0).</p>
241+
*
242+
* @param generator a {@link java.util.function.IntFunction} of array generator (array constructor)
243+
* the result of which is passed as the argument to {@link java.util.Set#toArray(Object[])}
244+
* @param <E> a type of elements in a set.
245+
* @return a {@link java.util.function.Function}.
246+
* @see java.util.Set#toArray(Object[])
247+
* @see java.util.function.IntFunction
248+
* @see java.util.function.Function
249+
* @since 0.1.0
250+
*/
94251
public static <E> Function<Set<? extends E>, E[]> toArray(IntFunction<? extends E[]> generator) {
95252
return c -> c.toArray(generator.apply(0));
96253
}
97254

255+
/**
256+
* <p>Returns the carrying of {@link java.util.Set#equals(Object)}:
257+
* other -&gt; set -&gt; set.equals(other).</p>
258+
*
259+
* @param other an {@link java.lang.Object} that is passed as the argument to {@link java.util.Set#equals(Object)})}
260+
* @param <E> a type of elements in a set.
261+
* @return a {@link java.util.function.Predicate}.
262+
* @see java.util.Set#equals(Object)
263+
* @see java.util.function.Predicate
264+
* @since 0.1.0
265+
*/
98266
public static <E> Predicate<Set<? extends E>> equalsTo(Object other) {
99267
return c -> c.equals(other);
100268
}

0 commit comments

Comments
 (0)