Пример #1
0
  /**
   * @param filter the filter
   * @param element the element to match
   * @return true if the element is matched by the filer
   * @since 7.0M2
   */
  public static boolean matches(Filter filter, Object element) {
    // TODO: add support for more than String
    String filterValue = filter.getValue() != null ? String.valueOf(filter.getValue()) : null;
    String elementValue = element != null ? String.valueOf(element) : null;

    if (filter.getComparison() == COMPARISON.MATCH) {
      Pattern patternMatcher = createPatternMatcher(filterValue);

      if (matches(patternMatcher, filterValue)) {
        return true;
      }
    } else if (filter.getComparison() == COMPARISON.EQUAL) {
      if (elementValue != null && filterValue.toLowerCase().equals(elementValue.toLowerCase())) {
        return true;
      }
    }

    return false;
  }
Пример #2
0
  /**
   * @param filter the filter
   * @param extension the extension to match
   * @return true if the extension is matched by the filer
   * @since 7.0M2
   */
  public static boolean matches(Filter filter, Extension extension) {
    Object value = extension.get(filter.getField());

    if (value != null) {
      return matches(filter, value);
    }

    // Unknown field
    // FIXME: not sure if it's should be true or false in this case
    return true;
  }