Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.workbench.screens.testscenario.client;
 
 
 import java.util.*;

Some utility methods as the display logic is a bit hairy.
 
 public class ScenarioHelper {
 
     static final String RETRACT_KEY = "retract";
     static final String ACTIVATE_RULE_FLOW_GROUP = "activate_rule_flow_group";

    
Called lumpy map - as this takes a flat list of fixtures, and groups things together. It will return a list - of which each element will either be a list - or a map. If its a map - then its a map of FactData to the fact type. If its a list, then it will be expectations or retractions.

Man, this will be so much nicer with generics.

Returns:
List<List<VeryifyRuleFired or VerifyFact or RetractFact> OR Map<String, List<FactData>> OR ExecutionTrace>
 
     public List<FixturelumpyMap(List<Fixturefixtures) {
         List<Fixtureoutput = new ArrayList<Fixture>();
 
         FixturesMap dataInput = new FixturesMap();
         CallFixtureMap callOnDataInput = new CallFixtureMap();
         FixtureList verifyFact = new FixtureList();
         FixtureList verifyRule = new FixtureList();
         FixtureList retractFacts = new FixtureList();
         for (Fixture fixture : fixtures) {
             if (fixture instanceof FactData) {
                 accumulateDataForFactData(dataInput, (FactDatafixture);
             } else if (fixture instanceof CallMethod) {
                 accumulateCallMethod(callOnDataInput, (CallMethodfixture);
             } else if (fixture instanceof ActivateRuleFlowGroup) {
                 accumulateDataForActivateRuleFlowGroup(dataInputfixture);
             } else if (fixture instanceof RetractFact) {
                 retractFacts.add(fixture);
             } else if (fixture instanceof VerifyRuleFired) {
                 verifyRule.add(fixture);
             } else if (fixture instanceof VerifyFact) {
                 verifyFact.add(fixture);
             } else if (fixture instanceof ExecutionTrace) {
                 gatherFixtures(outputdataInputcallOnDataInputverifyFactverifyRuleretractFactsfalse);
 
                 output.add(fixture);
 
                 verifyRule = new FixtureList();
                 verifyFact = new FixtureList();
                 retractFacts = new FixtureList();
                 callOnDataInput = new CallFixtureMap();
                 dataInput = new FixturesMap();
             }
         }
         gatherFixtures(outputdataInputcallOnDataInputverifyFactverifyRuleretractFactstrue);
 
         return output;
     }
 
     private void gatherFixtures(List<FixtureoutputFixturesMap dataInputCallFixtureMap callOnDataInputFixtureList verifyFactFixtureList verifyRuleFixtureList retractFactsboolean end) {
         if (verifyRule.size() > 0) output.add(verifyRule);
         if (verifyFact.size() > 0) output.add(verifyFact);
         if (retractFacts.size() > 0) dataInput.put(retractFacts);
         if (dataInput.size() > 0 || !endoutput.add(dataInput); // want to have a place holder for the GUI
         if (callOnDataInput.size() > 0 || !endoutput.add(callOnDataInput);
     }

    
Group the globals together by fact type.
    public Map<StringFixtureListlumpyMapGlobals(List<FactDataglobals) {
        Map<StringFixtureListmap = new HashMap<StringFixtureList>();
        for (FactData factData : globals) {
            accumulateDataForFactData(mapfactData);
        }
        return map;
    }
    private void accumulateDataForFactData(Map<StringFixtureListdataInputFactData fd) {
        if (!dataInput.containsKey(fd.getType())) {
            dataInput.put(fd.getType(), new FixtureList());
        }
        dataInput.get(fd.getType()).add(fd);
    }
    public List<ExecutionTracegetExecutionTraceFor(List<Fixturefixtures) {
        List<FixtureprocessedFixtures = lumpyMap(fixtures);
        List<ExecutionTracelistExecutionTrace = new ArrayList<ExecutionTrace>();
        for (int i = 0; i < processedFixtures.size(); i++) {
            final Object fixture = processedFixtures.get(i);
            if (fixture instanceof ExecutionTrace ) {
                listExecutionTrace.add((ExecutionTracefixture);
            }
        }
        return listExecutionTrace;
    }
    private void accumulateDataForActivateRuleFlowGroup(Map<StringFixtureListdataInputFixture f) {
        if (!dataInput.containsKey(.)) {
            dataInput.put(.new FixtureList());
        }
        dataInput.get(.).add(f);
    }
    private void accumulateCallMethod(Map<StringFixtureListdataInputCallMethod fd) {
        if (!dataInput.containsKey(fd.getVariable())) {
            dataInput.put(fd.getVariable(), new FixtureList());
        }
        dataInput.get(fd.getVariable()).add(fd);
    }
    static void removeFields(List<FixturefactDatasString field) {
        for (Fixture fixture : factDatas) {
            if (fixture instanceof FactData) {
                FactData factData = (FactDatafixture;
                for (Iterator<FieldfieldDataIterator = factData.getFieldData().iterator(); fieldDataIterator.hasNext(); ) {
                    if (fieldDataIterator.next().getName().equals(field)) {
                        fieldDataIterator.remove();
                    }
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X