org.springframework.rules.constraint
Class Required

java.lang.Object
  extended by org.springframework.rules.constraint.Required
All Implemented Interfaces:
Constraint, TypeResolvable

public class Required
extends Object
implements Constraint, TypeResolvable

Validates a required property. Required is defined as non-null and, if the object is a string, not empty and not blank. If the object is an instance of Collection, Map or an array it will test if it is empty.

Author:
Keith Donald, Mathias Broekelmann

Constructor Summary
Required()
          Default constructor which creates a required constraint by using the type required
Required(String type)
          Creates a required constraint by using a custom type.
 
Method Summary
 String getType()
          Returns this object's logical type identifier.
static Required instance()
          returns the required instance
static Required present()
          returns the present instance
 boolean test(Object argument)
          Tests if this argument is present (non-null, not-empty, not blank)
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Required

public Required(String type)
Creates a required constraint by using a custom type. This is primarly used to separate required and present constraint. These constraints where equaly implemented but where used differently

Parameters:
type - the type of the constraint. see getType()

Required

public Required()
Default constructor which creates a required constraint by using the type required

Method Detail

test

public boolean test(Object argument)
Tests if this argument is present (non-null, not-empty, not blank)

Specified by:
test in interface Constraint
Parameters:
argument - the argument value
Returns:
true if the condition was satisfied, false otherwise
See Also:
Constraint.test(java.lang.Object)

instance

public static Required instance()
returns the required instance

Returns:
the required instance (never null)

present

public static Required present()
returns the present instance

Returns:
the present instance (never null)

toString

public String toString()
Overrides:
toString in class Object

getType

public String getType()
Description copied from interface: TypeResolvable
Returns this object's logical type identifier.

Specified by:
getType in interface TypeResolvable
Returns:
The type identifier


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.