public static Collection<InterpolationVariable> extractInterpolationVariables(final String text) { if (text == null || text.length() == 0) { return Collections.emptyList(); } List<InterpolationVariable> interpolationVariableList = new ArrayList<>(); int pos = 0; while ((pos = text.indexOf("@{", pos)) != -1) { int end = text.indexOf('}', pos + 2); if (end != -1) { String varName = text.substring(pos + 2, end); pos = end + 1; InterpolationVariable var = new InterpolationVariable(varName, DataType.TYPE_OBJECT); interpolationVariableList.add(var); } else { break; } } return interpolationVariableList; }
private void extractInterpolationVariablesAbstractActionMultiConstraintBendableMatch(final AbstractActionMultiConstraintBendableMatch constraintMatch) { Collection<InterpolationVariable> interpolationVariables = constraintMatch.extractInterpolationVariables(); assertEquals(2, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); }
@Test public void extractInterpolationVariablesContainsVariables() { String string = "foo bar @{var1} baz @{var2}"; Collection<InterpolationVariable> interpolationVariables = TemplateUtils.extractInterpolationVariables(string); assertEquals(2, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); }
private void extractInterpolationVariablesAbstractActionConstraintMatch(final AbstractActionConstraintMatch constraintMatch) { Collection<InterpolationVariable> interpolationVariables = constraintMatch.extractInterpolationVariables(); assertEquals(1, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); }
@Test public void extractInterpolationVariablesActionMultiConstraintHardSoftMatch() { ActionHardConstraintMatch hardConstraintMatch = new ActionHardConstraintMatch("foo bar @{var1}"); ActionSoftConstraintMatch softConstraintMatch = new ActionSoftConstraintMatch("foo bar @{var2}"); ActionMultiConstraintHardSoftMatch multiConstraintHardSoftMatch = new ActionMultiConstraintHardSoftMatch(hardConstraintMatch, softConstraintMatch); Collection<InterpolationVariable> interpolationVariables = multiConstraintHardSoftMatch.extractInterpolationVariables(); assertEquals(2, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); }
@Test public void extractInterpolationVariablesActionMultiConstraintHardMediumSoftMatch() { ActionHardConstraintMatch hardConstraintMatch = new ActionHardConstraintMatch("foo bar @{var1}"); ActionMediumConstraintMatch mediumConstraintMatch = new ActionMediumConstraintMatch("foo bar @{var2}"); ActionSoftConstraintMatch softConstraintMatch = new ActionSoftConstraintMatch("foo bar @{var3}"); ActionMultiConstraintHardMediumSoftMatch multiConstraintHardSoftMatch = new ActionMultiConstraintHardMediumSoftMatch(hardConstraintMatch, mediumConstraintMatch, softConstraintMatch); Collection<InterpolationVariable> interpolationVariables = multiConstraintHardSoftMatch.extractInterpolationVariables(); assertEquals(3, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var3", DataType.TYPE_OBJECT))); }
private void parseStringPattern(final String text) { if (text == null || text.length() == 0) { return; } int pos = 0; while ((pos = text.indexOf("@{", pos)) != -1) { int end = text.indexOf('}', pos + 2); if (end != -1) { final String varName = text.substring(pos + 2, end); pos = end + 1; InterpolationVariable var = new InterpolationVariable(varName, DataType.TYPE_OBJECT); if (!vars.contains(var)) { vars.add(var); } } } }
private Map<InterpolationVariable, Integer> getInterpolationVariables() { Map<InterpolationVariable, Integer> result = new HashMap<InterpolationVariable, Integer>(); new RuleModelVisitor(result).visit(this); InterpolationVariable id = new InterpolationVariable(ID_COLUMN_NAME, DataType.TYPE_NUMERIC_LONG); result.put(id, result.size()); return result; }
@Override public Collection<InterpolationVariable> extractInterpolationVariables() { return Arrays.asList(new InterpolationVariable("test", DataType.TYPE_OBJECT)); }
private void visitActionFieldList(ActionInsertFact afl) { String factType = afl.getFactType(); for (ActionFieldValue afv : afl.getFieldValues()) { InterpolationVariable var = new InterpolationVariable(afv.getValue(), afv.getType(), factType, afv.getField()); if (afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.containsKey(var)) { vars.put(var, vars.size()); } } }
private void visitActionFieldList(ActionUpdateField afl) { String factType = model.getLHSBindingType(afl.getVariable()); for (ActionFieldValue afv : afl.getFieldValues()) { InterpolationVariable var = new InterpolationVariable(afv.getValue(), afv.getType(), factType, afv.getField()); if (afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.containsKey(var)) { vars.put(var, vars.size()); } } }
private void visitActionFieldList(ActionSetField afl) { String factType = model.getLHSBindingType(afl.getVariable()); for (ActionFieldValue afv : afl.getFieldValues()) { InterpolationVariable var = new InterpolationVariable(afv.getValue(), afv.getType(), factType, afv.getField()); if (afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.containsKey(var)) { vars.put(var, vars.size()); } } }
private void visitActionFieldList(final ActionInsertFact afl) { String factType = afl.getFactType(); for (ActionFieldValue afv : afl.getFieldValues()) { InterpolationVariable var = new InterpolationVariable(afv.getValue(), afv.getType(), factType, afv.getField()); if (afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.contains(var)) { vars.add(var); } else { hasNonTemplateOutput = true; } } }
private void visitActionFieldList(final ActionSetField afl) { String factType = model.getLHSBindingType(afl.getVariable()); for (ActionFieldValue afv : afl.getFieldValues()) { InterpolationVariable var = new InterpolationVariable(afv.getValue(), afv.getType(), factType, afv.getField()); if (afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.contains(var)) { vars.add(var); } else { hasNonTemplateOutput = true; } } }
private void extractInterpolationVariablesAbstractActionMultiConstraintBendableMatch(final AbstractActionMultiConstraintBendableMatch constraintMatch) { Collection<InterpolationVariable> interpolationVariables = constraintMatch.extractInterpolationVariables(); assertEquals(2, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); }
private void visitActionFieldList(final ActionUpdateField afl) { String factType = model.getLHSBindingType(afl.getVariable()); for (ActionFieldValue afv : afl.getFieldValues()) { InterpolationVariable var = new InterpolationVariable(afv.getValue(), afv.getType(), factType, afv.getField()); if (afv.getNature() == FieldNatureType.TYPE_TEMPLATE && !vars.contains(var)) { vars.add(var); } else { hasNonTemplateOutput = true; } } }
@Test public void extractInterpolationVariablesContainsVariables() { String string = "foo bar @{var1} baz @{var2}"; Collection<InterpolationVariable> interpolationVariables = TemplateUtils.extractInterpolationVariables(string); assertEquals(2, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); }
private void extractInterpolationVariablesAbstractActionConstraintMatch(final AbstractActionConstraintMatch constraintMatch) { Collection<InterpolationVariable> interpolationVariables = constraintMatch.extractInterpolationVariables(); assertEquals(1, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); }
@Test public void extractInterpolationVariablesActionMultiConstraintHardSoftMatch() { ActionHardConstraintMatch hardConstraintMatch = new ActionHardConstraintMatch("foo bar @{var1}"); ActionSoftConstraintMatch softConstraintMatch = new ActionSoftConstraintMatch("foo bar @{var2}"); ActionMultiConstraintHardSoftMatch multiConstraintHardSoftMatch = new ActionMultiConstraintHardSoftMatch(hardConstraintMatch, softConstraintMatch); Collection<InterpolationVariable> interpolationVariables = multiConstraintHardSoftMatch.extractInterpolationVariables(); assertEquals(2, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); }
@Test public void extractInterpolationVariablesActionMultiConstraintHardMediumSoftMatch() { ActionHardConstraintMatch hardConstraintMatch = new ActionHardConstraintMatch("foo bar @{var1}"); ActionMediumConstraintMatch mediumConstraintMatch = new ActionMediumConstraintMatch("foo bar @{var2}"); ActionSoftConstraintMatch softConstraintMatch = new ActionSoftConstraintMatch("foo bar @{var3}"); ActionMultiConstraintHardMediumSoftMatch multiConstraintHardSoftMatch = new ActionMultiConstraintHardMediumSoftMatch(hardConstraintMatch, mediumConstraintMatch, softConstraintMatch); Collection<InterpolationVariable> interpolationVariables = multiConstraintHardSoftMatch.extractInterpolationVariables(); assertEquals(3, interpolationVariables.size()); assertTrue(interpolationVariables.contains(new InterpolationVariable("var1", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var2", DataType.TYPE_OBJECT))); assertTrue(interpolationVariables.contains(new InterpolationVariable("var3", DataType.TYPE_OBJECT))); }