Skip to content

Commit

Permalink
chore(refactor): add some helpers tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Jan 21, 2022
1 parent 4ee5664 commit 79bcc33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 14 additions & 0 deletions core/src/main/java/io/kestra/core/repositories/ArrayListTotal.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static java.util.stream.Collectors.toCollection;

@Getter
@NoArgsConstructor
Expand All @@ -25,8 +28,19 @@ public static <T> ArrayListTotal<T> of(Pageable pageable, List<T> list) {
return new ArrayListTotal<T>(list.subList(from, to), size);
}

public ArrayListTotal(long total) {
this.total = total;
}

public ArrayListTotal(List<T> list, long total) {
super(list);
this.total = total;
}

public <R> ArrayListTotal<R> map(Function<T, R> map) {
return this
.stream()
.map(map)
.collect(toCollection(() -> new ArrayListTotal<R>(this.total)));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package io.kestra.webserver.utils;

import io.micronaut.http.exceptions.HttpStatusException;
import io.kestra.core.repositories.ArrayListTotal;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AutocompleteUtils {
@SafeVarargs
public static <T> List<T> from(List<T>... lists) throws HttpStatusException {
public static <T, R> List<R> map(Function<T, R> map, List<T>... lists) throws HttpStatusException {
Stream<T> stream = Stream.empty();

for (List<T> list : lists) {
Expand All @@ -22,6 +21,13 @@ public static <T> List<T> from(List<T>... lists) throws HttpStatusException {

return stream
.distinct()
.map(map)
.collect(Collectors.toList());
}

@SafeVarargs
public static <T> List<T> from(List<T>... lists) throws HttpStatusException {
return AutocompleteUtils
.map(o -> o, lists);
}
}

0 comments on commit 79bcc33

Please sign in to comment.