1 00:00:00,660 --> 00:00:03,210 Okay quick, so I don't forget, watches. 2 00:00:03,210 --> 00:00:07,010 So you can create expressions that constantly stay bookmarked, so 3 00:00:07,010 --> 00:00:08,340 let's do that over here. 4 00:00:08,340 --> 00:00:12,070 Okay, so I'm gonna click our cardCounts variable that we determined up here, 5 00:00:12,070 --> 00:00:13,040 it was so important. 6 00:00:13,040 --> 00:00:17,610 And I'm gonna right click it, I'm going to choose Add to Watches and 7 00:00:17,610 --> 00:00:21,700 it adds a little glasses like on here with cardCounts. 8 00:00:21,700 --> 00:00:23,510 There's a way that you can make a separate panel. 9 00:00:23,510 --> 00:00:25,050 I like this version a little bit better. 10 00:00:25,050 --> 00:00:26,940 They made it so that you can have more space but 11 00:00:26,940 --> 00:00:29,445 I'm gonna click this and now you'll see that there are separate, 12 00:00:29,445 --> 00:00:31,730 you got Variables and Watches as two separate things. 13 00:00:32,930 --> 00:00:36,540 One of my favorite things about these watches is that they stick across frames. 14 00:00:36,540 --> 00:00:38,850 So for instance, we're basically done with our current frame right? 15 00:00:38,850 --> 00:00:42,840 We're gonna return this value and the frame is gonna be popped from the stack. 16 00:00:42,840 --> 00:00:43,340 Are we ready? 17 00:00:45,277 --> 00:00:47,420 Boom, and now we're back where we started. 18 00:00:47,420 --> 00:00:49,600 Now notice our current execution point, 19 00:00:49,600 --> 00:00:54,010 we haven't set the cardCounts variable yet and that's why this right here can't find 20 00:00:54,010 --> 00:00:56,478 the local variable cardCounts because it doesn't exist yet, 21 00:00:56,478 --> 00:01:01,530 so I'm gonna go ahead and step over and now that it exists, look it's stuck there. 22 00:01:01,530 --> 00:01:04,860 So we can see know that there is the cardCounts value here and 23 00:01:04,860 --> 00:01:07,630 it's the cardCounts values here as well but it's also showing over in our 24 00:01:07,630 --> 00:01:09,890 Watches because we're remembering that that's what we wanna watch. 25 00:01:09,890 --> 00:01:13,340 There could be tons of variables there but one thing I wanna point out is that 26 00:01:13,340 --> 00:01:16,780 the reason why this is working is because the name is the same, okay? 27 00:01:16,780 --> 00:01:20,840 So we're watching an expression called cardCounts. 28 00:01:20,840 --> 00:01:24,782 Okay, so let's step in to our next method here which is getNextFlashCardBasedOnViews 29 00:01:24,782 --> 00:01:27,940 and we're gonna pass in the object reference cardCounts. 30 00:01:27,940 --> 00:01:28,680 Okay, so here we go. 31 00:01:28,680 --> 00:01:30,945 So we'll step in and here, uh-oh, 32 00:01:30,945 --> 00:01:35,180 it says cardCounts can't find the local variable cardCounts. 33 00:01:35,180 --> 00:01:37,460 And that's because it's been changed. 34 00:01:37,460 --> 00:01:41,680 It's called idToViewCounts, it's more specific, okay? 35 00:01:41,680 --> 00:01:43,480 So, well, that actually helps a little bit, right? 36 00:01:43,480 --> 00:01:44,800 So that's helping me understand what this is. 37 00:01:44,800 --> 00:01:47,310 So its id must be the key and 38 00:01:47,310 --> 00:01:50,500 the value must be how many times a card's been viewed. 39 00:01:50,500 --> 00:01:52,600 That's my current assumption at least. 40 00:01:52,600 --> 00:01:53,240 So what now though? 41 00:01:53,240 --> 00:01:56,450 Our watch isn't picking up this value in the current frame. 42 00:01:56,450 --> 00:01:59,317 Now I could, of course, add another watch super easily, right? 43 00:01:59,317 --> 00:02:03,198 Like I could just right click that, choose Add to Watches, it's there, and 44 00:02:03,198 --> 00:02:06,659 then if I switch between the frames here, when I'm looking at this, 45 00:02:06,659 --> 00:02:09,942 this one can't find the variable and when I look at the other one, 46 00:02:09,942 --> 00:02:13,610 it can't find the cardCounts, fixes the problem more or less, right? 47 00:02:13,610 --> 00:02:17,290 That's probably enough for most situations, but there's a pretty nice work 48 00:02:17,290 --> 00:02:21,130 around that we can use if you don't mind going on a slight detour with me. 49 00:02:21,130 --> 00:02:22,900 Okay, so there's a trick, right? 50 00:02:22,900 --> 00:02:26,190 It's possible that you can label or mark objects. 51 00:02:26,190 --> 00:02:28,390 So the usage of labeling is for various reasons. 52 00:02:28,390 --> 00:02:30,250 Maybe we don't like the way a variable's named or 53 00:02:30,250 --> 00:02:33,700 we want to add specific metadata about that object specifically. 54 00:02:33,700 --> 00:02:38,520 Or in our case, we want to see when it's pointing to the same object. 55 00:02:38,520 --> 00:02:40,250 So when you mark an object, 56 00:02:40,250 --> 00:02:44,030 you're marking the object, not the name, not the expression of it. 57 00:02:44,030 --> 00:02:45,520 Okay, so we can do that. 58 00:02:45,520 --> 00:02:50,160 So let's, you right-click and choose Mark Object and you choose a Label. 59 00:02:50,160 --> 00:02:51,950 Now, we know what we're talking about, right? 60 00:02:51,950 --> 00:02:54,710 We know it's cardCounts and we know that it's this idToViewCounts. 61 00:02:54,710 --> 00:02:58,140 So let's call it counts because that's what we wanna see. 62 00:02:58,140 --> 00:03:00,010 So now, see when I go back and 63 00:03:00,010 --> 00:03:02,820 forth between the frames, the counts sticks, right? 64 00:03:02,820 --> 00:03:04,290 So the counts is labelled there. 65 00:03:05,510 --> 00:03:07,830 It's also labelled in our watch over here. 66 00:03:09,390 --> 00:03:10,630 See that? 67 00:03:10,630 --> 00:03:13,470 So the awesome trick is that you can actually watch 68 00:03:13,470 --> 00:03:15,340 a label not the variable name. 69 00:03:15,340 --> 00:03:17,170 You can make it be an expression, right? 70 00:03:17,170 --> 00:03:19,030 So let's go ahead, let's remove our watches, you can do that, 71 00:03:19,030 --> 00:03:20,860 you can press backspace or 72 00:03:20,860 --> 00:03:26,510 down here, underneath this, you can press the minus key. 73 00:03:26,510 --> 00:03:28,980 All right, so we're gonna add a new watch and 74 00:03:28,980 --> 00:03:31,340 watches can basically be any expression. 75 00:03:31,340 --> 00:03:33,540 So, I'm gonna say counts and 76 00:03:33,540 --> 00:03:36,250 then IntelliJ was nice enough to expose them. 77 00:03:36,250 --> 00:03:38,630 So, I can say DebugLabel, right? 78 00:03:38,630 --> 00:03:41,370 And if I press Enter, now it's watching counts. 79 00:03:41,370 --> 00:03:43,900 So anything that counts it, so I'm both, 80 00:03:43,900 --> 00:03:48,310 there's one watch across multiple variables and it's using this count. 81 00:03:48,310 --> 00:03:49,540 Cool, right? 82 00:03:49,540 --> 00:03:52,790 The fact that you can add any sort of expression there is super powerful, 83 00:03:52,790 --> 00:03:54,260 you can put whatever in there and 84 00:03:54,260 --> 00:03:57,940 it will keep evaluating kind of like a spreadsheet cell. 85 00:03:57,940 --> 00:04:00,690 So back to our originally scheduled program. 86 00:04:00,690 --> 00:04:03,698 So we're just about ready to call this method, right, 87 00:04:03,698 --> 00:04:07,346 this method is getNextUnseenFlashCard and we're gonna pass in our 88 00:04:07,346 --> 00:04:11,640 idToViewCounts.keyset which at the moment remember that was empty, right? 89 00:04:11,640 --> 00:04:12,540 We're looking down here. 90 00:04:12,540 --> 00:04:14,320 This counts object is empty. 91 00:04:14,320 --> 00:04:17,489 So there are no keys, so it's going to return an empty set. 92 00:04:17,489 --> 00:04:22,480 So what's gonna happen, terminology wise, when I step into this method call? 93 00:04:22,480 --> 00:04:23,620 Can you recall the terms? 94 00:04:23,620 --> 00:04:25,180 What's gonna happen? 95 00:04:25,180 --> 00:04:29,760 That's right, it's going to push a new frame onto the stack for 96 00:04:29,760 --> 00:04:32,100 this specific method call. 97 00:04:32,100 --> 00:04:33,860 Okay, so yeah look at this. 98 00:04:33,860 --> 00:04:38,630 The parameter name is seenIds and we've passed in the keys of that ID to count. 99 00:04:38,630 --> 00:04:43,680 So I'm fairly certain that my assumption was correct, our counts label here is 100 00:04:43,680 --> 00:04:49,480 a map of IDs to the number of times that things were viewed, cool. 101 00:04:49,480 --> 00:04:51,260 So let's walk this logic. 102 00:04:51,260 --> 00:04:55,411 Okay, so there's no IDs at all yet as we haven't seen anything, 103 00:04:55,411 --> 00:04:58,228 it just returns a list of all of them, 104 00:04:58,228 --> 00:05:03,470 right, so yup, there's no seen so it's gonna turn all of them. 105 00:05:03,470 --> 00:05:05,330 So unseen here should be every card, right? 106 00:05:05,330 --> 00:05:06,430 Remember there's 8 cards. 107 00:05:07,920 --> 00:05:11,200 Okay, and since there is no unseen, we're gonna go ahead and 108 00:05:11,200 --> 00:05:13,690 come in here and it's gonna pull out a random card. 109 00:05:13,690 --> 00:05:15,630 So I can just go ahead and like we saw before, 110 00:05:15,630 --> 00:05:19,920 I can highlight this and we'll see that it's gonna pull out a number, right? 111 00:05:19,920 --> 00:05:24,528 It's gonna pull out an index between zero and whatever the number is. 112 00:05:24,528 --> 00:05:29,370 So if I do this, if I highlight all this, this should give us a random card. 113 00:05:31,330 --> 00:05:33,600 Yeah, so there so I ran that expression and 114 00:05:33,600 --> 00:05:37,030 pulled out a random card, pulled randomly the first time of all that you're gonna 115 00:05:37,030 --> 00:05:40,530 need because it created a new random and it was somewhere in between zero and 116 00:05:40,530 --> 00:05:43,870 the top of the array, so that's how you pull something random, cool. 117 00:05:43,870 --> 00:05:46,586 So I'm gonna step over to that, and 118 00:05:46,586 --> 00:05:51,520 the card that we got pulled out is Java EE Enterprise Edition. 119 00:05:51,520 --> 00:05:53,130 Okay, so that card got pulled out. 120 00:05:54,360 --> 00:05:56,731 So now our frame is gonna pop off the stack and 121 00:05:56,731 --> 00:06:02,670 it's gonna return to the getNextFlashCardBasedOnViews. 122 00:06:02,670 --> 00:06:06,630 Since we have one, I'm sorry getNextUnseenFlashCards, so 123 00:06:06,630 --> 00:06:09,680 there was one that was unseen, so we're gonna make sure that we show that. 124 00:06:11,110 --> 00:06:17,160 So that returns a card and that pops off and we're in the last one here, 125 00:06:17,160 --> 00:06:21,230 and so we do have a card and we're gonna return redirect link. 126 00:06:21,230 --> 00:06:24,730 And if you accidentally click step over like I did right there, 127 00:06:24,730 --> 00:06:28,630 you'll be dropped into the magic of what's going on. 128 00:06:28,630 --> 00:06:33,550 It will give you some great experience in how amazing 129 00:06:33,550 --> 00:06:36,720 this open source stuff is that we're using because of all this code that's right 130 00:06:36,720 --> 00:06:39,080 there no matter what we're thinking about but if you don't want to sit there and 131 00:06:39,080 --> 00:06:41,690 spend the time walking through it, you just press this Continue button. 132 00:06:42,840 --> 00:06:45,440 Now if we look back over, we'll see our Java EE. 133 00:06:46,810 --> 00:06:50,190 So let's just finish the flow once through just to feel a sense of accomplishment. 134 00:06:50,190 --> 00:06:52,150 Okay, so let's see what happens. 135 00:06:52,150 --> 00:06:57,900 So it generated flash card ID which is mapped here so 136 00:06:57,900 --> 00:07:01,190 let's drop this, we're gonna go ahead and call next. 137 00:07:03,620 --> 00:07:08,359 And here we are we're stopped and now we'll see that our counts has a size of 1 138 00:07:08,359 --> 00:07:13,550 and 5, I'm assuming must be the ID of the Java EE, 139 00:07:13,550 --> 00:07:18,070 right, so it's calling getCardCounts, right, 140 00:07:18,070 --> 00:07:21,610 cuz we have a breakpoint in our getCardCounts up here. 141 00:07:21,610 --> 00:07:25,359 So it's calling that and it's gonna get it out of the session. 142 00:07:28,691 --> 00:07:33,420 Cool, so Java EE has been seen once, right? 143 00:07:33,420 --> 00:07:35,675 And so we're gonna return the card counts. 144 00:07:35,675 --> 00:07:37,345 Step over that. 145 00:07:37,345 --> 00:07:39,109 Okay, so what is this doing? 146 00:07:39,109 --> 00:07:44,355 This is Java 8 new map compute function, okay? 147 00:07:44,355 --> 00:07:48,785 So what that does is it takes a key and a remapping function. 148 00:07:48,785 --> 00:07:52,245 So let's suppose that we wanted to break into this lambda right here to see 149 00:07:52,245 --> 00:07:56,010 actually what is this doing so I'm going to click right here. 150 00:07:56,010 --> 00:07:59,803 And you'll see that I get a choice between the lambda and 151 00:07:59,803 --> 00:08:03,113 the line itself, so I'm gonna use the lambda and 152 00:08:03,113 --> 00:08:07,489 I'm gonna click the run and now we're actually in here, okay? 153 00:08:07,489 --> 00:08:12,481 So we're here, so the key, I got passed in is 4 which must be the new card that 154 00:08:12,481 --> 00:08:18,070 we're looking at, must have the id 4 and it hasn't been seen yet before. 155 00:08:18,070 --> 00:08:22,110 Okay, so what it's gonna do is, it's gonna say, if it is null, which it is, 156 00:08:22,110 --> 00:08:23,170 it's gonna be 1. 157 00:08:23,170 --> 00:08:25,510 Otherwise, it's gonna increment, cool. 158 00:08:25,510 --> 00:08:30,244 So it will increment if it exists, and then if we continue out of this, 159 00:08:30,244 --> 00:08:33,857 we'll see that the card gets pushed in the template so 160 00:08:33,857 --> 00:08:37,015 the second was Java SE and it was seen one time. 161 00:08:39,488 --> 00:08:44,382 Awesome, and let's click Next one more time and we'll see that our cardCount 162 00:08:44,382 --> 00:08:49,830 has now has 4 which is that idea we saw and 5 and they both have view at one time. 163 00:08:49,830 --> 00:08:51,230 Cool, all right. 164 00:08:51,230 --> 00:08:54,720 So now that we've got the basic idea for the flow, let's take a quick break. 165 00:08:54,720 --> 00:08:57,320 I'm gonna go jog around my yard real quick and get my brain working. 166 00:08:57,320 --> 00:09:01,140 I find it's good to take breaks and let all that we just learned about the way 167 00:09:01,140 --> 00:09:04,090 that our app is working kind of work its way into our brains. 168 00:09:04,090 --> 00:09:07,100 Then when we're refreshed, let's go grab another one of those issues.