001 package edu.rice.cs.cunit.threadCheck.predicates;
002
003 import java.awt.*;
004
005 /**
006 * Class containing several common predicates used by the @Not* annotations.
007 * @author Mathias Ricken
008 */
009 public class NotThreadCheckPredicates {
010 /**
011 * Return false if the current thread is the event thread.
012 * @param thisObject "this" at the time of the check, or null if not available; ignored by this method
013 * @return false if the current thread is the event thread
014 */
015 public static boolean checkEventThread(Object thisObject) {
016 return !EventQueue.isDispatchThread();
017 }
018
019 /**
020 * Return false if the current thread's name equals the specified string
021 * @param thisObject "this" at the time of the check, or null if not available; ignored by this method
022 * @param value string to compare the current thread's name to
023 * @param regex true if value should be treated as a regular expression
024 * @return false if the current thread's name equals the specified string
025 */
026 public static boolean checkName(Object thisObject, String value, boolean regex) {
027 if (regex) {
028 return !Thread.currentThread().getName().matches(value);
029 }
030 else {
031 return !Thread.currentThread().getName().equals(value);
032 }
033 }
034
035 /**
036 * Return false if the current thread's group equals the specified string
037 * @param thisObject "this" at the time of the check, or null if not available; ignored by this method
038 * @param value string to compare the current thread's group to
039 * @param regex true if value should be treated as a regular expression
040 * @return false if the current thread's group equals the specified string
041 */
042 public static boolean checkGroup(Object thisObject, String value, boolean regex) {
043 if (regex) {
044 return !Thread.currentThread().getThreadGroup().getName().matches(value);
045 }
046 else {
047 return !Thread.currentThread().getThreadGroup().getName().equals(value);
048 }
049 }
050 }