Hi everyone.
Welcome back to this tutorial.
In this tutorial we will code and explore the by predicate example.
So by predicate is again a functional interface.
Let's go ahead and explore that.
It's part of the Java Radial dot function package.
Click on that.
Buy predicate is also similar to predicate.
It has one method called test and it is accepting two inputs, but the return type is the same.
It is going to return the boolean and it has another default method called and.
A gate and or it has all the default method, whatever the predicate has.
And it is going to behave the same as the predicate.
The only difference is by predicate is for two input parameters.
Predicate is for one input parameter.
So in this example, what we coded as part of the previous tutorial here, we have a condition.
We are using two different predicates in order to apply the filtering on the student list.
Now what I'm going to do, I'm going to create a bi predicate instance and then use that bi predicate
instance to apply the filtering of students from the student list.
Masterpiece.
Let's create the by predicate instance.
If you take a look at it, the first one is an integer.
The second one is a double, right?
So let's define the types integer.
And double.
I'm going to name this one as my predicate.
Now we have to pass into two values, right?
The first one is grade level can give any value you want.
It's just like a reference variable.
The next thing is GPA.
And then what it is going to do, it is going to check.
The grade level.
Is greater than or equal to three.
And.
GPA is greater than or equal to 3.9.
So we are performing these two checks as part of this, right?
So since it is a single line statement, you don't even have to provide the curly braces as part of
the lambda body.
So once this is evaluated, if this is true, true boolean result will be returned.
If it is false, then false Boolean result will be returned as part of this.
The next step is instead of this what I'm going to do.
Going to call this dot test.
We have to pass the inputs.
The first one, if you take a look at it, it is a grade level, right?
Get grade level, comma, student dot.
Get GPA.
And then is going to behave as let's go ahead and run this one and then check whether is it giving us
the same result as it was prior to the by predicate?
There you go.
It printed the same result as before.
We want you can create a multiple bike predicate instances and then you can use the and operation.
So if you press command space or sorry, control space, it will give you all these different operations
it supports.
You can use and you can use n number of and or you can use or or different methods.
Okay.
I'm going to remove this for now.
So this is all about by predicate.
By predicate.
To summarize this by predicate is basically is going to accept two parameters and perform some kind
of operation on the input, whatever that is being passed to that by predicate instance.
And it is going to return a Boolean value as a result.
With this, we came to the end of this tutorial.
Thank you for watching.