1
00:00:05,240 --> 00:00:09,760
so lets just run this program again just to
make sure that it is showing the four

2
00:00:09,760 --> 00:00:14,940
field variables that we have defined and you can
see down their we got the fourth fields putting

3
00:00:14,940 --> 00:00:19,570
up the artist field the album field
the year field and the song field so that's

4
00:00:19,570 --> 00:00:25,000
working fine so the
first approach that I'll take to putting

5
00:00:25,000 --> 00:00:29,380
the data into the classes follows
naturally from the data in other words

6
00:00:29,380 --> 00:00:34,730
as each row is read we are gonna create a song object
and then add that to the album and when

7
00:00:34,730 --> 00:00:38,790
a new album is found in the data the current album is gonna be stored in the

8
00:00:38,790 --> 00:00:43,960
artist's album list and a new album
object created with that current rows

9
00:00:43,960 --> 00:00:49,130
details and likewise the same things can
happen when a record for a new artist is

10
00:00:49,130 --> 00:00:55,200
read the current artist is gonna be saved in the
artists list and new artist objects

11
00:00:55,200 --> 00:01:00,660
is gonna be then created with the data in the current
row and we are gonna put all the code to populate

12
00:01:00,660 --> 00:01:05,129
the objects from the data file in a
function and that function will return a list

13
00:01:05,129 --> 00:01:11,570
of artists objects when we are finishing processing the
file so lets start by expanding the

14
00:01:11,570 --> 00:01:15,900
existing code that we got in our load data so we got this code we wrote

15
00:01:15,900 --> 00:01:23,920
in the previous video I'm gonna change
this a bit now actually what will do is change it

16
00:01:23,920 --> 00:01:28,960
a little bit lets just expanded and put some formatting in their so its easier to read so

17
00:01:28,960 --> 00:01:31,960
I'm going to add some formatting code.....

18
00:01:38,550 --> 00:02:25,600
....

19
00:02:25,600 --> 00:02:36,600
....and what that means

20
00:02:36,600 --> 00:02:42,460
at this point is that we just
read details for a new artist so we've just read

21
00:02:42,460 --> 00:02:51,250
details from new artist so what we want to do their is to store the current album in

22
00:02:51,250 --> 00:02:56,070
the current artist collection and create a new artist object so will just put our

23
00:02:56,070 --> 00:02:59,070
documentation.....

24
00:03:00,560 --> 00:03:03,880
....

25
00:03:05,030 --> 00:03:32,730
.....

26
00:03:32,730 --> 00:03:39,150
....

27
00:03:39,790 --> 00:03:45,230
....

28
00:03:45,230 --> 00:03:55,590
.....and then moving down here so we are going to do

29
00:03:55,590 --> 00:04:05,310
a test here....remembering the previous if was on line

30
00:04:05,310 --> 00:04:10,340
94 we are testing for artists we are not doing the test for album so....

31
00:04:10,340 --> 00:04:17,760
....

32
00:04:17,760 --> 00:04:33,860
.....

33
00:04:33,860 --> 00:04:44,830
....

34
00:04:44,830 --> 00:04:49,360
....just like before when we are reading details about a new artist in this case we've just read a

35
00:04:49,360 --> 00:04:54,750
new album for the current artists so....

36
00:04:54,750 --> 00:04:57,860
....

37
00:04:57,860 --> 00:05:07,020
....so we want to store the current album in

38
00:05:07,020 --> 00:05:15,910
the artist collection and then create a new
album object so....

39
00:05:15,910 --> 00:06:01,090
....

40
00:06:01,090 --> 00:06:06,440
...

41
00:06:06,440 --> 00:06:15,860
....

42
00:06:19,410 --> 00:06:39,910
....

43
00:06:39,910 --> 00:06:49,690
....ok so that is

44
00:06:49,690 --> 00:06:53,950
going through the entire code going
through the entire text file albums.txt

45
00:06:53,950 --> 00:07:00,160
which we started doing it or started the with open on line 87 so

46
00:07:00,160 --> 00:07:05,280
down here then what we want to do after
we finished reading the last line of

47
00:07:05,280 --> 00:07:09,010
that albums.txt text file then we're
gonna have an artist and an album that

48
00:07:09,010 --> 00:07:17,470
haven't been stored so we need to do
that now so...

49
00:07:17,470 --> 00:07:43,170
.....

50
00:07:44,920 --> 00:07:53,390
...

51
00:07:53,390 --> 00:08:12,490
....

52
00:08:13,750 --> 00:08:22,900
....

53
00:08:22,900 --> 00:08:41,929
.....

54
00:08:41,929 --> 00:08:48,480
....so we want the 4 to execute to go

55
00:08:48,480 --> 00:08:53,490
through the entire file then this code here is going to start executing after that

56
00:08:53,490 --> 00:08:57,560
4 is complete so its process the file and we are just processing the last line there

57
00:08:57,560 --> 00:09:02,620
that's fixed  that up and then returning as I
mentioned the artist list that we've

58
00:09:02,620 --> 00:09:08,030
created from this code from reading
in that file one thing to be aware of

59
00:09:08,030 --> 00:09:12,690
with this approach is that the objects
aren't stored in their collections until a new

60
00:09:12,690 --> 00:09:16,620
record is read from the file now for
example the current album is only added

61
00:09:16,620 --> 00:09:22,110
to the artists album list when a record
containing a different album is read that's

62
00:09:22,110 --> 00:09:26,210
just the way that we set this up to process
so ultimately what that means is the

63
00:09:26,210 --> 00:09:30,920
last set of data won't be stored and
that's why I've added this code from line 118

64
00:09:30,920 --> 00:09:36,320
down to process that lasted bit of code to
check if theirs a valid artist object on that

65
00:09:36,320 --> 00:09:40,760
last line adds that to the global list of artist and also adds the current album

66
00:09:40,760 --> 00:09:46,970
the last one read into the artists
list of albums so let's make a change so we just load data

67
00:09:46,970 --> 00:09:55,180
here so lets test to see whether this works
and we are going to do it differently we gonna put....

68
00:09:55,180 --> 00:10:04,890
...so we are gonna save the result the artist list that has
been returned and print out how many their is so...

69
00:10:04,890 --> 00:10:07,890
....

70
00:10:09,320 --> 00:10:19,480
....so lets running this and see what happens we can see it says

71
00:10:19,480 --> 00:10:24,050
there's twenty eight artist and that seems to
be working ok but how can we have be

72
00:10:24,050 --> 00:10:28,530
sure that it is well theirs a number of ways
we could validate the data contained

73
00:10:28,530 --> 00:10:32,760
in the artist the album the song objects
but this sort of checking is probably

74
00:10:32,760 --> 00:10:37,160
best left to the computer because the
ability to compare two or more files has

75
00:10:37,160 --> 00:10:40,780
been provided with most operating
systems for years but rather than using

76
00:10:40,780 --> 00:10:45,980
command-line tools we can do we can now
used the compare files feature

77
00:10:45,980 --> 00:10:50,120
of IntelliJ to do this comparison for us
much better to get the computer to be

78
00:10:50,120 --> 00:10:54,130
doing this sort of comparison checking
rather than using you

79
00:10:54,630 --> 00:10:58,640
know ourselves to do that so to achieve this all we
really have to do is use our objects to

80
00:10:58,640 --> 00:11:03,730
write a new file in the same format as the original and getting IntelliJ to check

81
00:11:03,730 --> 00:11:05,580
for differences

82
00:11:05,580 --> 00:11:10,290
so lets go and write a function to write the check file and
then we are gonna call it in the main program

83
00:11:10,290 --> 00:11:20,470
after we got this print out here so close that down and write that method will start down here...

84
00:11:20,470 --> 00:11:28,930
....so we define a file called...

85
00:11:28,930 --> 00:12:05,920
....

86
00:12:06,830 --> 00:12:31,350
....

87
00:12:31,350 --> 00:12:40,950
.....

88
00:12:40,950 --> 00:13:27,020
....

89
00:13:27,020 --> 00:13:32,890
....and that really should be all we
need to do to write that out and that should be in the same format as

90
00:13:32,890 --> 00:13:37,830
the original albums.txt files
because we've printed it out and with

91
00:13:37,830 --> 00:13:44,010
the relevant information separated by
tabs of course as the original file had so to

92
00:13:44,010 --> 00:13:51,330
test this we can then add a call after the print
here....

93
00:13:51,330 --> 00:14:03,460
.....so
let's just run that you can see there

94
00:14:03,460 --> 00:14:11,710
I made a mistake in 1.name and I got a bracket
there instead of a right brace....

95
00:14:12,510 --> 00:14:21,190
and run it again....ok we've now got a check file txt that's been
created so that's good we have just a quick

96
00:14:21,190 --> 00:14:25,070
look to see that it looks roughly the
same theirs the original albums.txt

97
00:14:25,070 --> 00:14:31,560
check file does seem to look pretty good
but lets end the video here and in the

98
00:14:31,560 --> 00:14:38,500
next video will start going through and we'll use IntelliJ compare files option to confirm

99
00:14:38,500 --> 00:14:41,150
that these files are identical so
let's do that in the next video

