WEBVTT

00:00.570 --> 00:01.110
Hi everyone.

00:01.110 --> 00:02.400
Welcome back to this tutorial.

00:02.400 --> 00:08.250
In this tutorial, we will explore the group by which accepts two parameter as an input in the previous

00:08.250 --> 00:08.670
tutorial.

00:08.670 --> 00:12.810
If you take a look at it, we just passed the one parameter version.

00:12.810 --> 00:17.010
We are going to explore the two parameter version in this tutorial.

00:21.470 --> 00:27.680
The first use case that we are going to code, we are going to create a two level grouping.

00:28.890 --> 00:33.420
Going to create a method called public static void.

00:35.180 --> 00:35.660
Level.

00:37.010 --> 00:43.010
Grouping, and then I'm going to give it as one because we'll be coding multiple examples on the same

00:43.040 --> 00:46.160
two level, on the same two parameter version of grouping.

00:46.160 --> 00:46.500
Why?

00:47.760 --> 00:53.730
So I'm going to call the get all students and then the next call is going to be stream and the next

00:53.730 --> 00:55.010
call is going to be collect.

00:55.020 --> 01:01.380
So we want to collect or we want to group the students based on their grade level.

01:01.380 --> 01:06.150
So it's going to be student colon, colon grade level.

01:06.150 --> 01:11.760
So this is the classifier for this we have to give the grouping by.

01:13.000 --> 01:14.020
Let's close it here.

01:14.590 --> 01:20.320
So this is similar to the previous version that we have here in here, what we are going to do, we

01:20.320 --> 01:23.440
are going to add the second parameter.

01:23.440 --> 01:28.120
If you go ahead and take a look at the grouping by it, accept it, accept the first parameter, which

01:28.120 --> 01:31.510
is a classifier, and the second parameter which is a downstream.

01:31.510 --> 01:38.200
So this downstream can be any type of grouping by implementation or any type of collector implementation.

01:38.200 --> 01:44.560
Basically what I'm going to do again in this example, I'm going to do another grouping by basically

01:44.560 --> 01:45.070
what it is.

01:45.100 --> 01:52.240
What is this going to happen is that this is going to create another level of map.

01:52.240 --> 01:58.270
So here we have the map and the value values or list of students.

01:58.270 --> 02:02.020
But in this use case, it is going to be a map of string.

02:02.020 --> 02:04.030
And again, another map here.

02:04.030 --> 02:10.540
So in here, what we are going to do, I'm going to group the students with this same category.

02:11.830 --> 02:12.760
There you go.

02:12.760 --> 02:15.160
So let's take a look at the output.

02:15.430 --> 02:21.010
It's going to be map of string, which is going to hold the grade level.

02:21.010 --> 02:26.080
And then the values are again, going to be map of string.

02:27.010 --> 02:29.470
And list of student.

02:32.250 --> 02:33.970
So this is called.

02:35.590 --> 02:36.640
Global mapping.

02:40.220 --> 02:43.070
So this is called two level mapping.

02:43.700 --> 02:44.000
Let's see.

02:44.000 --> 02:45.200
There are some issues here.

02:45.200 --> 02:46.760
Let's go ahead and take a look at it.

02:46.940 --> 02:49.210
This is going to be a student map.

02:49.220 --> 02:51.650
This is good here in here.

02:51.650 --> 02:52.880
What is going on?

02:53.450 --> 02:55.400
Let's give the name as student map.

02:56.370 --> 02:59.880
The map of it would be a string.

02:59.880 --> 03:02.540
Let's go and check what is a grade level or the grade level is.

03:02.550 --> 03:05.610
And so in that case it is going to be integer.

03:06.580 --> 03:07.150
There you go.

03:07.150 --> 03:09.520
So let's revisit this example again.

03:09.520 --> 03:12.820
So in this example, we are performing two level grouping.

03:12.820 --> 03:18.280
The first grouping is at the grade level and the second grouping is again going to be similar to the

03:18.280 --> 03:19.750
one which we coded here.

03:19.750 --> 03:26.050
It is going to tag each and every student as outstanding or average based on their GPA.

03:26.740 --> 03:28.300
Let's go ahead and run this example.

03:28.300 --> 03:34.030
Once you look at the result it will make it will give you more idea or more understanding of what's

03:34.030 --> 03:34.990
going on here.

03:38.810 --> 03:40.430
I'm going to run this example.

03:43.660 --> 03:45.310
And we are not printing anything here.

03:45.310 --> 03:47.580
That's the reason why we don't see anything here.

03:47.590 --> 03:48.970
I'm going to print it here.

03:50.830 --> 03:52.390
Run this example again.

03:52.720 --> 03:53.590
There you go.

03:53.590 --> 03:55.120
You have the result here.

03:55.120 --> 03:56.850
Let's let's review the result here.

03:56.860 --> 04:05.260
So here it has the first level of map, which has a key as a grade level and the second level of map,

04:05.260 --> 04:11.650
which is tagging each and every student in each and every grade as average and outstanding.

04:11.650 --> 04:16.900
If you take a look at it in the second grade, there is one average student who is Adam and there is

04:16.900 --> 04:18.640
one outstanding student who is Jenny.

04:19.300 --> 04:22.720
That's the same case with the third grade and fourth grade.

04:22.720 --> 04:32.560
In the fourth grade, there is no average student because their GPA is 4.0 and 3.9, which is matching

04:32.560 --> 04:34.450
the outstanding key.

04:36.000 --> 04:39.000
Let's explore one more example on this same topic.

04:39.000 --> 04:41.310
So here we have used grouping by rate.

04:41.340 --> 04:43.110
We can also use.

04:44.480 --> 04:45.620
Some other.

04:45.740 --> 04:48.200
I just copied the method from there and put it here.

04:48.230 --> 04:50.690
Let's use some other collector here.

04:50.720 --> 04:53.030
The collector is going to be.

04:55.000 --> 04:55.930
Summing int.

04:55.960 --> 05:00.130
So summing int is one collector which we have explored in one of the previous tutorial.

05:00.340 --> 05:02.230
I'm going to use the summing int.

05:02.260 --> 05:08.800
What it is going to accept is that it is going to take student colon colon notebooks.

05:09.370 --> 05:11.680
So here it is going to be.

05:13.190 --> 05:15.320
A map of integer.

05:16.550 --> 05:18.290
An integer, right?

05:18.290 --> 05:25.580
Because this summing int is again going to return an integer and this grade level is already mapping

05:25.610 --> 05:26.450
to an integer.

05:26.450 --> 05:33.350
So this is another way of using the two parameter grouping by.

05:34.270 --> 05:34.710
Method.

05:34.720 --> 05:40.720
So the first one is a classifier, which is going to be the key for the total.

05:40.900 --> 05:41.920
Output map.

05:41.920 --> 05:46.300
And then this determines what is a value that it is going to have.

05:46.330 --> 05:48.220
Let's call this method and check the result.

05:50.800 --> 05:51.960
Want to take a look at it.

05:53.120 --> 05:54.020
I'm going to run this.

05:55.430 --> 05:55.660
Run.

05:55.660 --> 05:56.320
The result?

05:56.350 --> 05:59.740
The two has 23 and three.

05:59.770 --> 06:04.540
Third grade has 19 books and fourth grade has 29 books.

06:05.520 --> 06:11.610
And if you want to group them based on based on their name, you can do that too.

06:11.660 --> 06:16.320
If we do, a get name is going to give you the key as.

06:17.750 --> 06:22.000
Thus because it's going to be a string, because getName is of type string, right?

06:22.010 --> 06:27.080
If I run this example, it is going to have name and their appropriate notebooks count.

06:27.110 --> 06:27.840
There you go.

06:27.860 --> 06:29.270
Adam as a notebook.

06:29.420 --> 06:30.630
Adam as 11 notebooks.

06:30.650 --> 06:31.850
Emily has ten.

06:32.030 --> 06:38.270
The following students have their appropriate notebook count mapped here, and it is grouped as a map

06:38.300 --> 06:38.810
here.

06:39.020 --> 06:42.770
So this is all about the two parameter grouping by.

06:43.750 --> 06:44.080
With this.

06:44.080 --> 06:45.710
We came to the end of this tutorial.

06:45.730 --> 06:46.930
Thank you for watching.
