org.databene.commons.validator
Class StringLengthValidator

java.lang.Object
  extended by org.databene.commons.validator.StringLengthValidator
All Implemented Interfaces:
Validator<java.lang.String>
Direct Known Subclasses:
StringValidator

public class StringLengthValidator
extends java.lang.Object
implements Validator<java.lang.String>

Validates a String for a minimum and a maximum length.

Created: 20.09.2006 21:38:20

Author:
Volker Bergmann

Constructor Summary
StringLengthValidator()
          Creates a validator that accepts any string
StringLengthValidator(int maxLength)
          Creates a validator of a maximum length
StringLengthValidator(int minLength, java.lang.Integer maxLength)
          Creates a validator of a minimum and maximum length
StringLengthValidator(int minLength, java.lang.Integer maxLength, boolean nullAllowed)
           
 
Method Summary
 java.lang.Integer getMaxLength()
          Returns the maximum length.
 int getMinLength()
          Returns the minimum length.
 boolean isNullAllowed()
           
 void setMaxLength(java.lang.Integer maxLength)
          Sets the maximum length.
 void setMinLength(int minLength)
          Sets the minimum length.
 java.lang.String toString()
           
 boolean valid(java.lang.String text)
          Checks if an object is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringLengthValidator

public StringLengthValidator()
Creates a validator that accepts any string


StringLengthValidator

public StringLengthValidator(int maxLength)
Creates a validator of a maximum length


StringLengthValidator

public StringLengthValidator(int minLength,
                             java.lang.Integer maxLength)
Creates a validator of a minimum and maximum length


StringLengthValidator

public StringLengthValidator(int minLength,
                             java.lang.Integer maxLength,
                             boolean nullAllowed)
Method Detail

getMinLength

public int getMinLength()
Returns the minimum length.

Returns:
the minimum length.
See Also:
minLength

setMinLength

public void setMinLength(int minLength)
Sets the minimum length.

Parameters:
minLength - the new minimum length

getMaxLength

public java.lang.Integer getMaxLength()
Returns the maximum length.

Returns:
the maximum length.
See Also:
maxLength

setMaxLength

public void setMaxLength(java.lang.Integer maxLength)
Sets the maximum length. If set to null, no maximum length check is done.

Parameters:
maxLength - the new minimum length

isNullAllowed

public boolean isNullAllowed()

valid

public boolean valid(java.lang.String text)
Description copied from interface: Validator
Checks if an object is valid.

Specified by:
valid in interface Validator<java.lang.String>
Parameters:
text - the string to validate
Returns:
true if the length restrictions match, otherwise false.
See Also:
Validator

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.