19- Solution- Getting Many Quotes
Jul 04, 2026 01:27
· 4:49
· English
· Whisper Turbo
· 2 Đầu ghi
Bản ghi chép này hết hạn hôm nay.
Tăng cấp cho lưu trữ vĩnh viễn →
Chỉ hiển thị
0:01
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now that we have built this small piece of functionality,
0:04
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we can work on getting quotes from different websites.
0:07
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So back to our flight service class,
0:10
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we have the get quote method.
0:12
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now let's add a method called get quotes.
0:15
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So public,
0:16
S…
Speaker 1 (19- Solution- Getting Many Quotes)
what should be the return type of this method?
0:19
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We want to return a list of completable future of
0:23
S…
Speaker 1 (19- Solution- Getting Many Quotes)
quote.
0:23
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So list of completable
0:27
S…
Speaker 1 (19- Solution- Getting Many Quotes)
future of quote.
0:31
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Let's import the list class now we call this get quotes Now
0:36
S…
Speaker 1 (19- Solution- Getting Many Quotes)
this method should have the knowledge of the websites you want to query So
0:40
S…
Speaker 1 (19- Solution- Getting Many Quotes)
let's store them in a list of strings here.
0:44
S…
Speaker 1 (19- Solution- Getting Many Quotes)
I'm going to use list of and pass site one site
0:48
S…
Speaker 1 (19- Solution- Getting Many Quotes)
two and site three Now for
0:53
S…
Speaker 1 (19- Solution- Getting Many Quotes)
each site we should get a quote.
0:54
S…
Speaker 1 (19- Solution- Getting Many Quotes)
There are two ways to do this one way is to create a list of
0:58
S…
Speaker 1 (19- Solution- Getting Many Quotes)
completable future of quote then iterate over
1:02
S…
Speaker 1 (19- Solution- Getting Many Quotes)
these sites,
1:02
S…
Speaker 1 (19- Solution- Getting Many Quotes)
get each site for each site,
1:04
S…
Speaker 1 (19- Solution- Getting Many Quotes)
call the git quote method and then add the result to our list.
1:08
S…
Speaker 1 (19- Solution- Getting Many Quotes)
But there is a better way.
1:09
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We can use functional programming techniques.
1:11
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We can use the streams API.
1:12
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we're going to get a stream
1:16
S…
Speaker 1 (19- Solution- Getting Many Quotes)
from this list and then map each object or
1:21
S…
Speaker 1 (19- Solution- Getting Many Quotes)
each string to a completable future of quote.
1:24
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we get the site and here we call git quote
1:28
S…
Speaker 1 (19- Solution- Getting Many Quotes)
with that site.
1:31
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now, this lambda expression is simply calling a method so we can convert
1:35
S…
Speaker 1 (19- Solution- Getting Many Quotes)
it to a method reference.
1:37
S…
Speaker 1 (19- Solution- Getting Many Quotes)
That's better.
1:38
S…
Speaker 2 (19- Solution- Getting Many Quotes)
Now,
1:39
S…
Speaker 1 (19- Solution- Getting Many Quotes)
what is the return type of this map method?
1:41
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Take a look.
1:42
S…
Speaker 2 (19- Solution- Getting Many Quotes)
X,
1:43
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we press F1 here.
1:45
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So this returns a stream of completable future.
1:49
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So earlier we talked about intermediate and terminal operations in streams.
1:53
S…
Speaker 1 (19- Solution- Getting Many Quotes)
The map method is not going to execute anything.
1:56
S…
Speaker 1 (19- Solution- Getting Many Quotes)
It's just going to build a pipeline.
1:57
S…
Speaker 1 (19- Solution- Getting Many Quotes)
It's going to build a recipe for us.
1:59
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So eventually we need to collect the result into a list object.
2:03
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So here we call collect and pass collectors
2:08
S…
Speaker 1 (19- Solution- Getting Many Quotes)
dot to list.
2:09
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So this will return a list of completable futures and
2:14
S…
Speaker 1 (19- Solution- Getting Many Quotes)
then we'll return it
2:15
S…
Speaker 1 (19- Solution- Getting Many Quotes)
from this method.
2:16
S…
Speaker 2 (19- Solution- Getting Many Quotes)
Now,
2:17
S…
Speaker 1 (19- Solution- Getting Many Quotes)
let's test our new method.
2:19
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we go to our demo class.
2:21
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Instead of calling the get quote method,
2:24
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we're going to call get quotes.
2:27
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now this returns a list of completable features.
2:31
S…
Speaker 1 (19- Solution- Getting Many Quotes)
For each feature,
2:32
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we need to consume it and print its result,
2:35
S…
Speaker 1 (19- Solution- Getting Many Quotes)
which is the quote object.
2:36
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So once again,
2:37
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we can use the streams API here.
2:39
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We convert this list to a stream and
2:43
S…
Speaker 1 (19- Solution- Getting Many Quotes)
then we use the map method.
2:45
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So here we should pass a function that takes a completable future of quote
2:49
S…
Speaker 1 (19- Solution- Getting Many Quotes)
and return something else.
2:51
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we're going to take a future object and then
2:55
S…
Speaker 1 (19- Solution- Getting Many Quotes)
call then accept Now here we need to pass
2:59
S…
Speaker 1 (19- Solution- Getting Many Quotes)
a consumer of quote.
3:01
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So this is where we get the quote object and Print
3:05
S…
Speaker 1 (19- Solution- Getting Many Quotes)
it on a terminal.
3:06
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So once again,
3:07
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we can use a method reference quote double colon to string
3:13
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now, once again,
3:14
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we're building a processing pipeline,
3:15
S…
Speaker 1 (19- Solution- Getting Many Quotes)
so nothing is going to happen until we use a terminal operation.
3:19
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So here we can call collect,
3:21
S…
Speaker 1 (19- Solution- Getting Many Quotes)
and then collect the result into a list.
3:25
S…
Speaker 2 (19- Solution- Getting Many Quotes)
Now,
3:26
S…
Speaker 1 (19- Solution- Getting Many Quotes)
there is something redundant here.
3:27
S…
Speaker 1 (19- Solution- Getting Many Quotes)
In our flight service,
3:29
S…
Speaker 1 (19- Solution- Getting Many Quotes)
after we call the map method,
3:31
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we get a stream.
3:32
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We get that stream and then collect the result into a list.
3:35
S…
Speaker 2 (19- Solution- Getting Many Quotes)
Now,
3:36
S…
Speaker 1 (19- Solution- Getting Many Quotes)
in our demo class,
3:37
S…
Speaker 1 (19- Solution- Getting Many Quotes)
once again,
3:38
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we get that list and convert it back to a stream.
3:41
S…
Speaker 1 (19- Solution- Getting Many Quotes)
This is unnecessary.
3:43
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So in this method,
3:43
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we don't really need to collect the result into a list.
3:46
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Let's delete this line.
3:47
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now we should return a stream of,
3:51
S…
Speaker 1 (19- Solution- Getting Many Quotes)
let's import this,
3:54
S…
Speaker 1 (19- Solution- Getting Many Quotes)
a stream of completable future of quote.
3:57
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Okay.
3:57
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now we don't need this import statement either.
4:00
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Good.
4:01
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So our method is cleaner.
4:02
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We can't even put this on the same line.
4:05
S…
Speaker 2 (19- Solution- Getting Many Quotes)
Nice.
4:07
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Now back to our demo class.
4:08
S…
Speaker 1 (19- Solution- Getting Many Quotes)
We don't need to call the stream method anymore.
4:11
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we get the quotes.
4:14
S…
Speaker 1 (19- Solution- Getting Many Quotes)
This will give us a stream of future objects.
4:17
S…
Speaker 1 (19- Solution- Getting Many Quotes)
For each future object,
4:18
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we'll accept the result and print the code.
4:21
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Actually,
4:22
S…
Speaker 1 (19- Solution- Getting Many Quotes)
I made a mistake here.
4:23
S…
Speaker 1 (19- Solution- Getting Many Quotes)
Instead of calling quote the toString,
4:25
S…
Speaker 1 (19- Solution- Getting Many Quotes)
we should call the print line method.
4:27
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we should pass this quote object that we get to the print line method.
4:31
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So system .out double colon print line.
4:35
S…
Speaker 2 (19- Solution- Getting Many Quotes)
Now,
4:37
S…
Speaker 1 (19- Solution- Getting Many Quotes)
let's run our program and see what happens.
4:39
S…
Speaker 1 (19- Solution- Getting Many Quotes)
So we're querying all these websites
4:43
S…
Speaker 1 (19- Solution- Getting Many Quotes)
at the same time.
4:44
S…
Speaker 1 (19- Solution- Getting Many Quotes)
After three seconds, they all respond, beautiful.
Bản ghi này được tạo bởi AI (tự động nhận dạng giọng nói). Có thể chứa lỗi — kiểm tra với âm thanh gốc để sử dụng quan trọng. Chính sách AI
Tóm tắt
Nhấn tổng hợp để tạo một tóm tắt AI của bản ghi này.
Tóm tắt...
Hỏi AI về bản ghi này
Hỏi bất cứ điều gì về bản ghi chép này - AI sẽ tìm thấy các phần liên quan và trả lời.