/** * @param accountNumber * @return true if the given account number matches the account number ranges of this row. */ public boolean doesMatch(final int accountNumber) { return config.getAccountNumberRanges().doesMatch(accountNumber); }
/** * The number ranges of the account numbers for the creditors, e. g. "10000-12999". * @return the creditorsAccountNumberRanges */ public IntRanges getCreditorsAccountNumberRanges() { return (IntRanges) new IntRanges(creditorsAccountNumberRangesString).setNullRangeMatchesAlways(true); }
testListSizes(new IntRanges(null), 0, 0); testListSizes(new IntRanges(""), 0, 0); testListSizes(new IntRanges(" "), 0, 0); testListSizes(new IntRanges(", , "), 0, 0); testValueList(new IntRanges("5-7"), (int[]) null); testValueList(new IntRanges("-5"), -5); testValueList(new IntRanges("-5,-5--3,-8,0"), -5, -8, 0); testRangeList(new IntRanges("2,5"), (Range<Integer>[]) null); testRangeList(new IntRanges("2-5"), r(2, 5)); testRangeList(new IntRanges("-2--5"), r(-5, -2)); testRangeList(new IntRanges("-5,-5--3,-8,0"), r(-5, -3)); testRangeList(new IntRanges("2-5,-5--3,-8,0"), r(2, 5), r(-5, -3)); assertEquals("", new IntRanges(null).toString()); assertEquals("1", new IntRanges("1").toString()); assertEquals("-10--5", new IntRanges("-5--10").toString()); assertEquals("2-5,-5--3,-8,0", new IntRanges("2-5,-5--3,-8,0").toString()); assertFalse(new IntRanges("").doesMatch(null)); doesNotMatch(new IntRanges(""), 0, 42, -1); doesMatch(new IntRanges("42"), 42); doesNotMatch(new IntRanges("42"), 0, -1); doesMatch((IntRanges) new IntRanges("").setNullRangeMatchesAlways(true), 0, 42); doesNotMatch(new IntRanges(""), 0, -1);
/** * Extract the account ranges of the configured accountRage at set the ranges. Examples: "4830,4947", "4000-4799" or "6300,6800-6855" */ private synchronized void initialize() { if (initialized == true) { return; } try { accountNumberRanges = new IntRanges(accountRangeConfig); } catch (final Exception ex) { log.warn("Couldn't parse number range of businessAssessmentRow '" + accountRangeConfig + "':" + ex.getMessage(), ex); } initialized = true; } }
private void testValueList(final IntRanges ranges, final int... values) { if (values == null) { assertEquals(0, ranges.getValues().size()); return; } assertEquals(values.length, ranges.getValues().size()); for (int i = 0; i < values.length; i++) { assertEquals(values[i], (int) ranges.getValues().get(i)); } }
private void testRangeList(final IntRanges intRanges, final Range<Integer>... ranges) { if (ranges == null) { assertEquals(0, intRanges.getRanges().size()); return; } assertEquals(ranges.length, intRanges.getRanges().size()); for (int i = 0; i < ranges.length; i++) { final Range<Integer> range = intRanges.getRanges().get(i); assertEquals(ranges[i].getMinValue(), range.getMinValue()); assertEquals(ranges[i].getMaxValue(), range.getMaxValue()); } }
assertEquals(0, row.getAccountNumberRanges().getValues().size()); assertEquals(1, row.getAccountNumberRanges().getRanges().size()); final Range<Integer> range = row.getAccountNumberRanges().getRanges().get(0); assertEquals(5700, (int) range.getMinValue()); assertEquals(5999, (int) range.getMaxValue()); assertEquals(1, row.getAccountNumberRanges().getValues().size()); assertEquals(6300, (int) row.getAccountNumberRanges().getValues().get(0)); assertEquals(1, row.getAccountNumberRanges().getRanges().size()); final Range<Integer> range = row.getAccountNumberRanges().getRanges().get(0); assertEquals(6800, (int) range.getMinValue()); assertEquals(6855, (int) range.getMaxValue()); assertEquals(3, row.getAccountNumberRanges().getValues().size()); assertEquals(6392, (int) row.getAccountNumberRanges().getValues().get(0)); assertEquals(6895, (int) row.getAccountNumberRanges().getValues().get(1)); assertEquals(6960, (int) row.getAccountNumberRanges().getValues().get(2)); assertEquals(0, row.getAccountNumberRanges().getRanges().size()); assertEquals(0, row.getAccountNumberRanges().getValues().size()); assertEquals(0, row.getAccountNumberRanges().getRanges().size());
private void checkExceptions(final String rangesString) { try { testValueList(new IntRanges(rangesString), -5); fail("Exception excepted for string: " + rangesString); } catch (final IllegalArgumentException ex) { // OK } } }
private void doesMatch(final IntRanges ranges, final int... values) { for (final int value : values) { assertTrue(ranges.doesMatch(value)); } }
/** * The number ranges of the account numbers for the debitors, e. g. "10000-12999". * @return the debitorsAccountNumberRanges */ public IntRanges getDebitorsAccountNumberRanges() { return (IntRanges) new IntRanges(debitorsAccountNumberRangesString).setNullRangeMatchesAlways(true); }
private void doesNotMatch(final IntRanges ranges, final int... values) { for (final int value : values) { assertFalse(ranges.doesMatch(value)); } }
@Override protected List<KontoDO> getChoices(final String input) { final BaseSearchFilter filter = new BaseSearchFilter(); filter.setSearchFields("nummer", "bezeichnung", "description"); filter.setSearchString(input); final List<KontoDO> list = kontoDao.getList(filter); if (kontoNumberRanges != null && list != null) { final List<KontoDO> result = new ArrayList<KontoDO>(); for (final KontoDO konto : list) { if (konto.getStatus() == KontoStatus.NONACTIVE) { continue; } if (kontoNumberRanges.doesMatch(konto.getNummer()) == true) { result.add(konto); } } return result; } return list; }