@Test public void testEmptyContent() { SearchingPatternBuilder pattenBuilder = new SearchingPatternBuilder(); pattenBuilder.add("\\d{3}[-\\.\\s]\\d{3}[-\\.\\s]\\d{4},-,3,8,-,7,4", PrivateDataType.regex_phone_number.name()); SearchingContent content = new SearchingContent(null); SearchingResult result = searchingHandler.search(pattenBuilder.build(), content); assertNotNull(result); assertEquals(0, result.getWords().size()); }
@Override public SearchingResult search(SearchingPattern pattern, SearchingContent content) { SearchingResultBuilder resultBuilder = new SearchingResultBuilder(); if (!isValidPattern(pattern) || !isValidContent(content)) { return resultBuilder.build(); } Map<Character, List<PatternInfo>> pivotCharMap = initPivotCharMap(pattern); String text = content.get(); for(int i = 0; i < text.length(); i++) { char pivotChar = text.charAt(i); if (!hasRelatedPattern(pivotChar, pivotCharMap)) { continue; } List<PatternInfo> relatedPattern = pivotCharMap.get(pivotChar); for(PatternInfo info : relatedPattern) { if (isValidCandidatePattern(info, text, i)) { String candidate = getValidCandidatePattern(info, pivotChar, text, i); if (candidate == null) { continue; } if (compare(candidate, info)) { resultBuilder.add(candidate, info.getType()); } } } } return resultBuilder.build(); }
PatternSearchingHandler implements ISearchingHandler { @Override public SearchingResult search(SearchingPattern pattern, SearchingContent content) { SearchingResultBuilder resultBuilder = new SearchingResultBuilder(); if (!isValidPattern(pattern) || !isValidContent(content)) { return resultBuilder.build(); } Map<Character, List<PatternInfo>> pivotCharMap = initPivotCharMap(pattern); String text = content.get(); for(int i = 0; i < text.length(); i++) { char pivotChar = text.charAt(i); if (!hasRelatedPattern(pivotChar, pivotCharMap)) { continue; } List<PatternInfo> relatedPattern = pivotCharMap.get(pivotChar); for(PatternInfo info : relatedPattern) { if (isValidCandidatePattern(info, text, i)) { String candidate = getValidCandidatePattern(info, pivotChar, text, i); if (candidate == null) { continue; } if (compare(candidate, info)) { resultBuilder.add(candidate, info.getType()); } } } } return resultBuilder.build(); } }
PatternSearchingHandler implements ISearchingHandler { @Override public SearchingResult search(SearchingPattern pattern, SearchingContent content) { SearchingResultBuilder resultBuilder = new SearchingResultBuilder(); if (!isValidPattern(pattern) || !isValidContent(content)) { return resultBuilder.build(); } Map<Character, List<PatternInfo>> pivotCharMap = initPivotCharMap(pattern); String text = content.get(); for(int i = 0; i < text.length(); i++) { char pivotChar = text.charAt(i); if (!hasRelatedPattern(pivotChar, pivotCharMap)) { continue; } List<PatternInfo> relatedPattern = pivotCharMap.get(pivotChar); for(PatternInfo info : relatedPattern) { if (isValidCandidatePattern(info, text, i)) { String candidate = getValidCandidatePattern(info, pivotChar, text, i); if (candidate == null) { continue; } if (compare(candidate, info)) { resultBuilder.add(candidate, info.getType()); } } } } return resultBuilder.build(); } PatternSearchingHandler(); }
PatternSearchingHandler implements ISearchingHandler { @Override public SearchingResult search(SearchingPattern pattern, SearchingContent content) { SearchingResultBuilder resultBuilder = new SearchingResultBuilder(); if (!isValidPattern(pattern) || !isValidContent(content)) { return resultBuilder.build(); } Map<Character, List<PatternInfo>> pivotCharMap = initPivotCharMap(pattern); String text = content.get(); for(int i = 0; i < text.length(); i++) { char pivotChar = text.charAt(i); if (!hasRelatedPattern(pivotChar, pivotCharMap)) { continue; } List<PatternInfo> relatedPattern = pivotCharMap.get(pivotChar); for(PatternInfo info : relatedPattern) { if (isValidCandidatePattern(info, text, i)) { String candidate = getValidCandidatePattern(info, pivotChar, text, i); if (candidate == null) { continue; } if (compare(candidate, info)) { resultBuilder.add(candidate, info.getType()); } } } } return resultBuilder.build(); } PatternSearchingHandler(); @Override SearchingResult search(SearchingPattern pattern, SearchingContent content); @Override boolean isValidPattern(SearchingPattern pattern); @Override boolean isValidContent(SearchingContent content); }
PatternSearchingHandler implements ISearchingHandler { @Override public SearchingResult search(SearchingPattern pattern, SearchingContent content) { SearchingResultBuilder resultBuilder = new SearchingResultBuilder(); if (!isValidPattern(pattern) || !isValidContent(content)) { return resultBuilder.build(); } Map<Character, List<PatternInfo>> pivotCharMap = initPivotCharMap(pattern); String text = content.get(); for(int i = 0; i < text.length(); i++) { char pivotChar = text.charAt(i); if (!hasRelatedPattern(pivotChar, pivotCharMap)) { continue; } List<PatternInfo> relatedPattern = pivotCharMap.get(pivotChar); for(PatternInfo info : relatedPattern) { if (isValidCandidatePattern(info, text, i)) { String candidate = getValidCandidatePattern(info, pivotChar, text, i); if (candidate == null) { continue; } if (compare(candidate, info)) { resultBuilder.add(candidate, info.getType()); } } } } return resultBuilder.build(); } PatternSearchingHandler(); @Override SearchingResult search(SearchingPattern pattern, SearchingContent content); @Override boolean isValidPattern(SearchingPattern pattern); @Override boolean isValidContent(SearchingContent content);  }