/** * This will go through the widgets and extract the values */ protected void updateSentence() { int iVariable = 0; for (Iterator<Widget> iter = widgets.iterator(); iter.hasNext(); ) { Widget wid = iter.next(); if (wid instanceof DSLVariableEditor) { sentence.getValues().set(iVariable++, ((DSLVariableEditor) wid).getSelectedValue()); } } this.setModified(true); }
/** * This will go through the widgets and extract the values */ protected void updateSentence() { int iVariable = 0; for (Iterator<Widget> iter = widgets.iterator(); iter.hasNext(); ) { Widget wid = iter.next(); if (wid instanceof DSLVariableEditor) { sentence.getValues().set(iVariable++, ((DSLVariableEditor) wid).getSelectedValue()); } } this.setModified(true); }
/** * This will strip off any "{" stuff, substituting values accordingly */ public String interpolate() { getValues(); if (definition == null) { return ""; } int variableStart = definition.indexOf("{"); if (variableStart < 0) { return definition; } int index = 0; int variableEnd = 0; StringBuilder sb = new StringBuilder(); while (variableStart >= 0) { sb.append(definition.substring(variableEnd, variableStart)); variableEnd = getIndexForEndOfVariable(definition, variableStart) + 1; variableStart = definition.indexOf("{", variableEnd); sb.append(values.get(index++).getValue()); } if (variableEnd < definition.length()) { sb.append(definition.substring(variableEnd)); } return sb.toString(); }
if (getValues().isEmpty()) { return fieldValueMap;
private DSLSentence toDSLSentence(final List<SimpleDSLSentence> simpleDslSentences, final String dslLine) { DSLSentence dslSentence = new DSLSentence(); for (SimpleDSLSentence simpleDslSentence : simpleDslSentences) { String dslPattern = simpleDslSentence.getDsl(); // Dollar breaks the matcher, need to escape them. dslPattern = dslPattern.replace("$", "\\$"); //A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}" String regex = dslPattern.replaceAll("\\{.*?\\}", "(.*)"); Matcher matcher = Pattern.compile(regex).matcher(dslLine); if (matcher.matches()) { dslPattern = dslPattern.replace("\\$", "$"); dslSentence.setDrl(simpleDslSentence.getDrl()); dslSentence.setDefinition(dslPattern); for (int i = 0; i < matcher.groupCount(); i++) { dslSentence.getValues().get(i).setValue(matcher.group(i + 1)); } return dslSentence; } } dslSentence.setDefinition(dslLine); return dslSentence; }
/** * This is used by the GUI when adding a sentence to LHS or RHS. * @return */ public DSLSentence copy() { final DSLSentence copy = new DSLSentence(); copy.drl = getDrl(); copy.definition = getDefinition(); copy.values = mapCopy(getValues()); return copy; }
List<DSLVariableValue> dslValues = sentence.getValues(); int index = 0;
List<DSLVariableValue> dslValues = sentence.getValues(); int index = 0;
dslPattern.getDefinition() ); assertEquals( 0, dslPattern.getValues().size() ); dslAction.getDefinition() ); assertEquals( 2, dslAction.getValues().size() ); assertTrue( dslAction.getValues().get( 0 ) instanceof DSLVariableValue ); assertTrue( dslAction.getValues().get( 1 ) instanceof DSLVariableValue ); dslAction.getValues().get( 0 ).getValue() ); assertEquals( "myout", dslAction.getValues().get( 1 ).getValue() );
dslPattern.getDefinition() ); assertEquals( 0, dslPattern.getValues().size() ); dslAction.getDefinition() ); assertEquals( 2, dslAction.getValues().size() ); assertTrue( dslAction.getValues().get( 0 ) instanceof DSLVariableValue ); assertTrue( dslAction.getValues().get( 1 ) instanceof DSLVariableValue ); dslAction.getValues().get( 0 ).getValue() ); assertEquals( "myout", dslAction.getValues().get( 1 ).getValue() );