Пример #1
0
  /**
   * Evaluate an input against the search group. This is the generalised from which you may want to
   * create specialised versions for a defined number of parameters, for reasons of performance.
   *
   * <p>This function returns all of the entries that are matched, in priority order. This is useful
   * for aggregation processing etc.
   *
   * @param Group The Regex group to search
   * @param Parameters The list of fields to search
   * @return List of all matches
   */
  public ArrayList<String> getAllEntries(String Group, String[] Parameters) {
    int i;
    SearchGroup tmpSearchGroup;
    SearchMap tmpSearchMap;
    Pattern tmpPattern;
    boolean found;
    double tmpParamValue;
    ArrayList<String> matches;

    matches = new ArrayList<>();

    // recover the object
    tmpSearchGroup = GroupCache.get(Group);

    if (tmpSearchGroup == null) {
      // Return a default value, we did not find the group
      return matches;
    } else {
      // Iterate thorough the entries in the group
      Iterator<SearchMap> GroupIter = tmpSearchGroup.SearchGroup.listIterator();

      while (GroupIter.hasNext()) {
        tmpSearchMap = GroupIter.next();

        // Initialise the found flag and the counter
        found = true;
        i = 0;

        // Now check the elements of the map
        while ((i < Parameters.length) & found) {
          switch (tmpSearchMap.matchType[i]) {
              // Regex inclusion case
            case 0:
              {
                tmpPattern = tmpSearchMap.matchPattern[i];

                if (!tmpPattern.matcher(Parameters[i]).matches()) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }

              // Regex exclusion case
            case 6:
              {
                tmpPattern = tmpSearchMap.matchPattern[i];

                if (tmpPattern.matcher(Parameters[i]).matches()) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }

              // "=" case
            case 1:
              {
                tmpParamValue = Double.parseDouble(Parameters[i]);
                if (tmpSearchMap.matchValue[i] != tmpParamValue) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }

              // ">" case
            case 2:
              {
                tmpParamValue = Double.parseDouble(Parameters[i]);
                if (tmpParamValue <= tmpSearchMap.matchValue[i]) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }

              // "<" case
            case 3:
              {
                tmpParamValue = Double.parseDouble(Parameters[i]);
                if (tmpParamValue >= tmpSearchMap.matchValue[i]) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }

              // ">=" case
            case 4:
              {
                tmpParamValue = Double.parseDouble(Parameters[i]);
                if (tmpParamValue < tmpSearchMap.matchValue[i]) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }

              // "<=" case
            case 5:
              {
                tmpParamValue = Double.parseDouble(Parameters[i]);
                if (tmpParamValue > tmpSearchMap.matchValue[i]) {
                  // We did not get a match, move on
                  found = false;
                }
                break;
              }
          }

          // Increment the loop counter
          i++;
        }

        if (found) {
          matches.add(tmpSearchMap.Results.get(0));
        }
      }

      return matches;
    }
  }