/** Dumps the entire contents of the cache to the Log. */ protected void DumpMapData() { String Helper; Iterator<String> GroupIter; Iterator<SearchMap> PatternIterator; Iterator<String> CDIterator; SearchGroup tmpSearchGroup; SearchMap tmpSearchMap; String PrintHelper; int counter = 0; OpenRate.getOpenRateFrameworkLog() .info("Dumping Map Data for RegexMatchCache <" + getSymbolicName() + ">"); OpenRate.getOpenRateFrameworkLog().info("Groups:"); // Iterate thorough the entries in the group GroupIter = GroupCache.keySet().iterator(); while (GroupIter.hasNext()) { Helper = GroupIter.next(); OpenRate.getOpenRateFrameworkLog().info(" " + Helper); } // Now dump the data GroupIter = GroupCache.keySet().iterator(); while (GroupIter.hasNext()) { Helper = GroupIter.next(); OpenRate.getOpenRateFrameworkLog().info("Dumping group map data for <" + Helper + ">"); tmpSearchGroup = GroupCache.get(Helper); PatternIterator = tmpSearchGroup.SearchGroup.iterator(); while (PatternIterator.hasNext()) { OpenRate.getOpenRateFrameworkLog().info("===ENTRY " + counter + "==="); counter++; PrintHelper = " ("; tmpSearchMap = PatternIterator.next(); for (int i = 0; i < tmpSearchMap.matchPattern.length; i++) { PrintHelper = PrintHelper + "[" + tmpSearchMap.matchType[i] + ":" + tmpSearchMap.matchPattern[i] + ":" + tmpSearchMap.matchValue[i] + "] "; } // dump the result array PrintHelper += ") --> ("; CDIterator = tmpSearchMap.Results.iterator(); while (CDIterator.hasNext()) { PrintHelper = PrintHelper + CDIterator.next() + ","; } PrintHelper += ")"; OpenRate.getOpenRateFrameworkLog().info(PrintHelper); } } }
/** * 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; } }