Search in sources :

Example 1 with ObjectField

use of org.drools.verifier.core.index.model.ObjectField in project drools by kiegroup.

the class ConditionsInspectorTest method setUp.

@Before
public void setUp() throws Exception {
    configurationMock = new AnalyzerConfigurationMock();
    field = new Field(new ObjectField("Person", "Integer", "age", configurationMock), "Person", "Integer", "age", configurationMock);
}
Also used : ObjectField(org.drools.verifier.core.index.model.ObjectField) Field(org.drools.verifier.core.index.model.Field) AnalyzerConfigurationMock(org.drools.verifier.core.AnalyzerConfigurationMock) ObjectField(org.drools.verifier.core.index.model.ObjectField) Before(org.junit.Before)

Example 2 with ObjectField

use of org.drools.verifier.core.index.model.ObjectField in project drools by kiegroup.

the class ConditionsInspectorTest method testSubsume003.

@Test
public void testSubsume003() throws Exception {
    final Field nameField = new Field(new ObjectField("Person", "String", "name", configurationMock), "Person", "String", "name", configurationMock);
    final Field lastNameField = new Field(new ObjectField("Person", "String", "lastName", configurationMock), "Person", "String", "lastName", configurationMock);
    final ConditionsInspectorMultiMap a = getConditions(new ComparableConditionInspector<String>(new FieldCondition(nameField, mock(Column.class), "==", new Values<>("Toni"), configurationMock), configurationMock));
    final ConditionsInspectorMultiMap b = getConditions(new ComparableConditionInspector<Integer>(new FieldCondition(field, mock(Column.class), "==", new Values<>(12), configurationMock), configurationMock), new ComparableConditionInspector<String>(new FieldCondition(nameField, mock(Column.class), "==", new Values<>("Toni"), configurationMock), configurationMock), new ComparableConditionInspector<String>(new FieldCondition(lastNameField, mock(Column.class), "==", new Values<>("Rikkola"), configurationMock), configurationMock));
    assertFalse(a.subsumes(b));
    assertTrue(b.subsumes(a));
}
Also used : ObjectField(org.drools.verifier.core.index.model.ObjectField) Field(org.drools.verifier.core.index.model.Field) FieldCondition(org.drools.verifier.core.index.model.FieldCondition) ConditionsInspectorMultiMap(org.drools.verifier.core.cache.inspectors.condition.ConditionsInspectorMultiMap) Column(org.drools.verifier.core.index.model.Column) ObjectField(org.drools.verifier.core.index.model.ObjectField) Test(org.junit.Test)

Example 3 with ObjectField

use of org.drools.verifier.core.index.model.ObjectField in project drools by kiegroup.

the class FieldInspectorUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    configurationMock = new AnalyzerConfigurationMock();
    final Field field = spy(new Field(objectField, "org.Person", "String", "name", configurationMock));
    fieldCondition = makeCondition(field);
    fieldAction = makeAction(field);
    new FieldInspector(field, ruleInspectorUpdater, new AnalyzerConfigurationMock());
}
Also used : ObjectField(org.drools.verifier.core.index.model.ObjectField) Field(org.drools.verifier.core.index.model.Field) AnalyzerConfigurationMock(org.drools.verifier.core.AnalyzerConfigurationMock) Before(org.junit.Before)

Example 4 with ObjectField

use of org.drools.verifier.core.index.model.ObjectField in project drools by kiegroup.

the class SingleRangeCheck method partition.

private Map<PartitionKey, List<RuleInspector>> partition(Collection<ObjectField> partitionFields, Collection<RuleInspector> rules, int conditionIndex) {
    List<PartitionKey> keysWithNull = new ArrayList<>();
    Map<PartitionKey, List<RuleInspector>> partitions = new HashMap<>();
    for (RuleInspector rule : rules) {
        PartitionKey key = getPartitionKey(partitionFields, rule, conditionIndex);
        partitions.computeIfAbsent(key, k -> {
            if (k.hasNulls()) {
                keysWithNull.add(k);
            }
            return new ArrayList<>();
        }).add(rule);
    }
    for (PartitionKey key : keysWithNull) {
        for (Map.Entry<PartitionKey, List<RuleInspector>> partition : partitions.entrySet()) {
            if (key.subsumes(partition.getKey())) {
                partition.getValue().addAll(partitions.get(key));
            }
        }
    }
    keysWithNull.forEach(partitions::remove);
    return partitions;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) ConditionInspector(org.drools.verifier.core.cache.inspectors.condition.ConditionInspector) SortedSet(java.util.SortedSet) Date(java.util.Date) AnalyzerConfiguration(org.drools.verifier.core.configuration.AnalyzerConfiguration) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) RuleInspector(org.drools.verifier.core.cache.inspectors.RuleInspector) Function(java.util.function.Function) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ObjectField(org.drools.verifier.core.index.model.ObjectField) HashSet(java.util.HashSet) CheckBase(org.drools.verifier.core.checks.base.CheckBase) CheckType(org.drools.verifier.api.reporting.CheckType) Map(java.util.Map) FieldCondition(org.drools.verifier.core.index.model.FieldCondition) Collectors.toSet(java.util.stream.Collectors.toSet) Operator(org.drools.verifier.core.relations.Operator) Operator.resolve(org.drools.verifier.core.relations.Operator.resolve) Iterator(java.util.Iterator) Collection(java.util.Collection) Severity(org.drools.verifier.api.reporting.Severity) Set(java.util.Set) Issue(org.drools.verifier.api.reporting.Issue) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) HashMap(java.util.HashMap) RuleInspector(org.drools.verifier.core.cache.inspectors.RuleInspector) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ObjectField

use of org.drools.verifier.core.index.model.ObjectField in project drools by kiegroup.

the class SingleRangeCheck method checkRanges.

private void checkRanges(Collection<ObjectField> rangeFields, Map<PartitionKey, List<RuleInspector>> partitions, int conditionIndex) {
    for (Map.Entry<PartitionKey, List<RuleInspector>> partition : partitions.entrySet()) {
        List<List<? extends Range<?>>> dimensions = new ArrayList<>();
        for (ObjectField field : rangeFields) {
            if ("Integer".equals(field.getFieldType())) {
                checkMonodimensionalRange(partition, dimensions, field, conditionIndex, IntegerRange::new, Integer.MIN_VALUE, Integer.MAX_VALUE);
            } else if ("Double".equals(field.getFieldType())) {
                checkMonodimensionalRange(partition, dimensions, field, conditionIndex, NumericRange::new, Double.MIN_VALUE, Double.MAX_VALUE);
            } else {
                checkMonodimensionalRange(partition, dimensions, field, conditionIndex, ComparableRange::new, ComparableWrapper.MIN_VALUE, ComparableWrapper.MAX_VALUE);
            }
        }
        checkBidimensionalRanges(partition, dimensions);
    }
}
Also used : ArrayList(java.util.ArrayList) ObjectField(org.drools.verifier.core.index.model.ObjectField) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ObjectField (org.drools.verifier.core.index.model.ObjectField)7 Field (org.drools.verifier.core.index.model.Field)4 AnalyzerConfigurationMock (org.drools.verifier.core.AnalyzerConfigurationMock)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 FieldCondition (org.drools.verifier.core.index.model.FieldCondition)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1