Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jharks.workflow.conditions;
  import java.util.List;
The class will retrieve responses for the question id that was declared in a <property> tag and attempt to match any of the response values against any of the specified values. This class takes two required attributes that should be configured as <property> elements of the <rule-condition> tag:
  • questionId - the key of the question to retrieve reponses for from the SessionHistory.
  • value - the string value to match reponses against.
Multiple <property&rt; elements can be used to configure multiple values to compare reponse values against. If any of the reponse values match any of the configured comparison values the condition will be met and return true. For example, to check whether the symptom selected was either asthma or seizures and move to the appropriate next view, you could use a transition configured as:
  <transition name="moveRespiratory" next-state="re0">
   <rule type="org.jharks.workflow.rules.GenericOrRule">
    <rule-condition type="org.jharks.workflow.conditions.
      <property name="questionId" value="symQ1"/>
      <property name="value" value="asthma"/>
      <property name="value" value="seizures"/>

Michael J. Rizzo
 public class MultipleStringMatchCondition extends StringMatchCondition {

The constant seperator used for values.
     private final static String SEPARATOR = ";";
A list containing possible values to match reponses against.
     private List<Stringvalue = new ArrayList<String>();
       public boolean checkCondition(Object param) {
       boolean result = false;    
         if (.isDebugEnabled())
               .debug("MultipleStringMatchCondition: Check condition: " +
                     "questionId = " + this.getQuestionId());
         if (param instanceof SessionHistory) {
             SessionHistory rs = (SessionHistoryparam;
             List<Answerresponses = rs.getResponses(this.getQuestionId());
             if (responses != null) {
               if (.isDebugEnabled())
                   .debug ("Size response set " + responses.size());
               for (int i=0; i < responses.size(); i++) {
                   result = compare(responses.get(i));
                   if (resultbreak;
         } else {
             throw new ClassCastException("Expecting SessionHistory Object.");
       return result;
Compare method to check equivalence. Compares response values against each string in the value list.

response the response for the configured question.
true if response matches one of configured values.
     private boolean compare(Object response) {
         Object answerValue = WorkFlowUtilities.getAnswerValue(response); 
         boolean cmpResult = false;
         if (answerValue instanceof String) {
             String stResp = (StringanswerValue;
            for (int i=0; i < .size(); i++) {
                String val = .get(i);
                if.isDebugEnabled() )
                    .debug("MultipleStringMatchCondition: comparison " +
                      "value = [" + val + "]: response value = [" 
                      + stResp + "]");
                if (stResp.equalsIgnoreCase(val)) {
                  cmpResult = true;
            return cmpResult;
        } else {
            throw new ClassCastException("Expecting String Object.");
Getter method for value property. Returns all values within the value list as a delimited string.

Returns the value string.
    public String getValue() {
        Object[] valArray = .toArray();
        StringBuffer result = new StringBuffer();
        if (valArray.length > 0) {
            for (int i=1; i<valArray.lengthi++) {
        return result.toString();
Setter method for value property.

value The value to set.
    public void setValue(String value) {
        if.isDebugEnabled() )
            .debug("MultipleStringMatchCondition: added value to " +
                    "list = [" + value + "]: response size = [" 
                    + this..size() + "]");
New to GrepCode? Check out our FAQ X