Let's say you were given the requirement "ensure that all five lines of a shipping address contains valid characters." How do you suppose you would go about implementing such a requirement? Let's hope your solution would be far, far away from Buri's coworker's implementation which not only has a separate function for each address but manages to have an astonishingly unique method of testing for bad characters ...
/** Valid signs */
private char [] validSign =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '.', ',', '\'', '-', '/', '&', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '!', '\"', '$', '%', '(', ')', '*', '+', ':', ';', '=', '?',
'ü', 'é', 'â', 'ä', 'à', 'ç', 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'ß', 'ô', 'ö', 'ò',
'û', 'ù', 'ß', 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'Ä', 'Ö', 'Ü', '#',
'å', 'ÿ', 'ý', 'Á', 'Â', 'À', 'Å', 'Ç', 'É', 'Ê', 'Ë', 'È', 'Í', 'Î',
'Ï', 'Ì', 'Ó', 'Ô', 'Ò', 'Ú', 'Û', 'Ù', 'Ý'
};
private int validateshippingaddress1( StringBuffer vsadr1 )
throws Exception
{
int validSignCount = validSign.length;
int vsadr1Count;
String vsadr1Test;
if( vsadr1 != null )
{
vsadr1Test = vsadr1.toString();
vsadr1Count = vsadr1Test.length();
for( int i = 0; i < validSignCount; i++ )
{
vsadr1Test = vsadr1Test.replace( validSign[ i ], ' ' );
}
for( int i = 0; i < vsadr1Count; i++ )
{
if( vsadr1Test.charAt( i ) != ' ' )
{
throw new VerificationException(
"Vsadr1 with invalid sign",
VerificationException.VSADR1_INVALID_SIGN );
}
}
return 1;
}
else
{
return 0;
}
}
private int validateshippingaddress2( StringBuffer vsadr2 )
throws Exception
{
int validSignCount = validSign.length;
int vsadr2Count;
String vsadr2Test;
if( vsadr2 != null )
{
vsadr2Test = vsadr2.toString( );
vsadr2Count = vsadr2Test.length( );
for( int i = 0; i < validSignCount; i++ )
{
vsadr2Test = vsadr2Test.replace( validSign[ i ], ' ' );
}
for( int i = 0; i < vsadr2Count; i++ )
{
if( vsadr2Test.charAt( i ) != ' ' )
{
throw new VerificationException(
"Vsadr2 with invalid sign",
VerificationException.VSADR2_INVALID_SIGN );
}
}
return 1;
}
else
{
return 0;
}
}
/* ED: Snip */
private int validateshippingaddress5( StringBuffer vsadr5 )
throws Exception
{
int validSignCount = validSign.length;
int vsadr5Count;
String vsadr5Test;
if( vsadr5 != null )
{
vsadr5Test = vsadr5.toString( );
vsadr5Count = vsadr5Test.length( );
for( int i = 0; i < validSignCount; i++ )
{
vsadr5Test = vsadr5Test.replace( validSign[ i ], ' ' );
}
for( int i = 0; i < vsadr5Count; i++ )
{
if( vsadr5Test.charAt( i ) != ' ' )
{
throw new VerificationException(
"Vsadr5 with invalid sign",
VerificationException.VSADR5_INVALID_SIGN );
}
}
return 1;
}
else
{
return 0;
}
}