org.jutil.predicate
Class TypePredicate

java.lang.Object
  |
  +--org.jutil.predicate.AbstractPredicate
        |
        +--org.jutil.predicate.TotalPredicate
              |
              +--org.jutil.predicate.PrimitiveTotalPredicate
                    |
                    +--org.jutil.predicate.TypePredicate
All Implemented Interfaces:
CollectionOperator, Predicate

public class TypePredicate
extends PrimitiveTotalPredicate

A class of predicate that check whether or not an object conforms to a certain type.

This class is typically used as follows:


 TotalPredicate predicate = new TypePredicate(MyClass.class);
 

When a TypePredicate is used as a constant in an interface, the .class operator will return null, so in that case you must pass the name of the class as a String:


 TotalPredicate predicate = new TypePredicate("mypackage.MyClass");
 


Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
TypePredicate(java.lang.Class type)
          Initialize a new TypePredicate that check whether or not objects are from a give type.
TypePredicate(java.lang.String name)
          Initialize a new TypePredicate based on the type with the given name.
 
Method Summary
 boolean eval(java.lang.Object object)
          Evaluate this Predicate for the given object.
 java.lang.Class getType()
          Return the type of this TypePredicate.
 
Methods inherited from class org.jutil.predicate.PrimitiveTotalPredicate
getSubPredicates, nbSubPredicates
 
Methods inherited from class org.jutil.predicate.TotalPredicate
count, exists, filter, forall, isValidElement
 
Methods inherited from class org.jutil.predicate.AbstractPredicate
equals
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

TypePredicate

public TypePredicate(java.lang.Class type)

Initialize a new TypePredicate that check whether or not objects are from a give type.

Parameters:
type - The type.

Specifications:
public behavior
requires type != null;
ensures getType() == type;

TypePredicate

public TypePredicate(java.lang.String name)
              throws java.lang.LinkageError,
                     java.lang.ExceptionInInitializerError,
                     java.lang.IllegalArgumentException

Initialize a new TypePredicate based on the type with the given name.

Parameters:
name - The name of the type.

Specifications:
public behavior
requires name != null;
requires (* <name> must be a valid classname *);
ensures getType() == Class.forName(name);
signals (LinkageError) (* something went wrong *);
signals (ExceptionInInitializerError) (* something went wrong *);
signals (IllegalArgumentException) (* Illegal Class Name *);
Method Detail

getType

public java.lang.Class getType()
Return the type of this TypePredicate.

Specifications:
public behavior
ensures \result != null;

eval

public boolean eval(java.lang.Object object)
Description copied from interface: Predicate
Evaluate this Predicate for the given object.

Specifications:
     also
public behavior
ensures \result == getType().isInstance(object);

Specifications inherited from overridden method in class TotalPredicate:
     also
public behavior
signals (Exception) false;
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures \result == true|\result == false;
signals (Exception) !isValidElement(object);