/**
* @author 陳楊
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class CollectorsDetail {
private List<String> names;
private List<Student> students;
private List<List<String>> snames;
@Before
public void init() {
names = Arrays.asList("Kirito", "Asuna", "Sinon", "Yuuki", "Alice");
snames = Arrays.asList(Collections.singletonList("Kirito"), Collections.singletonList("Asuna"),
Collections.singletonList("Sinon"), Collections.singletonList("Yuuki"),
Collections.singletonList("Alice"));
students = new Students().init();
}
@Test
public void testCollectorsDetail() {
1、靜態工廠類Collectors 實現方式
// 1、靜態工廠類Collectors 實現方式
// Collectors 靜態工廠類 最終由CollectorImpl實現
// 一、 經過CollectorImpl實現
// 二、 經過reducing()實現---> reducing()底層由CollectorImpl實現
// Collectors.toList() 是 Collectors.toCollection()的一種具化表現形式
// Collectors.joining() 使用StringBuilder.append 拼接字符串
2、靜態工廠類Collectors 經常使用收集器
// 2、靜態工廠類Collectors 經常使用收集器
/*
返回一個(不可修改)unmodifiable List的ArrayList 按照相遇的順序encounter order
@since 10
@SuppressWarnings("unchecked")
public static <T>
Collector<T, ?, List<T>> toUnmodifiableList() {
return new CollectorImpl<>((Supplier<List<T>>) ArrayList::new, List::add,
(left, right) -> { left.addAll(right); return left; },
list -> (List<T>)List.of(list.toArray()),
CH_NOID);
}*/
/*
返回一個(不可修改)unmodifiable Set的HashSet 無序
@since 10
@SuppressWarnings("unchecked")
public static <T>
Collector<T, ?, Set<T>> toUnmodifiableSet() {
return new CollectorImpl<>((Supplier<Set<T>>) HashSet::new, Set::add,
(left, right) -> {
if (left.size() < right.size()) {
right.addAll(left); return right;
} else {
left.addAll(right); return left;
}
},
set -> (Set<T>)Set.of(set.toArray()),
CH_UNORDERED_NOID);
}
*/
/*
返回一個flatMapping扁平化mapper處理後 由downstream收集的 累加器處理的結果合併 單線程
@since 9
public static <T, U, A, R>
Collector<T, ?, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper,
Collector<? super U, A, R> downstream) {
BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator();
return new CollectorImpl<>(downstream.supplier(),
(r, t) -> {
try (Stream<? extends U> result = mapper.apply(t)) {
if (result != null)
result.sequential().forEach(u -> downstreamAccumulator.accept(r, u));
}
},
downstream.combiner(), downstream.finisher(),
downstream.characteristics());
}*/
/*
對符合Predicate預期結果 進行過濾filtering 使用downstream 收集元素
@since 9
public static <T, A, R>
Collector<T, ?, R> filtering(Predicate<? super T> predicate,
Collector<? super T, A, R> downstream) {
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
return new CollectorImpl<>(downstream.supplier(),
(r, t) -> {
if (predicate.test(t)) {
downstreamAccumulator.accept(r, t);
}
},
downstream.combiner(), downstream.finisher(),
downstream.characteristics());
}*/
/*
使用Map映射key-->keyMapper-->Key value-->valueMapper-->Value
對映射後的結果進行組裝entrySet-->Map<Key,Value> (unmodifiable Map)
@since 10
@SuppressWarnings({"rawtypes", "unchecked"})
public static <T, K, U>
Collector<T, ?, Map<K,U>> toUnmodifiableMap(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper) {
Objects.requireNonNull(keyMapper, "keyMapper");
Objects.requireNonNull(valueMapper, "valueMapper");
return collectingAndThen(
toMap(keyMapper, valueMapper),
map -> (Map<K,U>)Map.ofEntries(map.entrySet().toArray(new Map.Entry[0])));
}*/
/*
使用Map映射key-->keyMapper-->Key value-->valueMapper-->Value
mergeFunction 對相同key 映射後的進行Value 合併操做
對映射後的結果進行組裝entrySet-->Map<Key,Value> (unmodifiable Map)
@since 10
@SuppressWarnings({"rawtypes", "unchecked"})
public static <T, K, U>
Collector<T, ?, Map<K,U>> toUnmodifiableMap(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper,
BinaryOperator<U> mergeFunction) {
Objects.requireNonNull(keyMapper, "keyMapper");
Objects.requireNonNull(valueMapper, "valueMapper");
Objects.requireNonNull(mergeFunction, "mergeFunction");
return collectingAndThen(
toMap(keyMapper, valueMapper, mergeFunction, HashMap::new),
map -> (Map<K,U>)Map.ofEntries(map.entrySet().toArray(new Map.Entry[0])));
}*/
// Collectors 收集器
System.out.println("-----------------------------------------\n");
// 使用ArrayList集合 按照流中元素排列前後順序 進行添加操做
List<String> unmodifiableList = names.stream().collect(Collectors.toUnmodifiableList());
System.out.println(unmodifiableList);
System.out.println("---------------------------------------\n");
// 使用HashSet集合 對流中元素順序 進行添加操做
Set<String> unmodifiableSet = names.stream().collect(Collectors.toUnmodifiableSet());
System.out.println(unmodifiableSet);
System.out.println("---------------------------------------\n");
// 將集合扁平化展開 對其中的字符串的每一個字母 進行大寫轉換 使用ArrayList對轉換後的結果進行收集
List<String> strings = snames.stream()
.collect(Collectors.flatMapping(list -> list.stream().map(String::toUpperCase), Collectors.toList()));
System.out.println(strings);
System.out.println("---------------------------------------\n");
// 對流中元素進行遍歷 對符合預期要求的元素 使用ArrayList集合存放
List<String> filteringPredicate = names.stream().collect(Collectors.filtering("Kirito"::equals,
Collectors.toList()));
System.out.println(filteringPredicate);
System.out.println("---------------------------------------\n");
// 對流中元素進行遍歷 對key-->keyMapper value-->valueMapper 映射 獲得Map集合
Map<Integer, List<Student>> listMap = students.stream()
.collect(Collectors.toUnmodifiableMap(Student::getId, student -> {
List<Student> stus = new ArrayList<>();
stus.add(student);
return stus;
}));
System.out.println(listMap);
System.out.println("---------------------------------------\n");
// 對流中元素進行遍歷 對key-->keyMapper-->Key value-->valueMapper-->Value 映射
// 對知足相同Key的元素 Value進行合併
Map<Integer, String> lengthName = names.stream()
.collect(Collectors.toUnmodifiableMap(String::length,
String::toString, (str1, str2) -> str1 + "\t" + str2));
System.out.println(lengthName);
System.out.println("---------------------------------------\n");
3、groupingBy分組
// 3、groupingBy分組
// 分組 groupingBy
// 對T元素按 key進行分組 --> 分組的依據 classifier--> 分組後的集合 value--> 獲得 Map<key,value>
/*
Returns a {@code Collector} implementing a "group by" operation on
input elements of type {@code T}, grouping elements according to a
classification function, and returning the results in a {@code Map}.
<p>The classification function maps elements to some key type {@code K}.
The collector produces a {@code Map<K, List<T>>} whose keys are the
values resulting from applying the classification function to the input
elements, and whose corresponding values are {@code List}s containing the
input elements which map to the associated key under the classification
function.
<p>There are no guarantees on the type, mutability, serializability, or
thread-safety of the {@code Map} or {@code List} objects returned.*/
/*
按照key對T進行classifier分組
使用List集合收集分組結果 單線程 線程安全
public static <T, K> Collector<T, ?, Map<K, List<T>>>
groupingBy(Function<? super T, ? extends K> classifier) {
return groupingBy(classifier, toList());
}*/
/*
按照key對T進行classifier分組
使用自定義收集器downstream 收集分組結果 單線程 線程安全
public static <T, K, A, D>
Collector<T, ?, Map<K, D>> groupingBy(Function<? super T, ? extends K> classifier,
Collector<? super T, A, D> downstream) {
return groupingBy(classifier, HashMap::new, downstream);
}*/
/*
按照key對T進行classifier分組
使用自定義mapFactory 重置downstream的CollectorImpl實現
使用自定義收集器downstream 收集分組結果 單線程 線程安全
public static <T, K, D, A, M extends Map<K, D>>
Collector<T, ?, M> groupingBy(Function<? super T, ? extends K> classifier,
Supplier<M> mapFactory,
Collector<? super T, A, D> downstream) {
Supplier<A> downstreamSupplier = downstream.supplier();
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
BiConsumer<Map<K, A>, T> accumulator = (m, t) -> {
K key = Objects.requireNonNull(classifier.apply(t), "element cannot be mapped to a null key");
A container = m.computeIfAbsent(key, k -> downstreamSupplier.get());
downstreamAccumulator.accept(container, t);
};
BinaryOperator<Map<K, A>> merger = Collectors.<K, A, Map<K, A>>mapMerger(downstream.combiner());
@SuppressWarnings("unchecked")
Supplier<Map<K, A>> mangledFactory = (Supplier<Map<K, A>>) mapFactory;
// 不進行強制類型轉換 重構CollectorImpl實現
if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
return new CollectorImpl<>(mangledFactory, accumulator, merger, CH_ID);
}
else {
// 進行強制類型轉換 重構CollectorImpl實現
@SuppressWarnings("unchecked")
Function<A, A> downstreamFinisher = (Function<A, A>) downstream.finisher();
Function<Map<K, A>, M> finisher = intermediate -> {
intermediate.replaceAll((k, v) -> downstreamFinisher.apply(v));
@SuppressWarnings("unchecked")
M castResult = (M) intermediate;
return castResult;
};
return new CollectorImpl<>(mangledFactory, accumulator, merger, finisher, CH_NOID);
}
}*/
// 分組
System.out.println("-----------------------------------------\n");
// select * from students group by sex ;
Map<String, List<Student>> sexStudent =
students.stream().collect(Collectors.groupingBy(Student::getSex));
System.out.println(sexStudent);
System.out.println("-----------------------------------------\n");
// select sex, count(*) from students group by sex ;
Map<String, Long> sexCount =
students.stream().collect(Collectors.groupingBy(Student::getSex, Collectors.counting()));
System.out.println(sexCount);
System.out.println("-----------------------------------------\n");
// select sex,avg(salary) from students group by sex ;
Map<String, Double> avgSexSalary = students.stream().collect
(Collectors.groupingBy(Student::getSex, Collectors.averagingDouble(Student::getSalary)));
System.out.println(avgSexSalary);
System.out.println("-----------------------------------------\n");
// 嵌套分組 先根據sex分組 再對結果按照addr進行分組
Map<String, Map<String, List<Student>>> NestedGroupBy = students.stream()
.collect(Collectors.groupingBy(Student::getSex, Collectors.groupingBy(Student::getAddr)));
System.out.println(NestedGroupBy);
System.out.println("-----------------------------------------\n");
// 使用自定義收集器downstream 按性別分組 使用HashSet進行 結果收集
Map<String, HashSet<Student>> sexHashSet = students.stream()
.collect(Collectors.groupingBy(Student::getSex, Collectors.toCollection(HashSet::new)));
System.out.println(sexHashSet);
System.out.println("-----------------------------------------\n");
// 使用自定義收集器downstream 按性別分組 使用HashSet進行 結果收集 重置CollectorImpl實現
Map<String, HashSet<Student>> sexCustomCollectorImpl = students.stream()
.collect(Collectors.groupingBy(Student::getSex, Hashtable::new, Collectors.toCollection(HashSet::new)));
System.out.println(sexCustomCollectorImpl);
System.out.println("-----------------------------------------\n");
4、groupingByConcurrent分組
// 4、groupingByConcurrent分組
// 分組 groupingByConcurrent
// 流的適用條件:
// 無序 Collector.Characteristics.UNORDERED
// 併發 Collector.Characteristics.CONCURRENT
// This is a {@link Collector.Characteristics#CONCURRENT concurrent} and
// {@link Collector.Characteristics#UNORDERED unordered} Collector.
/*
按照key對T進行classifier分組
使用List集合收集分組結果
public static <T, K>
Collector<T, ?, ConcurrentMap<K, List<T>>>
groupingByConcurrent(Function<? super T, ? extends K> classifier) {
return groupingByConcurrent(classifier, ::new, toList());
}*/
/*
按照key對T進行classifier分組
使用自定義收集器downstream 收集分組結果
public static <T, K, A, D>
Collector<T, ?, ConcurrentMap<K, D>> groupingByConcurrent(Function<? super T, ? extends K> classifier,
Collector<? super T, A, D> downstream) {
return groupingByConcurrent(classifier, ConcurrentHashMap::new, downstream);
}*/
/*
按照key對T進行classifier分組
使用自定義累加器mapFactory 重置downstream的CollectorImpl實現
使用自定義收集器downstream 收集分組結果
public static <T, K, A, D, M extends ConcurrentMap<K, D>>
Collector<T, ?, M> groupingByConcurrent(Function<? super T, ? extends K> classifier,
Supplier<M> mapFactory,
Collector<? super T, A, D> downstream) {
Supplier<A> downstreamSupplier = downstream.supplier();
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
BinaryOperator<ConcurrentMap<K, A>> merger = Collectors.<K, A, ConcurrentMap<K, A>>mapMerger(downstream.combiner());
@SuppressWarnings("unchecked")
Supplier<ConcurrentMap<K, A>> mangledFactory = (Supplier<ConcurrentMap<K, A>>) mapFactory;
BiConsumer<ConcurrentMap<K, A>, T> accumulator;
if (downstream.characteristics().contains(Collector.Characteristics.CONCURRENT)) {
accumulator = (m, t) -> {
K key = Objects.requireNonNull(classifier.apply(t), "element cannot be mapped to a null key");
A resultContainer = m.computeIfAbsent(key, k -> downstreamSupplier.get());
downstreamAccumulator.accept(resultContainer, t);
};
}
else {
accumulator = (m, t) -> {
K key = Objects.requireNonNull(classifier.apply(t), "element cannot be mapped to a null key");
A resultContainer = m.computeIfAbsent(key, k -> downstreamSupplier.get());
// 多個操做-->同時操做同一個結果容器-->同一時間,有且只有一個進行實際操做-->線程同步
synchronized (resultContainer) {
downstreamAccumulator.accept(resultContainer, t);
}
};
}
if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
return new CollectorImpl<>(mangledFactory, accumulator, merger, CH_CONCURRENT_ID);
}
else {
@SuppressWarnings("unchecked")
Function<A, A> downstreamFinisher = (Function<A, A>) downstream.finisher();
Function<ConcurrentMap<K, A>, M> finisher = intermediate -> {
intermediate.replaceAll((k, v) -> downstreamFinisher.apply(v));
@SuppressWarnings("unchecked")
M castResult = (M) intermediate;
return castResult;
};
return new CollectorImpl<>(mangledFactory, accumulator, merger, finisher, CH_CONCURRENT_NOID);
}
}*/
// 分組 無序 併發
System.out.println("-----------------------------------------\n");
// 按性別分組 使用ArrayList進行 結果收集
ConcurrentMap<String, List<Student>> sexStudentConcurrent = students.stream()
.collect(Collectors.groupingByConcurrent(Student::getSex));
System.out.println(sexStudentConcurrent);
System.out.println("-----------------------------------------\n");
// 使用自定義收集器downstream 按性別分組 使用HashSet進行 結果收集
ConcurrentMap<String, HashSet<Student>> sexHashSetConcurrent = students.stream()
.collect(Collectors.groupingByConcurrent(Student::getSex, Collectors.toCollection(HashSet::new)));
System.out.println(sexHashSetConcurrent);
System.out.println("-----------------------------------------\n");
// 使用自定義收集器downstream 按性別分組 使用HashSet進行 結果收集 重置CollectorImpl實現
ConcurrentReferenceHashMap<String, HashSet<Student>> sexCustomCollectorImplConcurrent =
students.stream().collect(Collectors.groupingByConcurrent(Student::getSex,
ConcurrentReferenceHashMap::new, Collectors.toCollection(HashSet::new)));
System.out.println(sexCustomCollectorImplConcurrent);
System.out.println("-----------------------------------------\n");
5、partitioningBy分區
// 5、partitioningBy分區
// 分區 partitioningBy
/*
對知足預期的條件 進行分區 使用ArrayList 進行結果的收集
public static <T>
Collector<T, ?, Map<Boolean, List<T>>> partitioningBy(Predicate<? super T> predicate) {
return partitioningBy(predicate, toList());
}*/
/*
對知足預期的條件 進行分區 使用自定義收集器downstream 進行結果的收集
public static <T, D, A>
Collector<T, ?, Map<Boolean, D>> partitioningBy(Predicate<? super T> predicate,
Collector<? super T, A, D> downstream) {
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
BiConsumer<Partition<A>, T> accumulator = (result, t) ->
downstreamAccumulator.accept(predicate.test(t) ? result.forTrue : result.forFalse, t);
BinaryOperator<A> op = downstream.combiner();
BinaryOperator<Partition<A>> merger = (left, right) ->
new Partition<>(op.apply(left.forTrue, right.forTrue),
op.apply(left.forFalse, right.forFalse));
Supplier<Partition<A>> supplier = () ->
new Partition<>(downstream.supplier().get(),
downstream.supplier().get());
if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
return new CollectorImpl<>(supplier, accumulator, merger, CH_ID);
}
else {
Function<Partition<A>, Map<Boolean, D>> finisher = par ->
new Partition<>(downstream.finisher().apply(par.forTrue),
downstream.finisher().apply(par.forFalse));
return new CollectorImpl<>(supplier, accumulator, merger, finisher, CH_NOID);
}
}*/
// 分區
System.out.println("-----------------------------------------\n");
// select * from students partition by (addr == Sword Art Online) ;
Map<Boolean, List<Student>> addrPartition = students.stream().collect
(Collectors.partitioningBy(student -> student.getAddr().equals("Sword Art Online")));
System.out.println(addrPartition);
System.out.println("-----------------------------------------\n");
// 嵌套分區 先根據sex分區 再對結果按照addr進行分區
Map<Boolean, Map<Boolean, List<Student>>> NestedPartiton = students.stream()
.collect(Collectors.partitioningBy(student -> student.getSex().equals("Male"),
Collectors.partitioningBy(student -> student.getAddr().equals("Sword Art Online"))));
System.out.println(NestedPartiton);
System.out.println("-----------------------------------------\n");
// 使用自定義downstream收集器分區
Map<Boolean, HashSet<Student>> addrCustomPartition = students.stream().collect(Collectors.partitioningBy
(student -> student.getAddr().equals("Sword Art Online"), Collectors.toCollection(HashSet::new)));
System.out.println(addrCustomPartition);
System.out.println("-----------------------------------------\n");
}
}
6、測試結果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-02-20 16:58:15.870 INFO 13392 --- [ main] c.j.d.java8.Stream.CollectorsDetail : Starting CollectorsDetail on DESKTOP-87RMBG4 with PID 13392 (started by 46250 in E:\IdeaProjects\design)
2019-02-20 16:58:15.871 INFO 13392 --- [ main] c.j.d.java8.Stream.CollectorsDetail : No active profile set, falling back to default profiles: default
2019-02-20 16:58:16.383 INFO 13392 --- [ main] c.j.d.java8.Stream.CollectorsDetail : Started CollectorsDetail in 0.708 seconds (JVM running for 1.421)
-----------------------------------------
[Kirito, Asuna, Sinon, Yuuki, Alice]
---------------------------------------
[Yuuki, Asuna, Kirito, Sinon, Alice]
---------------------------------------
[KIRITO, ASUNA, SINON, YUUKI, ALICE]
---------------------------------------
[Kirito]
---------------------------------------
{5=[Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], 4=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8)], 3=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8)], 2=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], 1=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
---------------------------------------
{6=Kirito, 5=Asuna Sinon Yuuki Alice}
---------------------------------------
-----------------------------------------
{Female=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------
{Female=4, Male=1}
-----------------------------------------
{Female=9.99999999E8, Male=9.99999999E8}
-----------------------------------------
{Female={Alicization=[Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], Sword Art Online=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Gun Gale Online=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8)], Alfheim Online=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8)]}, Male={Sword Art Online=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}}
-----------------------------------------
{Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------
{Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------
-----------------------------------------
{Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)], Female=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)]}
-----------------------------------------
{Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)], Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------
{Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------
-----------------------------------------
{false=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], true=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------
{false={false=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], true=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)]}, true={false=[], true=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}}
-----------------------------------------
{false=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], true=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8), Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------