|
@@ -17,6 +17,7 @@ import net.ranides.assira.reflection.BeanModel;
|
|
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
import java.util.stream.IntStream;
|
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
@@ -58,11 +59,14 @@ public class Grid<T> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static <T> Grid<T> fromMap(List<? extends Map<String, T>> records) {
|
|
public static <T> Grid<T> fromMap(List<? extends Map<String, T>> records) {
|
|
|
- Set<String> headset = new LinkedHashSet<>();
|
|
|
|
|
- records.stream().map(Map::keySet).forEach(headset::addAll);
|
|
|
|
|
-
|
|
|
|
|
- List<String> head = new ArrayList<>(headset);
|
|
|
|
|
- List<List<T>> data = records.stream().map(r -> head.stream().map((String key) -> r.get(key)).collect(toList())).collect(toList());
|
|
|
|
|
|
|
+ List<String> head = records.stream()
|
|
|
|
|
+ .flatMap(map -> map.keySet().stream())
|
|
|
|
|
+ .distinct()
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<List<T>> data = records.stream()
|
|
|
|
|
+ .map(r -> head.stream().map(r::get).collect(toList()))
|
|
|
|
|
+ .collect(toList());
|
|
|
|
|
|
|
|
return new Grid<>(head, data);
|
|
return new Grid<>(head, data);
|
|
|
}
|
|
}
|