InConstraintpublic class InConstraint extends ConstraintUtils implements ConstraintInConstraint is a {@link Constraint} to validate an Enumeration value.
It implements Constraint interface and extends
{@link ConstraintUtils} class.
match method of this object returns empty
Collection if the value being validated belongs to the
enumeration represented by this object; else it returns a
Collection with a {@link ConstraintFailure} object in it.
ConstraintUtils class provides utility methods for formating
failure messages and a print method to print this object. |
Fields Summary |
---|
private Collection | enumerationAn enumeration represented by this Constraint . |
Constructors Summary |
---|
public InConstraint()Creates a new instance of InConstraint .
enumeration = new ArrayList();
| public InConstraint(Collection enumeration)Creates a new instance of InConstraint .
this.enumeration = enumeration;
| public InConstraint(String[] enumeration)Creates a new instance of InConstraint .
this.enumeration = new ArrayList();
int size = enumeration.length;
for(int i=0; i<size; i++) {
this.enumeration.add(enumeration[i]);
}
|
Methods Summary |
---|
public java.util.Collection | match(java.lang.String value, java.lang.String name)Validates the given value against this Constraint .
Collection failed_constrained_list = new ArrayList();
if((value != null) && (value.length() != 0)) {
if(!enumeration.contains(value)){
String failureMessage = formatFailureMessage(toString(),
value, name);
String format = BundleReader.getValue(
"MSG_InConstraint_Failure"); //NOI18N
String set = ""; //NOI18N
Iterator iterator = enumeration.iterator();
String member;
while(iterator.hasNext()){
member = (String)iterator.next();
set = set + " " + member; //NOI18N
}
Object[] arguments = new Object[]{set};
String genericFailureMessage =
MessageFormat.format(format, arguments);
failed_constrained_list.add(new ConstraintFailure(toString(),
value, name, failureMessage, genericFailureMessage));
}
}
return failed_constrained_list;
| void | print()Prints this Constraint .
super.print();
String format = BundleReader.getValue("Name_Value_Pair_Format");//NOI18N
Iterator iterator = enumeration.iterator();
String values = "";
while(iterator.hasNext()){
values = values + " " + (String)iterator.next(); //NOI18N
}
if(values != null){
Object[] arguments =
new Object[]{"Enumeration Values", values}; //NOI18N
System.out.println(MessageFormat.format(format, arguments));
}
| public void | setEnumerationValue(java.util.Collection enumeration)Sets the given Collection as the enumeration
represented by this object.
this.enumeration = enumeration;
| public void | setEnumerationValue(java.lang.String value)Adds the given value to the enumeration
represented by this object.
enumeration.add(value);
|
|