티스토리 뷰

반응형

1.Comparator
- Comparator.comparing : comparing은 Comparator의 정적 메서드로 Function을 인자로 받는다.
<예> Comparator<Test> c = Comparator.comparing(Test::getTest);
- reversed : 역정렬
<예> Comparator.comparing(Test::getTest).reversed();
- thenComparing : 첫 비교결과가 동일할 경우 다음 비교 Function을 설정할 수 있다.
<예> Comparator.comparing(Test::getTest).reversed().thenComparing(Test::getScore());

2. Predicate
- negate : 기존 Predicate을 반전 시킬때
<예> Predicate<Test> notMaxScore = maxScore.negate();
- and : Predicate들을 and 조건으로 연결하여 하나의 Predicate로 만들 때.
<예> Predicate<Test> maxAndMin = maxScore.and(Test::min);
- or : Predicate들을 or 조건으로 연결하여 하나의 Predicate로 만들 때.
<예> Predicate<Test> maxAndMinOrMath = maxScore.and(Test::min).or(Test::math);

3. Function
- andThen : 주어진 함수를 먼저 연산하고 연산한 결과를 다음 함수에 전달한다.
<예>
Function<Integer, Integer> f = x -> x + 4;
Function<Integer, Integer> g = x -> x * 4;
Function<Integer, Integer> h = f.andThen(g);
-> f를 먼저 연산하고 g를 연산
h.apply(1) -> 20

- compose : 인수로 주어진 함수를 먼저 연산하고 그 결과를 앞선 함수에 적용한다. Function<Integer, Integer> f = x -> x + 4;
Function<Integer, Integer> g = x -> x * 4;
Function<Integer, Integer> h = f.compose(g);
-> g를 먼저 연산하고 f를 연산
h.apply(1) -> 8

 

*참고 : Java 8 in Action (한빛 미디어) 


반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함