Beispiel #1
0
  /**
   * Determines a relative order for the provided filter objects.
   *
   * @param f1 The first filter for which to make the determination.
   * @param f2 The second filter for which to make the determination.
   * @return A negative value if the first filter should be ordered before the second, a positive
   *     value if the first filter should be ordered after the second, or zero if there is no
   *     difference in their relative orders.
   */
  public int compare(final Filter f1, final Filter f2) {
    final byte type1 = f1.getFilterType();
    final byte type2 = f2.getFilterType();

    if (type1 != type2) {
      return ((type1 & 0x1F) - (type2 & 0x1F));
    }

    final String name1 = toLowerCase(f1.getAttributeName());
    final String name2 = toLowerCase(f2.getAttributeName());
    if ((name1 != null) && (name2 != null)) {
      final int cmpValue = name1.compareTo(name2);
      if (cmpValue != 0) {
        return cmpValue;
      }
    }

    final byte[] value1 = f1.getAssertionValueBytes();
    if (value1 != null) {
      final byte[] value2 = f2.getAssertionValueBytes();
      final int cmpValue = compare(value1, value2);
      if (cmpValue != 0) {
        return cmpValue;
      }
    }

    switch (type1) {
      case Filter.FILTER_TYPE_AND:
      case Filter.FILTER_TYPE_OR:
        return compareANDOrOR(f1, f2);

      case Filter.FILTER_TYPE_NOT:
        return compare(f1.getNOTComponent(), f2.getNOTComponent());

      case Filter.FILTER_TYPE_PRESENCE:
      case Filter.FILTER_TYPE_EQUALITY:
      case Filter.FILTER_TYPE_GREATER_OR_EQUAL:
      case Filter.FILTER_TYPE_LESS_OR_EQUAL:
      case Filter.FILTER_TYPE_APPROXIMATE_MATCH:
        // The necessary processing for these types has already been done.
        return 0;

      case Filter.FILTER_TYPE_SUBSTRING:
        return compareSubstring(f1, f2);

      case Filter.FILTER_TYPE_EXTENSIBLE_MATCH:
        return compareExtensible(f1, f2);

      default:
        // This should never happen.
        return 0;
    }
  }
Beispiel #2
0
  /**
   * Performs a comparison of the contents of substring filters.
   *
   * @param f1 The first filter for which to make the determination.
   * @param f2 The second filter for which to make the determination.
   * @return A negative value if the first filter should be ordered before the second, a positive
   *     value if the first filter should be ordered after the second, or zero if there is no
   *     difference in their relative orders.
   */
  private static int compareExtensible(final Filter f1, final Filter f2) {
    final String name1 = f1.getAttributeName();
    final String name2 = f2.getAttributeName();
    if (name1 == null) {
      if (name2 != null) {
        return -1;
      }
    } else if (name2 == null) {
      return 1;
    }

    final String mr1 = f1.getMatchingRuleID();
    final String mr2 = f2.getMatchingRuleID();
    if (mr1 == null) {
      if (mr2 != null) {
        return -1;
      }
    } else if (mr2 == null) {
      return 1;
    } else {
      final int cmpValue = mr1.compareTo(mr2);
      if (cmpValue != 0) {
        return cmpValue;
      }
    }

    if (f1.getDNAttributes()) {
      if (f2.getDNAttributes()) {
        return 0;
      } else {
        return 1;
      }
    } else if (f2.getDNAttributes()) {
      return -1;
    } else {
      return 0;
    }
  }