
org.biopax.validator.AbstractCardinalityAndRangeRule Maven / Gradle / Ivy
package org.biopax.validator;
import java.util.HashSet;
import java.util.Set;
import org.biopax.paxtools.controller.EditorMap;
import org.biopax.paxtools.controller.PropertyEditor;
import org.biopax.paxtools.model.BioPAXElement;
import org.biopax.validator.api.ValidatorException;
import org.biopax.validator.api.beans.Validation;
/**
* Base BioPAX Rule for checking cardinality and range restrictions.
*
* @author rodche
*
* @param extends BioPAXElement
*/
public abstract class AbstractCardinalityAndRangeRule
extends AbstractRule
{
protected EditorMap editorMap;
private final String property;
private final Class domain;
private int minCardinality = 0;
private int maxCardinality = Integer.MAX_VALUE;
Class>[] ranges; // although the editor has range property, this is for stricter checks
String rangesAsString = "";
// Constructor with arguments
public AbstractCardinalityAndRangeRule(
Class domain, String property,
int min, int max, Class>... ranges) {
this.domain = domain;
this.property = property;
this.minCardinality = (min >= 0) ? min : 0;
this.maxCardinality = (max > 0) ? max : Integer.MAX_VALUE;
this.ranges = ranges;
for(Class> cl : ranges) {
rangesAsString += cl.getSimpleName() + " ";
}
}
public boolean canCheck(Object thing) {
return domain.isInstance(thing);
}
public void check(Validation validation, E thing) {
PropertyEditor editor =
editorMap.getEditorForProperty(property, thing.getModelInterface());
if(editor == null) {
throw new ValidatorException(
"BUG in " + getClass().getSimpleName() +
" rule: no editor exists for property '" +
property + "' of " + domain);
}
//get value(s) from the property of the biopax obj; copy to avoid CMEx...
Set> ret = null;
//sync to get the property values (there're other rules in separate threads that might check/fix the same thing and property)
synchronized (thing) {
ret = new HashSet
© 2015 - 2025 Weber Informatics LLC | Privacy Policy