/** * Evaluates the string array against the snippet in the {@link StringMatchingExpression} * instance. * * @param stringValue * string to check * @return boolean evaluation result */ private boolean evaluateString(String stringValue) { switch (getMatchingType()) { case CONTAINS: return stringValue.contains(getSnippet()); case ENDS_WITH: return stringValue.endsWith(getSnippet()); case STARTS_WITH: return stringValue.startsWith(getSnippet()); case EQUALS: return stringValue.equals(getSnippet()); case REGEX: return stringValue.matches(getSnippet()); default: return false; } }
/** * Validates the contents of the passed {@link StringMatchingExpression} without the need to * create corresponding editing controls. * * @param expression * {@link StringMatchingExpression} to validate * @param sourceName * the name of the string snippet source * @return a set of {@link ValidationState} instances. */ public static Set<ValidationState> validate(StringMatchingExpression expression, String sourceName) { Set<ValidationState> resultSet = new HashSet<>(); if (StringUtils.isBlank(expression.getSnippet())) { resultSet.add(new ValidationState(STRING_SNIPPET_VALIDATOR_ID, false, sourceName + " must not be empty!")); } return resultSet; }
/** * {@inheritDoc} */ @Override protected void executeSpecificInitialization(StringMatchingExpression expression) { super.executeSpecificInitialization(expression); int index = 0; for (String opt : stringValueSource.getOptions()) { if (opt.equals(expression.getSnippet())) { break; } index++; } if (index < stringValueSource.getOptions().length) { valueComboBox.select(index); } } }
/** * * {@inheritDoc} */ @Override protected void executeSpecificInitialization(StringMatchingExpression expression) { if (isValidExpression(expression)) { super.executeSpecificInitialization(expression); for (int i = 0; i < PatternMatchingType.values().length; i++) { if (PatternMatchingType.values()[i].equals(expression.getMatchingType())) { patternMatchingTypeComboBox.select(i); } } stringSnippetText.setText(expression.getSnippet()); } }