Esempio n. 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;
    }
  }
Esempio n. 2
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 only the first match.
   *
   * @param Group The Regular expression group to search
   * @param Parameters The list of fields to search
   * @return Result The result of the search as a SearchMap object
   */
  private SearchMap getMatchingSearchResult(String Group, String[] Parameters) {
    int i;
    SearchGroup tmpSearchGroup;
    SearchMap tmpSearchMap;
    Pattern tmpPattern;
    boolean Found;
    double tmpParamValue;

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

    if (tmpSearchGroup == null) {
      // Return a default value
      return null;
    } 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 (Parameters[i] == null) {
                  // we cannot match on null values - warn once and out...
                  OpenRate.getOpenRateFrameworkLog()
                      .warning(
                          "Null value found in regex match on parameter <"
                              + i
                              + "> in module <"
                              + getSymbolicName()
                              + ">");
                  return null;
                }

                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) {
          return tmpSearchMap;
        }
      }

      // Return a default value - we found nothing
      return null;
    }
  }