Skip to content

Commit b415e3b

Browse files
author
Jafar Husain
committed
Adding explanation to the two last remaining exercises.
1 parent ffe42af commit b415e3b

File tree

1 file changed

+67
-16
lines changed

1 file changed

+67
-16
lines changed

src/main/java/learnrxjava/ComposableListExercises.java

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -977,44 +977,95 @@ public static ComposableList<JSON> exercise23() {
977977
throw new UnsupportedOperationException("Not implemented yet.");
978978
}
979979

980+
/*
981+
Exercise 24: Converting Lists to Trees
982+
983+
Now that we've learned the five operators let's flex our muscles and write some powerful queries.
984+
985+
When information is organized hierarchically, parent hold references to their children. In relational systems like databases, children hold references to their parents. Both ways of organizing information are equivalent, and depending on the circumstances we might get data organized in one way or another. It may surprise you to learn that you can use the methods you already know to easily convert between these representations. In other words, not only can you transform trees into lists, you can transform lists into trees.
986+
987+
We have 2 lists each containing lists, and videos respectively. Each video has a listId field indicating its parent list. We want to build a list of movie list objects, each with a name and a videos array. The videos list will contain the video's id and title. In other words we want to build the following structure:
988+
*/
980989
public static ComposableList<List<MovieList>> exercise24() {
981990
ComposableListExercises<MovieListRow> lists = ComposableListExercises.of(
982991
new MovieListRow(
983-
5434364,
984-
"New Releases"
992+
5434364,
993+
"New Releases"
985994
),
986995
new MovieListRow(
987-
65456475,
988-
"Thrillers"
996+
65456475,
997+
"Thrillers"
989998
)
990999
);
9911000
ComposableList<VideoRow> videos = ComposableListExercises.of(
9921001
new VideoRow(
993-
5434364,
994-
65432445,
995-
"The Chamber"
1002+
5434364,
1003+
65432445,
1004+
"The Chamber"
9961005
),
9971006
new VideoRow(
998-
5434364,
999-
675465,
1000-
"Fracture"
1007+
5434364,
1008+
675465,
1009+
"Fracture"
10011010
),
10021011
new VideoRow(
1003-
65456475,
1004-
70111470,
1005-
"Die Hard"
1012+
65456475,
1013+
70111470,
1014+
"Die Hard"
10061015
),
10071016
new VideoRow(
1008-
65456475,
1009-
654356453,
1010-
"Bad Boys"
1017+
65456475,
1018+
654356453,
1019+
"Bad Boys"
10111020
)
10121021
);
10131022

10141023
// return lists. // complete this expression
10151024
throw new UnsupportedOperationException("Not implemented yet.");
10161025
}
10171026

1027+
/*
1028+
Exercise 25: Converting Lists to Deeper Trees
1029+
1030+
Let's try creating a deeper tree structure. This time we have 4 seperate lists each containing movie lists, videos, boxarts, and bookmarks respectively. Each object has a parent id, indicating its parent. We want to build a list of movie list objects, each with a name and a videos array. The videos list will contain the video's id, title, bookmark time, and smallest boxart url. In other words we want to build the following structure:
1031+
1032+
[
1033+
{
1034+
"name": "New Releases",
1035+
"videos": [
1036+
{
1037+
"id": 65432445,
1038+
"title": "The Chamber",
1039+
"time": 32432,
1040+
"boxart": "http://cdn-0.nflximg.com/images/2891/TheChamber130.jpg"
1041+
},
1042+
{
1043+
"id": 675465,
1044+
"title": "Fracture",
1045+
"time": 3534543,
1046+
"boxart": "http://cdn-0.nflximg.com/images/2891/Fracture120.jpg"
1047+
}
1048+
]
1049+
},
1050+
{
1051+
"name": "Thrillers",
1052+
"videos": [
1053+
{
1054+
"id": 70111470,
1055+
"title": "Die Hard",
1056+
"time": 645243,
1057+
"boxart": "http://cdn-0.nflximg.com/images/2891/DieHard150.jpg"
1058+
},
1059+
{
1060+
"id": 654356453,
1061+
"title": "Bad Boys",
1062+
"time": 984934,
1063+
"boxart": "http://cdn-0.nflximg.com/images/2891/BadBoys140.jpg"
1064+
}
1065+
]
1066+
}
1067+
]
1068+
*/
10181069
public static ComposableList<List<MovieList>> exercise25() {
10191070
ComposableListExercises<MovieListRow> lists = ComposableListExercises.of(
10201071
new MovieListRow(

0 commit comments

Comments
 (0)