DoublePredicate
DoublePredicate (double 프레디케이트)
하나의 double 값 인자에 대한 프레디케이트(boolean 값을 반환하는 함수)를 나타내는 함수형 인터페이스예요. Predicate의 double 소비 원시 타입 특수화예요.
본문
DoublePredicate의 추상 메서드는 test(double)로 double 인자를 받아 boolean을 반환해요. 기본 메서드로 and, or, negate가 있어 결합·부정할 수 있어요.
@FunctionalInterface
public interface DoublePredicate
DoublePredicate positive = d -> d > 0;
DoublePredicate small = d -> Math.abs(d) < 100;
boolean r1 = positive.test(5.0); // true
boolean r2 = positive.and(small).test(50.0); // true
boolean r3 = positive.negate().test(-2.0); // true
DoubleStream.filter에 자주 사용돼요.
double[] results = DoubleStream.of(1.0, -2.0, 30.0)
.filter(d -> d > 0)
.toArray(); // [1.0, 30.0]
함수형 메서드는 test(double)예요. 코드와 시그니처는 원문 그대로 보존돼요.