1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +01:00

Add documentation to CollectionUtils methods

This commit is contained in:
Paul Schaub 2021-12-28 01:34:50 +01:00
parent 376e234baf
commit 2f44621657

View file

@ -15,6 +15,13 @@ public final class CollectionUtils {
}
/**
* Return all items returned by the {@link Iterator} as a {@link List}.
*
* @param iterator iterator
* @param <I> type
* @return list
*/
public static <I> List<I> iteratorToList(Iterator<I> iterator) {
List<I> items = new ArrayList<>();
while (iterator.hasNext()) {
@ -24,6 +31,13 @@ public final class CollectionUtils {
return items;
}
/**
* Return a new array which contains <pre>t</pre> as first element, followed by the elements of <pre>ts</pre>.
* @param t head
* @param ts tail
* @param <T> type
* @return t and ts as array
*/
public static <T> T[] concat(T t, T[] ts) {
T[] concat = (T[]) Array.newInstance(t.getClass(), ts.length + 1);
concat[0] = t;
@ -31,6 +45,13 @@ public final class CollectionUtils {
return concat;
}
/**
* Return true, if the given array <pre>ts</pre> contains the element <pre>t</pre>.
* @param ts elements
* @param t searched element
* @param <T> type
* @return true if ts contains t, false otherwise
*/
public static <T> boolean contains(T[] ts, T t) {
for (T i : ts) {
if (i.equals(t)) {