@Test public void test4() { final MatchResult result = matcher.match(0, "14-12-1234"); Assert.assertTrue(result.isMatching()); Assert.assertTrue(result.getMaskIndex(0) == 0); Assert.assertTrue(result.getMaskIndex(1) == 1); Assert.assertTrue(result.getMaskIndex(2) == 2); Assert.assertTrue(result.getMaskIndex(3) == 3); Assert.assertTrue(result.getMaskIndex(4) == 4); Assert.assertTrue(result.getMaskIndex(5) == 5); Assert.assertTrue(result.getMaskIndex(6) == 6); Assert.assertTrue(result.getMaskIndex(7) == 7); Assert.assertTrue(result.getMaskIndex(8) == 8); Assert.assertTrue(result.getMaskIndex(9) == 9); Assert.assertTrue(result.getLastMatch() == 9); }
public MatchResult match(final int startMaskPos, final String input) { if (input == null || input.isEmpty()) { final List<Integer> matchResult = Collections.emptyList(); return new MatchResult(matchResult, 0, true); } final List<Integer> matchResult = new LinkedList<Integer>(); final List<Integer> matchPositions = getMatchPositions(startMaskPos, input.charAt(0)); if (matchPositions.isEmpty()) { return new MatchResult(matchResult, input.length(), false); } else { if (input.length() > 1) { int bestMatchPos = 0; MatchResult bestMatchResult = null; int bestMatchIndex = Integer.MIN_VALUE; for (final Integer matchPos : matchPositions) { final MatchResult result = match((matchPos.intValue() + 1), input.substring(1, input.length())); if (result.isMatching()) { matchResult.add(Integer.valueOf(matchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(result.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), true); } else if (result.getLastMatch() > bestMatchIndex) { bestMatchPos = matchPos; bestMatchResult = result; bestMatchIndex = result.getLastMatch(); } } matchResult.add(Integer.valueOf(bestMatchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(bestMatchResult.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), false); } else { matchResult.add(Integer.valueOf(matchPositions.get(0))); return new MatchResult(matchResult, input.length(), true); } } }
TextMaskMatcher { public MatchResult match(final int startMaskPos, final String input) { if (input == null || input.isEmpty()) { final List<Integer> matchResult = Collections.emptyList(); return new MatchResult(matchResult, 0, true); } final List<Integer> matchResult = new LinkedList<Integer>(); final List<Integer> matchPositions = getMatchPositions(startMaskPos, input.charAt(0)); if (matchPositions.isEmpty()) { return new MatchResult(matchResult, input.length(), false); } else { if (input.length() > 1) { int bestMatchPos = 0; MatchResult bestMatchResult = null; int bestMatchIndex = Integer.MIN_VALUE; for (final Integer matchPos : matchPositions) { final MatchResult result = match((matchPos.intValue() + 1), input.substring(1, input.length())); if (result.isMatching()) { matchResult.add(Integer.valueOf(matchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(result.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), true); } else if (result.getLastMatch() > bestMatchIndex) { bestMatchPos = matchPos; bestMatchResult = result; bestMatchIndex = result.getLastMatch(); } } matchResult.add(Integer.valueOf(bestMatchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(bestMatchResult.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), false); } else { matchResult.add(Integer.valueOf(matchPositions.get(0))); return new MatchResult(matchResult, input.length(), true); } } } }
TextMaskMatcher { public MatchResult match(final int startMaskPos, final String input) { if (input == null || input.isEmpty()) { final List<Integer> matchResult = Collections.emptyList(); return new MatchResult(matchResult, 0, true); } final List<Integer> matchResult = new LinkedList<Integer>(); final List<Integer> matchPositions = getMatchPositions(startMaskPos, input.charAt(0)); if (matchPositions.isEmpty()) { return new MatchResult(matchResult, input.length(), false); } else { if (input.length() > 1) { int bestMatchPos = 0; MatchResult bestMatchResult = null; int bestMatchIndex = Integer.MIN_VALUE; for (final Integer matchPos : matchPositions) { final MatchResult result = match((matchPos.intValue() + 1), input.substring(1, input.length())); if (result.isMatching()) { matchResult.add(Integer.valueOf(matchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(result.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), true); } else if (result.getLastMatch() > bestMatchIndex) { bestMatchPos = matchPos; bestMatchResult = result; bestMatchIndex = result.getLastMatch(); } } matchResult.add(Integer.valueOf(bestMatchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(bestMatchResult.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), false); } else { matchResult.add(Integer.valueOf(matchPositions.get(0))); return new MatchResult(matchResult, input.length(), true); } } } TextMaskMatcher(final ITextMask textMask); }
TextMaskMatcher { public MatchResult match(final int startMaskPos, final String input) { if (input == null || input.isEmpty()) { final List<Integer> matchResult = Collections.emptyList(); return new MatchResult(matchResult, 0, true); } final List<Integer> matchResult = new LinkedList<Integer>(); final List<Integer> matchPositions = getMatchPositions(startMaskPos, input.charAt(0)); if (matchPositions.isEmpty()) { return new MatchResult(matchResult, input.length(), false); } else { if (input.length() > 1) { int bestMatchPos = 0; MatchResult bestMatchResult = null; int bestMatchIndex = Integer.MIN_VALUE; for (final Integer matchPos : matchPositions) { final MatchResult result = match((matchPos.intValue() + 1), input.substring(1, input.length())); if (result.isMatching()) { matchResult.add(Integer.valueOf(matchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(result.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), true); } else if (result.getLastMatch() > bestMatchIndex) { bestMatchPos = matchPos; bestMatchResult = result; bestMatchIndex = result.getLastMatch(); } } matchResult.add(Integer.valueOf(bestMatchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(bestMatchResult.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), false); } else { matchResult.add(Integer.valueOf(matchPositions.get(0))); return new MatchResult(matchResult, input.length(), true); } } } TextMaskMatcher(final ITextMask textMask); MatchResult match(final int startMaskPos, final String input); }
TextMaskMatcher { public MatchResult match(final int startMaskPos, final String input) { if (input == null || input.isEmpty()) { final List<Integer> matchResult = Collections.emptyList(); return new MatchResult(matchResult, 0, true); } final List<Integer> matchResult = new LinkedList<Integer>(); final List<Integer> matchPositions = getMatchPositions(startMaskPos, input.charAt(0)); if (matchPositions.isEmpty()) { return new MatchResult(matchResult, input.length(), false); } else { if (input.length() > 1) { int bestMatchPos = 0; MatchResult bestMatchResult = null; int bestMatchIndex = Integer.MIN_VALUE; for (final Integer matchPos : matchPositions) { final MatchResult result = match((matchPos.intValue() + 1), input.substring(1, input.length())); if (result.isMatching()) { matchResult.add(Integer.valueOf(matchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(result.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), true); } else if (result.getLastMatch() > bestMatchIndex) { bestMatchPos = matchPos; bestMatchResult = result; bestMatchIndex = result.getLastMatch(); } } matchResult.add(Integer.valueOf(bestMatchPos)); for (int i = 0; i < input.length() - 1; i++) { matchResult.add(Integer.valueOf(bestMatchResult.getMaskIndex(i))); } return new MatchResult(matchResult, input.length(), false); } else { matchResult.add(Integer.valueOf(matchPositions.get(0))); return new MatchResult(matchResult, input.length(), true); } } } TextMaskMatcher(final ITextMask textMask); MatchResult match(final int startMaskPos, final String input);  }