Class PropertyRestrictor
- java.lang.Object
-
- science.aist.gtf.verification.syntactic.PropertyRestrictor
-
public class PropertyRestrictor extends Object
Property restrictor which consists of collections of classes, fields, default values which should be considered in property verification process
General Constraint Convention: Normally you will need
NullConstraint
,DefaultInitializedConstraint
andEmptyContainerConstraint
. If default constructor is used those will be initialized atgeneralConstraints
indices Integer.MIN_VALUE, Integer.MIN_VALUE + 1 and Integer.MIN_VALUE + 2.You can use the PropertyRestrictor in a spring configuration file like:
<bean name="restrictor" class="science.aist.gtf.verification.syntactic.PropertyRestrictor"> <!-- ignored classes --> <property name="ignoredClasses"> <list> <value>java.lang.String</value> <value>java.lang.Integer</value> <value>science.aist.gtf.core.FieldTuple</value> </list> </property> <!-- ignored fields of class --> <property name="ignoredFieldsInClass"> <list value-type="science.aist.gtf.core.FieldTuple"> <bean class="science.aist.gtf.core.FieldTuple"> <constructor-arg name="first" value="java.lang.Integer"/> <constructor-arg name="second" value="SIZE"/> </bean> <bean class="science.aist.gtf.core.FieldTuple"> <constructor-arg name="first" value="java.lang.Integer"/> <constructor-arg name="second" value="BYTES"/> </bean> <bean class="science.aist.gtf.core.FieldTuple"> <constructor-arg name="first" value="science.aist.gtf.core.FieldTuple"/> <constructor-arg name="second" value="first"/> </bean> <bean class="science.aist.gtf.core.FieldTuple"> <constructor-arg name="first" value="science.aist.gtf.core.FieldTuple"/> <constructor-arg name="second" value="second"/> </bean> </list> </property> <!-- general constraints --> <property name="generalConstraints"> <map> <entry key="#{ T(java.lang.Integer).MIN_VALUE }"> <bean class="science.aist.gtf.verification.syntactic.constraint.impl.NullConstraint"/> </entry> <entry key="#{ T(java.lang.Integer).MIN_VALUE + 1 }"> <bean class="science.aist.gtf.verification.syntactic.constraint.impl.DefaultInitializedConstraint"> <property name="userdefinedDefaultValues"> <map> <entry key="science.aist.gtf.core.Tuple"> <map> <entry key="first" value="10"/> <entry key="second" value="5"/> </map> </entry> <entry key="java.lang.Integer"> <map> <entry key="SIZE" value-type="java.lang.Integer" value="10"/> </map> </entry> </map> </property> </bean> </entry> <entry key="#{ T(java.lang.Integer).MIN_VALUE + 2 }"> <bean class="science.aist.gtf.verification.syntactic.constraint.impl.EmptyContainerConstraint"/> </entry> </map> </property> <!-- class constraints --> <property name="classConstraints"> <map> <entry key="java.lang.Integer"> <map> <entry key="0"> <bean class="science.aist.gtf.verification.syntactic.constraint.impl.IntegerRangeConstraint"> <property name="lowerBound" value="0"/> <property name="upperBound" value="5"/> </bean> </entry> </map> </entry> </map> </property> <!-- fields per class constraints --> <property name="fieldConstraints"> <map> <entry> <key> <bean name="keyBean1" class="science.aist.gtf.core.FieldTuple"> <constructor-arg name="first" value="test.something.SomeClass"/> <constructor-arg name="second" value="someBooleanField"/> </bean> </key> <map> <entry key="0"> <bean class="science.aist.gtf.verification.syntactic.constraint.impl.BooleanConstraint"> <property name="expectedValue" value="true"/> </bean> </entry> </map> </entry> </map> </property> </bean>
- Since:
- 1.0
- Author:
- Christoph Praschl
-
-
Constructor Summary
Constructors Constructor Description PropertyRestrictor()
Constructs a property restrictor with initialized general constraints containing:NullConstraint
at indexInteger.MIN_VALUE
,DefaultInitializedConstraint
at indexInteger.MIN_VALUE
+ 1 andEmptyContainerConstraint
at indexInteger.MIN_VALUE
+ 2.PropertyRestrictor(boolean initializeGeneralConstraints)
Constructs a property restrictor with initialized general constraints containing if initializeGeneralConstraints is true:NullConstraint
at indexInteger.MIN_VALUE
,DefaultInitializedConstraint
at indexInteger.MIN_VALUE
+ 1 andEmptyContainerConstraint
at indexInteger.MIN_VALUE
+ 2.PropertyRestrictor(boolean initializeNullConstraint, boolean initializeDefaultInitializedConstraint, boolean initializeEmptyContainerConstraint)
Constructs a property restrictor with initialized general constraints containingNullConstraint
,DefaultInitializedConstraint
andEmptyContainerConstraint
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addClassConstraint(Class<T> clazz, Constraint<T> c)
Add a constraint for a given class (takes the next possible priority)<T> void
addClassConstraint(Class<T> clazz, Constraint<T> c, Integer priority)
Add a constraint for a given class with a given priority Attention: Only one constraint per priority! Calling multiple times with same priority will always replace the constraint.void
addFieldConstraint(Class<?> clazz, String fieldName, Constraint<?> c)
Add a constraint for a given field (takes the next possible priority)void
addFieldConstraint(Field f, Constraint<?> c)
Add a constraint for a given field (takes the next possible priority)void
addFieldConstraint(Field f, Constraint<?> c, Integer priority)
Add a constraint for a given field with a given priority Attention: Only one constraint per priority! Calling multiple times with same priority will always replace the constraint.void
addGeneralConstraint(Integer priority, Constraint<?> c)
Adds a general constraint checked for every field if suitablevoid
addIgnoredClass(Class<?> clazz)
Method to add a class to be ignored (helpful for e.q.void
addIgnoredClassField(Class<?> clazz, String fieldName)
Method to ignore a field in a class (helpful for fields which are not touched by transformation for some reason)void
addIgnoredClassField(Field field)
Method to ignore a field in a class (helpful for fields which are not touched by transformation for some reason)Collection<Class<?>>
getIgnoredClasses()
Collection<Field>
getIgnoredFieldsInClass()
void
setFieldConstraints(Map<science.aist.jack.data.Pair<Class<?>,String>,Map<Integer,Constraint<?>>> fieldConstraints)
void
setIgnoredFieldsInClass(Iterable<science.aist.jack.data.Pair<Class<?>,String>> ignoredFieldsInClass)
-
-
-
Constructor Detail
-
PropertyRestrictor
public PropertyRestrictor()
Constructs a property restrictor with initialized general constraints containing:NullConstraint
at indexInteger.MIN_VALUE
,DefaultInitializedConstraint
at indexInteger.MIN_VALUE
+ 1 andEmptyContainerConstraint
at indexInteger.MIN_VALUE
+ 2.
-
PropertyRestrictor
public PropertyRestrictor(boolean initializeGeneralConstraints)
Constructs a property restrictor with initialized general constraints containing if initializeGeneralConstraints is true:NullConstraint
at indexInteger.MIN_VALUE
,DefaultInitializedConstraint
at indexInteger.MIN_VALUE
+ 1 andEmptyContainerConstraint
at indexInteger.MIN_VALUE
+ 2.- Parameters:
initializeGeneralConstraints
- if true initializes the three general constraints
-
PropertyRestrictor
public PropertyRestrictor(boolean initializeNullConstraint, boolean initializeDefaultInitializedConstraint, boolean initializeEmptyContainerConstraint)
Constructs a property restrictor with initialized general constraints containingNullConstraint
,DefaultInitializedConstraint
andEmptyContainerConstraint
.- Parameters:
initializeNullConstraint
- if true NullConstraint will be initialized at positionInteger.MIN_VALUE
initializeDefaultInitializedConstraint
- if true DefaultInitializedConstraint will be initialized at positionInteger.MIN_VALUE
+ 1initializeEmptyContainerConstraint
- if true EmptyContainerConstraint will be initialized at positionInteger.MIN_VALUE
+ 2
-
-
Method Detail
-
getIgnoredClasses
public Collection<Class<?>> getIgnoredClasses()
- Returns:
- Collection with classes which should be ignored
-
getIgnoredFieldsInClass
public Collection<Field> getIgnoredFieldsInClass()
- Returns:
- Collection with Tuples for a field in a given class which should be ignored
-
setIgnoredFieldsInClass
public void setIgnoredFieldsInClass(Iterable<science.aist.jack.data.Pair<Class<?>,String>> ignoredFieldsInClass)
- Parameters:
ignoredFieldsInClass
- sets the collection ofignoredFieldsInClass
-
addIgnoredClassField
public void addIgnoredClassField(Field field)
Method to ignore a field in a class (helpful for fields which are not touched by transformation for some reason)- Parameters:
field
- Field which should be ignored
-
addIgnoredClassField
public void addIgnoredClassField(Class<?> clazz, String fieldName)
Method to ignore a field in a class (helpful for fields which are not touched by transformation for some reason)- Parameters:
clazz
- Class which contains the fieldfieldName
- Name of the Field which should be ignored
-
addIgnoredClass
public void addIgnoredClass(Class<?> clazz)
Method to add a class to be ignored (helpful for e.q. boolean which has often the default value `false` and is so often misinterpreted as IsDefaultInitialized)- Parameters:
clazz
- clazz which should be ignored
-
setFieldConstraints
public void setFieldConstraints(Map<science.aist.jack.data.Pair<Class<?>,String>,Map<Integer,Constraint<?>>> fieldConstraints)
- Parameters:
fieldConstraints
- Constraints for a specific field
-
addGeneralConstraint
public void addGeneralConstraint(Integer priority, Constraint<?> c)
Adds a general constraint checked for every field if suitable- Parameters:
priority
- priority of the constraintc
- constraint
-
addFieldConstraint
public void addFieldConstraint(Field f, Constraint<?> c)
Add a constraint for a given field (takes the next possible priority)- Parameters:
f
- field for which the constraint should be definedc
- constraint which should be added
-
addFieldConstraint
public void addFieldConstraint(Class<?> clazz, String fieldName, Constraint<?> c)
Add a constraint for a given field (takes the next possible priority)- Parameters:
clazz
- Class which contains the fieldfieldName
- Name of the Field for which constraint is addedc
- constraint which should be added
-
addFieldConstraint
public void addFieldConstraint(Field f, Constraint<?> c, Integer priority)
Add a constraint for a given field with a given priority Attention: Only one constraint per priority! Calling multiple times with same priority will always replace the constraint.- Parameters:
f
- field for which the constraint should be definedc
- constraint which should be addedpriority
- the priority of the constraint
-
addClassConstraint
public <T> void addClassConstraint(Class<T> clazz, Constraint<T> c)
Add a constraint for a given class (takes the next possible priority)- Type Parameters:
T
- type parameter of class- Parameters:
clazz
- class for which the constraint should be definedc
- constraint which should be added
-
addClassConstraint
public <T> void addClassConstraint(Class<T> clazz, Constraint<T> c, Integer priority)
Add a constraint for a given class with a given priority Attention: Only one constraint per priority! Calling multiple times with same priority will always replace the constraint.- Type Parameters:
T
- type parameter of class- Parameters:
clazz
- class for which the constraint should be definedc
- constraint which should be addedpriority
- the priority of the constraint
-
-