Notice
Recent Posts
Recent Comments
올해는 머신러닝이다.
Rxjava2 Collection 예제 본문
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();
'링크모음 > rxjava' 카테고리의 다른 글
RxJava 를 활용한 효과적인 네트워크 체크 풀링 (0) | 2017.09.27 |
---|---|
RxJava2 함수 간단 예제 모음 (0) | 2017.09.15 |
RxJava Extection 라이버러리 (0) | 2017.09.15 |
Rxjava를 활용한 두개의 리스트 항목 비교 (0) | 2017.09.14 |
RxAndroid 활용한 라이버러리 모음 (0) | 2017.09.14 |