List<SubjectRelation> subjectRelationList = Arrays.asList(
new SubjectRelation(1, 1001, "Doohyun Nam", 1)
, new SubjectRelation(1, 1002, "Dolkin", 2)
, new SubjectRelation(1, 1003, "hshawng", 1)
, new SubjectRelation(1, 1004, "spKwon", 1)
, new SubjectRelation(2, 1005, "Other Person1", 3)
, new SubjectRelation(2, 1006, "Other Person2", 4)
);
// create Map
Map<Integer, Collection<String>> mapTest = Observable.fromIterable(subjectRelationList).
toMultimap(SubjectRelation::getCompanySubjectSn, SubjectRelation::getMemberName).
blockingGet();
// only subscribe
Observable.fromIterable(subjectRelationList)
.groupBy(SubjectRelation::getCompanySubjectSn).subscribe(group -> {
System.out.println(group.getKey());
group.map(SubjectRelation::getMemberName).forEach(System.out::println);
});
// create multi group
Map<Integer, Map<Integer, Collection<String>>> doubleKeyMap = new HashMap<>();
Observable.fromIterable(subjectRelationList).
groupBy(SubjectRelation::getCompanySubjectSn).
blockingSubscribe(group ->
doubleKeyMap.put(group.getKey(),
group.toMultimap(
SubjectRelation::getOrganizationSubjectSn
, SubjectRelation::getMemberName).blockingGet())
);
// partitioning
Map<Boolean, Collection<String>> partitioningMap = Observable.fromIterable(subjectRelationList).
toMultimap(subjectRelation -> subjectRelation.getCompanySubjectSn().intValue() == 1
, SubjectRelation::getMemberName).
blockingGet();