TimeProcessor implements SearchStringProcessor { @Override public List<String> processSearchString(String searchString) throws IllegalArgumentException, InterruptedException { String space = "\\s{0,2}"; String number_float = space + "\\d{1,10}\\.\\d{1,10}" + space; String number_int = space + "\\d{1,10}" + space; String interval_float = "((" + number_float + "-" + number_float + ")|(" + number_float + "to" + number_float + "))"; String interval_int = "((" + number_int + "-" + number_int + ")|(" + number_int + "to" + number_int + "))"; Pattern pattern_interval_float = Pattern.compile(interval_float); Pattern pattern_interval_int = Pattern.compile(interval_int); Pattern pattern_number_float = Pattern.compile(number_float); Pattern pattern_number_int = Pattern.compile(number_int); String matchedNumber; String processedString = searchString; Matcher matcher_interval_float = pattern_interval_float.matcher(processedString); while (matcher_interval_float.find()) { checkAlive(searchString); matchedNumber = RegexUtils.escapeString(matcher_interval_float.group()); processedString = processedString.replaceFirst(matchedNumber, ""); } Matcher matcher_interval_int = pattern_interval_int.matcher(processedString); while (matcher_interval_int.find()) { checkAlive(searchString); matchedNumber = matcher_interval_int.group(); processedString = processedString.replaceFirst(matchedNumber, ""); } Matcher matcher_number_float = pattern_number_float.matcher(processedString); while (matcher_number_float.find()) { checkAlive(searchString); matchedNumber = matcher_number_float.group(); processedString = processedString.replaceFirst(matchedNumber, ""); } Matcher matcher_number_int = pattern_number_int.matcher(processedString); while (matcher_number_int.find()) { checkAlive(searchString); matchedNumber = matcher_number_int.group(); processedString = processedString.replaceFirst(matchedNumber, ""); } processedString = processedString.trim().replaceAll("\\s+", " "); if (!processedString.isEmpty()) { return Collections.singletonList(processedString); } else { return Collections.emptyList(); } }  @Override float getBoostFactor(); @Override boolean canProcess(String searchString); @Override List<String> processSearchString(String searchString);  }
@Test public void testProcessTimes() { try { List<String> results; results = processor.processSearchString(day); assertEquals(1, results.size()); assertEquals("day", results.get(0)); results = processor.processSearchString(hours); assertEquals(1, results.size()); assertEquals("hours", results.get(0)); results = processor.processSearchString(week); assertEquals(1, results.size()); assertEquals("week", results.get(0)); results = processor.processSearchString(decimal); assertEquals(1, results.size()); assertEquals("days", results.get(0)); results = processor.processSearchString(hyperploidyExample); assertEquals(1, results.size()); assertEquals("hyperdiploidy,-X,-q,+,-,-q,+,+(),+(),+,-q,+,-", results.get(0)); } catch (Exception e) { e.printStackTrace(); fail(); } }