org.drools.verifier.dao.VerifierDataMaps Maven / Gradle / Ivy
package org.drools.verifier.dao;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.drools.verifier.components.Consequence;
import org.drools.verifier.components.Constraint;
import org.drools.verifier.components.Field;
import org.drools.verifier.components.FieldObjectTypeLink;
import org.drools.verifier.components.ObjectType;
import org.drools.verifier.components.OperatorDescr;
import org.drools.verifier.components.Pattern;
import org.drools.verifier.components.PatternPossibility;
import org.drools.verifier.components.Restriction;
import org.drools.verifier.components.RulePackage;
import org.drools.verifier.components.RulePossibility;
import org.drools.verifier.components.Variable;
import org.drools.verifier.components.VerifierEvalDescr;
import org.drools.verifier.components.VerifierPredicateDescr;
import org.drools.verifier.components.VerifierRule;
/**
*
* @author Toni Rikkola
*/
class VerifierDataMaps implements VerifierData {
private Map packagesById = new TreeMap();
private Map packagesByName = new TreeMap();
private Map objectTypesById = new TreeMap();
private Map objectTypesByName = new TreeMap();
private Map fieldsByObjectTypeAndFieldName = new TreeMap();
private Map fieldsById = new TreeMap();
private DataTree fieldsByObjectTypeId = new DataTree();
private Map fieldObjectTypeLinkByIds = new TreeMap();
private Map rulesById = new TreeMap();
private Map patternsById = new TreeMap();
private DataTree patternsByObjectTypeId = new DataTree();
private DataTree patternsByRuleName = new DataTree();
private Map constraintsById = new TreeMap();
private Map restrictionsById = new TreeMap();
private DataTree restrictionsByFieldId = new DataTree();
private Map operatorsById = new TreeMap();
private Map evalsById = new TreeMap();
private Map predicatesById = new TreeMap();
private Map consiquencesById = new TreeMap();
private Map variablesByRuleAndVariableName = new TreeMap();
private Map patternPossibilitiesById = new TreeMap();
private Map rulePossibilitiesById = new TreeMap();
public void add(ObjectType objectType) {
objectTypesById.put(Integer.valueOf(objectType.getId()), objectType);
objectTypesByName.put(objectType.getName(), objectType);
}
public void add(Field field) {
ObjectType objectType = objectTypesById.get(Integer.valueOf(field
.getObjectTypeId()));
fieldsByObjectTypeAndFieldName.put(objectType.getName() + "."
+ field.getName(), field);
fieldsById.put(field.getId(), field);
fieldsByObjectTypeId.put(field.getObjectTypeId(), field);
}
public void add(Variable variable) {
variablesByRuleAndVariableName.put(variable.getRuleName() + "."
+ variable.getName(), variable);
}
public void add(VerifierRule rule) {
rulesById.put(Integer.valueOf(rule.getId()), rule);
}
public void add(Pattern pattern) {
patternsById.put(Integer.valueOf(pattern.getId()), pattern);
patternsByObjectTypeId.put(pattern.getObjectTypeId(), pattern);
patternsByRuleName.put(pattern.getRuleName(), pattern);
}
public void add(Constraint constraint) {
constraintsById.put(Integer.valueOf(constraint.getId()), constraint);
}
public void add(Restriction restriction) {
restrictionsById.put(restriction.getId(), restriction);
restrictionsByFieldId.put(restriction.getFieldId(), restriction);
}
public void add(FieldObjectTypeLink link) {
fieldObjectTypeLinkByIds.put(link.getFieldId() + "."
+ link.getObjectTypeId(), link);
}
public ObjectType getObjectTypeByName(String name) {
return objectTypesByName.get(name);
}
public Field getFieldByObjectTypeAndFieldName(String objectTypeName,
String fieldName) {
return fieldsByObjectTypeAndFieldName.get(objectTypeName + "."
+ fieldName);
}
public Variable getVariableByRuleAndVariableName(String ruleName,
String variableName) {
return variablesByRuleAndVariableName
.get(ruleName + "." + variableName);
}
public FieldObjectTypeLink getFieldObjectTypeLink(int id, int id2) {
return fieldObjectTypeLinkByIds.get(id + "." + id2);
}
public Collection getAllRules() {
return rulesById.values();
}
public void add(PatternPossibility possibility) {
patternPossibilitiesById.put(possibility.getId(), possibility);
}
public void add(RulePossibility possibility) {
rulePossibilitiesById.put(possibility.getId(), possibility);
}
public Collection getObjectTypesByRuleName(String ruleName) {
Set set = new HashSet();
for (Pattern pattern : patternsByRuleName.getBranch(ruleName)) {
ObjectType objectType = getObjectTypeById(pattern.getObjectTypeId());
set.add(objectType);
}
return set;
}
public ObjectType getObjectTypeById(int id) {
return objectTypesById.get(id);
}
public Collection extends Object> getAll() {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy