StringValidatorpublic class StringValidator extends BaseValidator Class for validating String method parameters. Current implementation's
stock object (getInstance()) verifies that the String exists and has length > 0 |
Fields Summary |
---|
private final int | mMininumLength | private static final int | kDefaultMinimumLength | private static final StringValidator | sDefaultInstance | private static final String | badArgMessage |
Constructors Summary |
---|
public StringValidator(int minimumLength)Create a StringValidator
Assert.assertRange(minimumLength, 0, Integer.MAX_VALUE, "minimumLength");
mMininumLength = minimumLength;
|
Methods Summary |
---|
public static Validator | getInstance()Get the standard StringValidator
return sDefaultInstance;
| private ValidatorResult | makeBadResult(int len)
return new ValidatorResult(false,
"The String argument is invalid. The minimum required length is " +
mMininumLength + " and the String's actual length is " + len);
| public ValidatorResult | validate(java.lang.Object obj)Validate a String
ValidatorResult result = super.validate(obj);
if (result.isValid())
{
Assert.assertit( (obj instanceof String), badArgMessage);
final String str = (String)obj;
final int len = str.length();
if(len < mMininumLength)
{
result = makeBadResult(len);
}
}
return result;
|
|