Clean Code


} catch (ArgsException e) {



Download 3,58 Mb.
Pdf ko'rish
bet214/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   210   211   212   213   214   215   216   217   ...   384
Bog'liq
Clean Code

} catch (ArgsException e) {
valid = false;
errorArgumentId = argChar;
throw e;
}
return true;
}
private void setIntArg(
ArgumentMarshaler m
) throws ArgsException {
currentArgument++;
String parameter = null;
try {
parameter = args[currentArgument];
m
.set(parameter);
} catch (ArrayIndexOutOfBoundsException e) {
errorCode = ErrorCode.MISSING_INTEGER;
throw new ArgsException();
} catch (ArgsException e) {
errorParameter = parameter;
errorCode = ErrorCode.INVALID_INTEGER;
throw e;
}
}
private void setStringArg(
ArgumentMarshaler m
) throws ArgsException {
currentArgument++;
try {
m
.set(args[currentArgument]);
} catch (ArrayIndexOutOfBoundsException e) {
errorCode = ErrorCode.MISSING_STRING;
throw new ArgsException();
}
}


224
Chapter 14: Successive Refinement
I was close to being able to remove the three old maps. First, I needed to change the
getBoolean
function from this:
public boolean getBoolean(char arg) {
Args.ArgumentMarshaler am = booleanArgs.get(arg);
return am != null && (Boolean) am.get();
}
to this:
public boolean getBoolean(char arg) {
Args.ArgumentMarshaler am = marshalers.get(arg);
boolean b = false;
 try {
b = 
am != null && (Boolean) am.get();
} catch (ClassCastException e) {
b = false;
}
return b;
}
This last change might have been a surprise. Why did I suddenly decide to deal with
the
ClassCastException
? The reason is that I have a set of unit tests and a separate set of
acceptance tests written in FitNesse. It turns out that the FitNesse tests made sure that if
you called 
getBoolean
on a nonboolean argument, you got a 
false
. The unit tests did not.
Up to this point I had only been running the unit tests.
2
This last change allowed me to pull out another use of the 
boolean
map:
private void parseBooleanSchemaElement(char elementId) {
ArgumentMarshaler m = new BooleanArgumentMarshaler();

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   210   211   212   213   214   215   216   217   ...   384




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