Predicate interface :
Represents a predicate (boolean-valued function) of one argument.This is a functional interface whose functional method is
test(Object)
.please refer below link for more inforamation:
https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
package utlfunc;
import java.util.function.BiPredicate;
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
public class GraspPrdicate {
public static void main(String[] args) {
Predicate<String> prdcate= (check)->checkStiringEmpty(check);
System.out.println(prdcate.test("from predicate"));
BiPredicate<String , Integer> biPrdcate=(a,c)->checkStiringEmpty(a, c);
System.out.println(biPrdcate.test(" from Bipredicaate", 345));
BiPredicate<Integer,Integer> expBiPrdcate=(x,y)->x>y;
BiPredicate<Integer,Integer> expOnePrdcate=(x,y)->x-2>y;
System.out.println(expBiPrdcate.and(expOnePrdcate).test(10, 5));
System.out.println(expBiPrdcate.or(expOnePrdcate).test(6,7));
IntPredicate prdcateInt=(x)->checkInt(x);
prdcateInt.test(234);
IntPredicate prdciateTest=(y)->y>1;
System.out.println(prdciateTest.test(21));
System.out.println(prdciateTest.and(prdcateInt).test(23));
System.out.println(prdciateTest.or(prdcateInt).test(23));
LongPredicate lngPrdcate=(y)->checkLng(y);
System.out.println(lngPrdcate.test(21l));
}
public static boolean checkStiringEmpty(String check) {
return check.length()>0?true:false;
}
public static boolean checkStiringEmpty(String check,int b) {
return check.length()>0 && b>0?true:false;
}
public static boolean checkInt(int a) {
return a>0?true:false;
}
public static boolean checkLng(Long a) {
return a>0?true:false;
}
}
No comments:
Post a Comment