Search in sources :

Example 6 with RuleInspector

use of org.drools.verifier.core.cache.inspectors.RuleInspector in project drools by kiegroup.

the class CheckRunManagerTest method setUp.

@Before
public void setUp() throws Exception {
    configuration = new AnalyzerConfigurationMock();
    checkStorage = new CheckStorage(new CheckFactory(configuration) {

        @Override
        public HashSet<Check> makeSingleChecks(final RuleInspector ruleInspector) {
            final HashSet<Check> result = new HashSet<>();
            result.add(new MockSingleCheck(ruleInspector));
            return result;
        }
    });
    ruleInspectors = new ArrayList<>();
    when(cache.all()).thenReturn(ruleInspectors);
    ruleInspector1 = mockRowInspector(1);
    ruleInspectors.add(ruleInspector1);
    ruleInspector2 = mockRowInspector(2);
    ruleInspectors.add(ruleInspector2);
    ruleInspector3 = mockRowInspector(3);
    ruleInspectors.add(ruleInspector3);
    checkRunManager.addChecks(ruleInspector1.getChecks());
    checkRunManager.addChecks(ruleInspector2.getChecks());
    checkRunManager.addChecks(ruleInspector3.getChecks());
}
Also used : AnalyzerConfigurationMock(org.drools.verifier.core.AnalyzerConfigurationMock) RuleInspector(org.drools.verifier.core.cache.inspectors.RuleInspector) Check(org.drools.verifier.core.checks.base.Check) SingleCheck(org.drools.verifier.core.checks.base.SingleCheck) CheckFactory(org.drools.verifier.core.checks.base.CheckFactory) CheckStorage(org.drools.verifier.core.checks.base.CheckStorage) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 7 with RuleInspector

use of org.drools.verifier.core.cache.inspectors.RuleInspector in project drools by kiegroup.

the class RuleInspectorCacheTest method assertContainsRowNumbers.

private void assertContainsRowNumbers(final Collection<RuleInspector> all, final int... numbers) {
    final ArrayList<Integer> rowNumbers = new ArrayList<>();
    for (final RuleInspector ruleInspector : all) {
        final int rowIndex = ruleInspector.getRowIndex();
        rowNumbers.add(rowIndex);
    }
    for (final int number : numbers) {
        assertTrue(rowNumbers.toString(), rowNumbers.contains(number));
    }
}
Also used : RuleInspector(org.drools.verifier.core.cache.inspectors.RuleInspector) ArrayList(java.util.ArrayList)

Example 8 with RuleInspector

use of org.drools.verifier.core.cache.inspectors.RuleInspector 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 9 with RuleInspector

use of org.drools.verifier.core.cache.inspectors.RuleInspector in project drools by kiegroup.

the class PairCheckStorage method removeByOther.

private List<PairCheckBundle> removeByOther(final RuleInspector ruleInspector) {
    final MultiSet<RuleInspector, PairCheckBundle> removedMap = pairChecksByOtherRowInspector.remove(ruleInspector);
    if (removedMap != null) {
        for (final RuleInspector inspector : removedMap.keys()) {
            final Collection<PairCheckBundle> collection = removedMap.get(inspector);
            pairChecks.get(inspector).removeAll(collection);
            getByOther(inspector).remove(ruleInspector);
        }
        return removedMap.allValues();
    } else {
        return Collections.EMPTY_LIST;
    }
}
Also used : RuleInspector(org.drools.verifier.core.cache.inspectors.RuleInspector)

Example 10 with RuleInspector

use of org.drools.verifier.core.cache.inspectors.RuleInspector in project drools by kiegroup.

the class RuleInspectorCache method reset.

public void reset() {
    for (final RuleInspector ruleInspector : ruleInspectors.values()) {
        ruleInspector.clearChecks();
    }
    ruleInspectors.clear();
    generalChecks.clear();
    for (final Rule rule : index.getRules().where(Rule.uuid().any()).select().all()) {
        add(new RuleInspector(rule, checkStorage, this, configuration));
    }
    generalChecks.add(new SingleRangeCheck(configuration, ruleInspectors.values()));
}
Also used : RuleInspector(org.drools.verifier.core.cache.inspectors.RuleInspector) SingleRangeCheck(org.drools.verifier.core.checks.SingleRangeCheck) Rule(org.drools.verifier.core.index.model.Rule)

Aggregations

RuleInspector (org.drools.verifier.core.cache.inspectors.RuleInspector)10 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Rule (org.drools.verifier.core.index.model.Rule)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1