class Ideone {
public static void main
(String[] args
) { final Relation
<Integer, Integer
> isLarger
= (x, y
) -> x
< y
; final Relation
<Integer, Integer
> isSmallerOrEqual
= isLarger.
negate(); System.
out.
println(isLarger.
test(1,
2)); System.
out.
println(isSmallerOrEqual.
test(1,
2)); }
}
interface Relation<X,Y> {
boolean test(X x, Y y);
default Relation<X,Y> negate() {
return (x, y) -> !this.test(x, y);
}
}
Y2xhc3MgSWRlb25lIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBmaW5hbCBSZWxhdGlvbjxJbnRlZ2VyLCBJbnRlZ2VyPiBpc0xhcmdlciA9ICh4LCB5KSAtPiB4IDwgeTsKICAgICAgICBmaW5hbCBSZWxhdGlvbjxJbnRlZ2VyLCBJbnRlZ2VyPiBpc1NtYWxsZXJPckVxdWFsID0gaXNMYXJnZXIubmVnYXRlKCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGlzTGFyZ2VyLnRlc3QoMSwgMikpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihpc1NtYWxsZXJPckVxdWFsLnRlc3QoMSwgMikpOwogICAgfQp9CgppbnRlcmZhY2UgUmVsYXRpb248WCxZPiB7CgogICAgYm9vbGVhbiB0ZXN0KFggeCwgWSB5KTsKCiAgICBkZWZhdWx0IFJlbGF0aW9uPFgsWT4gbmVnYXRlKCkgewogICAgICAgIHJldHVybiAoeCwgeSkgLT4gIXRoaXMudGVzdCh4LCB5KTsKICAgIH0KfQ==