Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet159/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   155   156   157   158   159   160   161   162   ...   341
Bog'liq
Effective Java



ITEM 37: USE ENUMMAP INSTEAD OF ORDINAL INDEXING
175
the transitions by source phase, and the second creates an 
EnumMap
with mappings
from destination phase to transition. The merge function in the second collector
(
(x,
y)
->
y)
) is unused; it is required only because we need to specify a map fac-
tory in order to get an 
EnumMap
, and 
Collectors
provides telescoping factories.
The previous edition of this book used explicit iteration to initialize the phase
transition map. The code was more verbose but arguably easier to understand.
Now suppose you want to add a new phase to the system: 
plasma
, or ionized
gas. There are only two transitions associated with this phase: 
ionization
, which
takes a gas to a plasma; and 
deionization
, which takes a plasma to a gas. To update
the array-based program, you would have to add one new constant to 
Phase
and
two to 
Phase.Transition
, and replace the original nine-element array of arrays
with a new sixteen-element version. If you add too many or too few elements to
the array or place an element out of order, you are out of luck: the program will
compile, but it will fail at runtime. To update the 
EnumMap
-based version, all you
have to do is add 
PLASMA
to the list of phases, and 
IONIZE(GAS,
PLASMA)
and
DEIONIZE(PLASMA,
GAS)
to the list of phase transitions:

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   155   156   157   158   159   160   161   162   ...   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