Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet194/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   190   191   192   193   194   195   196   197   ...   341
Bog'liq
Effective Java



ITEM 46: PREFER SIDE-EFFECT-FREE FUNCTIONS IN STREAMS
213
Note that the comparator uses the static factory method 
maxBy
, which is stati-
cally imported from 
BinaryOperator
. This method converts a 
Comparator
into a 
BinaryOperator
that computes the maximum implied by the specified
comparator. In this case, the comparator is returned by the comparator construc-
tion method 
comparing
, which takes the key extractor function 
Album::sales
.
This may seem a bit convoluted, but the code reads nicely. Loosely speaking, it
says, “convert the stream of albums to a map, mapping each artist to the album
that has the best album by sales.” This is surprisingly close to the problem state-
ment.
Another use of the three-argument form of 
toMap
is to produce a collector that
imposes a last-write-wins policy when there are collisions. For many streams, the
results will be nondeterministic, but if all the values that may be associated with a
key by the mapping functions are identical, or if they are all acceptable, this
collector’s s behavior may be just what you want:

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   190   191   192   193   194   195   196   197   ...   341




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish