se.liu.ida.critiquer.constraints
Class StructureCritic

java.lang.Object
  extended by se.liu.ida.critiquer.activities.AbstractParamChangedListener
      extended by se.liu.ida.critiquer.constraints.StandardConstraint
          extended by se.liu.ida.critiquer.constraints.StructureCritic
All Implemented Interfaces:
Serializable, Comparable<ActivityUpdateListener>, ActivityUpdateListener, SingletonConstraint, VisualConstraint, ViewRenderingListener
Direct Known Subclasses:
AgentMutex

public abstract class StructureCritic
extends StandardConstraint

Thisclass should be inherited by all individual structure critics. Structure critics can be checked individually for consistency through the ActivityStructureCritic.

Author:
olale
See Also:
Serialized Form

Field Summary
protected  ArrayList<Class<? extends Activity>> applicableClasses
          A structure critic can be applicable to one or more activity classes
protected  String description
           
protected  HashMap<Activity,String> errorMessages
           
protected  Logger logger
           
protected static Pair<Boolean,String> OK
           
 
Fields inherited from class se.liu.ida.critiquer.constraints.StandardConstraint
applicableViews, statusListeners, violationActivities
 
Constructor Summary
StructureCritic()
          Subclasses need to call this constructor in order to be included among the static activity update listeners and have their applicable classes registered.
 
Method Summary
 void activityCreated(Activity activity)
          Checks the consistency
 void activityRemoved(Activity activity)
          Checks the consistency
 void activityUpdated(Activity activity)
          Checks the consistency
 void addApplicableClass(Class<? extends Activity> activityClass)
           
 void addApplicableClasses()
          Subclasses should override this method if they are only applicable to some subclasses of Activity.
 boolean applicableForActivity(Activity activity)
          Is there a class among the ones in applicableClasses that is assignment-compatible with the class of the argument activity?
abstract  Pair<Boolean,String> check(Activity activity)
          This method checks if an activity is consistent with respect to some structural property, such as that it should be completely specified, have an agent, have a parent activity and so on.
protected  void checkAndUpdate(Activity activity)
           
 int compareTo(ActivityUpdateListener l)
          Make sure these critics are processed before the ActivityStructureCritic
abstract  String getDescription()
          Describes which errors this critic will find
 String getErrorMessage(Activity activity)
          Returns an error message for this activity.
 HashMap<Activity,String> getErrorMessages()
           
abstract  String getName()
          Short descriptive name
 boolean isConsistent(Activity activity)
           
<T> void
paramChanged(Activity activity, Parameter<T> p)
          Checks the consistency
 void viewUpdated(View v, Graphics2D g2)
           
 
Methods inherited from class se.liu.ida.critiquer.constraints.StandardConstraint
addStatusListener, debug, error, getApplicableViews, getColor, info, initApplicableViews, isActive, isApplicableFor, isConsistent, removeStatusListener, setActive, setColor, setConsistent, warn
 
Methods inherited from class se.liu.ida.critiquer.activities.AbstractParamChangedListener
paramAdded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OK

protected static Pair<Boolean,String> OK

applicableClasses

protected ArrayList<Class<? extends Activity>> applicableClasses
A structure critic can be applicable to one or more activity classes


errorMessages

protected HashMap<Activity,String> errorMessages

description

protected String description

logger

protected Logger logger
Constructor Detail

StructureCritic

public StructureCritic()
Subclasses need to call this constructor in order to be included among the static activity update listeners and have their applicable classes registered.

Method Detail

applicableForActivity

public boolean applicableForActivity(Activity activity)
Is there a class among the ones in applicableClasses that is assignment-compatible with the class of the argument activity?

Parameters:
activity - The activity we want to check if this structure critic is applicable for
Returns:
true iff this StructureCritic is applicable to the activity.

check

public abstract Pair<Boolean,String> check(Activity activity)
This method checks if an activity is consistent with respect to some structural property, such as that it should be completely specified, have an agent, have a parent activity and so on. If the activity is inconsistent, a message is put into the errorMessages map.

Parameters:
activity - The activity to check
Returns:
A pair of truth-value, message. If the check returns false as the truth value, then the message is the error message.

checkAndUpdate

protected void checkAndUpdate(Activity activity)

isConsistent

public boolean isConsistent(Activity activity)

getDescription

public abstract String getDescription()
Describes which errors this critic will find

Returns:
the description string

getName

public abstract String getName()
Short descriptive name

Returns:
a string with the name

getErrorMessage

public String getErrorMessage(Activity activity)
Returns an error message for this activity.

Parameters:
activity - The activity that we want to check.
Returns:
the error message

addApplicableClasses

public void addApplicableClasses()
Subclasses should override this method if they are only applicable to some subclasses of Activity. This method should add all classes that this critic is applicable for.


addApplicableClass

public void addApplicableClass(Class<? extends Activity> activityClass)

activityUpdated

public void activityUpdated(Activity activity)
Checks the consistency

Specified by:
activityUpdated in interface ActivityUpdateListener
Overrides:
activityUpdated in class AbstractParamChangedListener
See Also:
ActivityUpdateListener.activityUpdated(se.liu.ida.critiquer.activities.Activity)

activityRemoved

public void activityRemoved(Activity activity)
Checks the consistency

Specified by:
activityRemoved in interface ActivityUpdateListener
Overrides:
activityRemoved in class AbstractParamChangedListener
See Also:
ActivityUpdateListener.activityRemoved(se.liu.ida.critiquer.activities.Activity)

activityCreated

public void activityCreated(Activity activity)
Checks the consistency

Specified by:
activityCreated in interface ActivityUpdateListener
Overrides:
activityCreated in class AbstractParamChangedListener
See Also:
ActivityUpdateListener.activityCreated(se.liu.ida.critiquer.activities.Activity)

paramChanged

public <T> void paramChanged(Activity activity,
                             Parameter<T> p)
Checks the consistency

Specified by:
paramChanged in interface ActivityUpdateListener
Specified by:
paramChanged in class AbstractParamChangedListener
See Also:
se.liu.ida.critiquer.activities.ActivityUpdateListener#paramChanged(se.liu.ida.critiquer.activities.Activity, critiquer.activities.parameters.Parameter)

compareTo

public int compareTo(ActivityUpdateListener l)
Make sure these critics are processed before the ActivityStructureCritic

Specified by:
compareTo in interface Comparable<ActivityUpdateListener>
Overrides:
compareTo in class AbstractParamChangedListener
See Also:
java.lang.Comparable#compareTo(T)

getErrorMessages

public HashMap<Activity,String> getErrorMessages()
Returns:
Returns the errorMessages.

viewUpdated

public void viewUpdated(View v,
                        Graphics2D g2)