ComplexSearchUtils { public static Pair<String, BigDecimal> checkNumericSearch(String filter, char[] binarySortedPrefixes, int precision) { if (filter.length() > 1 && Arrays.binarySearch(binarySortedPrefixes, filter.charAt(0)) >= 0) { try { final BigDecimal qty = new BigDecimal(filter.substring(1).trim()).setScale(precision, BigDecimal.ROUND_CEILING); if (qty.signum() == -1) { return null; } return new Pair<>(filter.substring(0, 1), qty); } catch (Exception exp) { return null; } } return null; } private  ComplexSearchUtils(); static Pair<String, String> checkSpecialSearch(String filter, char[] binarySortedPrefixes); static Pair<String, BigDecimal> checkNumericSearch(String filter, char[] binarySortedPrefixes, int precision); static Pair<LocalDateTime, LocalDateTime> checkDateRangeSearch(String filter);  }
@Test public void testCheckNumericSearch() throws Exception { assertNull(ComplexSearchUtils.checkNumericSearch("a", new char[] { '-' }, 2)); assertNull(ComplexSearchUtils.checkNumericSearch("abc", new char[] { '-' }, 2)); assertNull(ComplexSearchUtils.checkNumericSearch("-", new char[] { '-' }, 2)); assertNull(ComplexSearchUtils.checkNumericSearch("--", new char[] { '-' }, 2)); assertNull(ComplexSearchUtils.checkNumericSearch("-a", new char[] { '-' }, 2)); assertNull(ComplexSearchUtils.checkNumericSearch("-1f", new char[]{'-'}, 2)); Pair<String, BigDecimal> search; search = ComplexSearchUtils.checkNumericSearch("-1", new char[]{ '+', '-' }, 2); assertNotNull(search); assertEquals("-", search.getFirst()); assertEquals("1.00", search.getSecond().toPlainString()); search = ComplexSearchUtils.checkNumericSearch("-1.001", new char[]{ '+', '-' }, 2); assertNotNull(search); assertEquals("-", search.getFirst()); assertEquals("1.01", search.getSecond().toPlainString()); search = ComplexSearchUtils.checkNumericSearch("+1", new char[] { '+', '-' }, 3); assertNotNull(search); assertEquals("+", search.getFirst()); assertEquals("1.000", search.getSecond().toPlainString()); search = ComplexSearchUtils.checkNumericSearch("+ 1 ", new char[] { '+', '-' }, 3); assertNotNull(search); assertEquals("+", search.getFirst()); assertEquals("1.000", search.getSecond().toPlainString()); }