edu.rice.cs.cunit.threadCheck.subAnnot
Class Predicates

java.lang.Object
  extended by edu.rice.cs.cunit.threadCheck.subAnnot.Predicates

public class Predicates
extends java.lang.Object

Class containing several common predicates.

Author:
Mathias Ricken

Constructor Summary
Predicates()
           
 
Method Summary
static boolean checkAnd(java.lang.Object thisObject, java.lang.Object[] methodArgs, InvariantAnnotation[] value)
          Return false if one or more of the annotations in the array returned false.
static boolean checkDistinctArguments(java.lang.Object thisObject, java.lang.Object[] args, int[] value)
          Return true if the object with the specified indices are all distinct.
static boolean checkEventThread(java.lang.Object thisObject)
          Return true if the current thread is the event thread.
static boolean checkEventThreadAfterRealized(java.lang.Object thisObject)
          Return true if the current thread is the event thread, or if thisObject is an instance of a subclass of java.awt.Component and that component has not been realized yet.
static boolean checkGroup(java.lang.Object thisObject, java.lang.String value, boolean regex)
          Return true if the current thread's group equals the specified string
static boolean checkImplies(java.lang.Object thisObject, java.lang.Object[] methodArgs, InvariantAnnotation[] value)
          Return true if A -> B is true, where A is the first annotation and B is the second.
static boolean checkMonitorOwned(java.lang.Object o)
          Return true if the any thread owns the monitor of the object.
static boolean checkName(java.lang.Object thisObject, java.lang.String value, boolean regex)
          Return true if the current thread's name equals the specified string
static boolean checkNot(java.lang.Object thisObject, java.lang.Object[] methodArgs, InvariantAnnotation value)
          Return true if the annotations in the array returned false, and vice versa.
static boolean checkNullArgument(java.lang.Object thisObject, java.lang.Object[] args, int value)
          Return true if the object with index value in the array of method arguments is null.
static boolean checkNumberBoundedArgument(java.lang.Object thisObject, java.lang.Object[] args, NumberBoundedArgument.Mode mode, int index, double bound, double upperBound)
          Return true if the object with the specified index is a Number and meeds the bounds.
static boolean checkOr(java.lang.Object thisObject, java.lang.Object[] methodArgs, InvariantAnnotation[] value)
          Return true if one or more of the annotations in the array returned true.
static boolean checkSameArguments(java.lang.Object thisObject, java.lang.Object[] args, int[] value)
          Return true if the object with the specified indices are all the same.
static boolean checkSynchronizedArgument(java.lang.Object thisObject, java.lang.Object[] args, int value)
          Return true if the any thread owns the monitor of the object with index value in the array of method arguments
static boolean checkSynchronizedField(java.lang.Object thisObject, java.lang.Class fieldClass, java.lang.String fieldName)
          Return true if the any thread owns the monitor of the specified field.
static boolean checkSynchronizedFieldByName(java.lang.Object thisObject, java.lang.String fieldClassName, java.lang.String fieldName)
          Return true if any thread owns the monitor of the specified field.
static boolean checkThread(java.lang.Object thisObject, java.lang.Class fieldClass, java.lang.String fieldName)
          Return true if the current thread is equal to the thread in the specified field.
static boolean checkThreadByName(java.lang.Object thisObject, java.lang.String fieldClassName, java.lang.String fieldName)
          Return true if the current thread is equal to the thread in the specified field.
static boolean checkXOr(java.lang.Object thisObject, java.lang.Object[] methodArgs, InvariantAnnotation[] value)
          Return true if exactly one of the annotations in the array returned true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Predicates

public Predicates()
Method Detail

checkOr

public static boolean checkOr(java.lang.Object thisObject,
                              java.lang.Object[] methodArgs,
                              InvariantAnnotation[] value)
Return true if one or more of the annotations in the array returned true.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
methodArgs - array with method arguments
value - array of invariant annotations
Returns:
true if one or more of the annotations returned true

checkAnd

public static boolean checkAnd(java.lang.Object thisObject,
                               java.lang.Object[] methodArgs,
                               InvariantAnnotation[] value)
Return false if one or more of the annotations in the array returned false.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
methodArgs - array with method arguments
value - array of invariant annotations
Returns:
falseif one or more of the annotations returned false

checkXOr

public static boolean checkXOr(java.lang.Object thisObject,
                               java.lang.Object[] methodArgs,
                               InvariantAnnotation[] value)
Return true if exactly one of the annotations in the array returned true.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
methodArgs - array with method arguments
value - array of invariant annotations
Returns:
true if exactly one of the annotations returned true

checkNot

public static boolean checkNot(java.lang.Object thisObject,
                               java.lang.Object[] methodArgs,
                               InvariantAnnotation value)
Return true if the annotations in the array returned false, and vice versa.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
methodArgs - array with method arguments
value - invariant annotation
Returns:
true if the annotation returned false, and vice versa

checkImplies

public static boolean checkImplies(java.lang.Object thisObject,
                                   java.lang.Object[] methodArgs,
                                   InvariantAnnotation[] value)
Return true if A -> B is true, where A is the first annotation and B is the second.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
methodArgs - array with method arguments
value - array of invariant annotations; must be of length two
Returns:
true if A -> B is true

checkName

public static boolean checkName(java.lang.Object thisObject,
                                java.lang.String value,
                                boolean regex)
Return true if the current thread's name equals the specified string

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
value - string to compare the current thread's name to
regex - true if value should be treated as a regular expression
Returns:
true if the current thread's name equals the specified string

checkGroup

public static boolean checkGroup(java.lang.Object thisObject,
                                 java.lang.String value,
                                 boolean regex)
Return true if the current thread's group equals the specified string

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
value - string to compare the current thread's group to
regex - true if value should be treated as a regular expression
Returns:
true if the current thread's group equals the specified string

checkSynchronizedArgument

public static boolean checkSynchronizedArgument(java.lang.Object thisObject,
                                                java.lang.Object[] args,
                                                int value)
Return true if the any thread owns the monitor of the object with index value in the array of method arguments

Parameters:
thisObject - object that represents "this", or null if static
args - array of method arguments
value - index of the method argument that should be checked
Returns:
true if the any thread owns the monitor of the argument (false if value is out of range)

checkMonitorOwned

public static boolean checkMonitorOwned(java.lang.Object o)
Return true if the any thread owns the monitor of the object. If this method is directly used in a predicate annotation, then the object passed is "this".

Parameters:
o - object whose monitor should be checked; must be non-null
Returns:
true if the any thread owns the monitor (false if o is null)

checkSynchronizedField

public static boolean checkSynchronizedField(java.lang.Object thisObject,
                                             java.lang.Class fieldClass,
                                             java.lang.String fieldName)
Return true if the any thread owns the monitor of the specified field.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
fieldClass - the class the field is in
fieldName - the name of the field
Returns:
true if the any thread owns the monitor of the specified field

checkSynchronizedFieldByName

public static boolean checkSynchronizedFieldByName(java.lang.Object thisObject,
                                                   java.lang.String fieldClassName,
                                                   java.lang.String fieldName)
Return true if any thread owns the monitor of the specified field.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
fieldClassName - the name of the class the field is in
fieldName - the name of the field
Returns:
true if any thread owns the monitor of the specified field

checkEventThread

public static boolean checkEventThread(java.lang.Object thisObject)
Return true if the current thread is the event thread.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
Returns:
true if the current thread is the event thread

checkEventThreadAfterRealized

public static boolean checkEventThreadAfterRealized(java.lang.Object thisObject)
Return true if the current thread is the event thread, or if thisObject is an instance of a subclass of java.awt.Component and that component has not been realized yet.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
Returns:
true if the current thread is the event thread, or thisObject is a component that has not been realized

checkThread

public static boolean checkThread(java.lang.Object thisObject,
                                  java.lang.Class fieldClass,
                                  java.lang.String fieldName)
Return true if the current thread is equal to the thread in the specified field.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
fieldClass - the class the field is in
fieldName - the name of the field
Returns:
true if the current thread is equal to the thread in the specified field

checkThreadByName

public static boolean checkThreadByName(java.lang.Object thisObject,
                                        java.lang.String fieldClassName,
                                        java.lang.String fieldName)
Return true if the current thread is equal to the thread in the specified field.

Parameters:
thisObject - "this" at the time of the check, or null if not available; ignored by this method
fieldClassName - the name of the class the field is in
fieldName - the name of the field
Returns:
true if the current thread is equal to the thread in the specified field

checkNullArgument

public static boolean checkNullArgument(java.lang.Object thisObject,
                                        java.lang.Object[] args,
                                        int value)
Return true if the object with index value in the array of method arguments is null.

Parameters:
thisObject - object that represents "this", or null if static
args - array of method arguments
value - index of the method argument that should be checked
Returns:
true if the argument is null (false if value is out of range)

checkDistinctArguments

public static boolean checkDistinctArguments(java.lang.Object thisObject,
                                             java.lang.Object[] args,
                                             int[] value)
Return true if the object with the specified indices are all distinct.

Parameters:
thisObject - object that represents "this", or null if static
args - array of method arguments
value - array of indices of the method argument that should be checked
Returns:
true if the arguments are all distinct, false otherwise, if value is out of range, or if fewer than two indices are specified

checkSameArguments

public static boolean checkSameArguments(java.lang.Object thisObject,
                                         java.lang.Object[] args,
                                         int[] value)
Return true if the object with the specified indices are all the same.

Parameters:
thisObject - object that represents "this", or null if static
args - array of method arguments
value - array of indices of the method argument that should be checked
Returns:
true if the arguments are all the same, false otherwise, if value is out of range, or if fewer than two indices are specified

checkNumberBoundedArgument

public static boolean checkNumberBoundedArgument(java.lang.Object thisObject,
                                                 java.lang.Object[] args,
                                                 NumberBoundedArgument.Mode mode,
                                                 int index,
                                                 double bound,
                                                 double upperBound)
Return true if the object with the specified index is a Number and meeds the bounds.

Parameters:
thisObject - object that represents "this", or null if static
args - array of method arguments
mode - bounding mode
index - index of the method argument that should be checked
bound - bound
upperBound - upper bound
Returns:
true if the number meets the bound, false otherwise, if index is out of range, or if the argument is not a Number