GenericCharPatternRecognizer extends AbstractPatternRecognizer { @Override public RecognitionResult recognize(String stringToRecognize, DataTypeEnum type) { RecognitionResult result = new RecognitionResult(); if (StringUtils.isEmpty(stringToRecognize)) { result.setResult(Collections.singleton(stringToRecognize), false); return result; } String pattern = TextPatternUtil.findPattern(stringToRecognize); result.setResult(Collections.singleton(pattern), true); return result; }  @Override RecognitionResult recognize(String stringToRecognize, DataTypeEnum type); @Override Set<String> getValuePattern(String originalValue);  }
@Test public void testRecognize() { RecognitionResult result = recognizer.recognize(""); Assert.assertFalse(result.isComplete()); Assert.assertEquals(Collections.singleton(""), result.getPatternStringSet()); RecognitionResult result2 = recognizer.recognize(" "); Assert.assertTrue(result2.isComplete()); Assert.assertEquals(Collections.singleton(" "), result2.getPatternStringSet()); RecognitionResult result3 = recognizer.recognize(null); Assert.assertFalse(result3.isComplete()); Assert.assertEquals(Collections.singleton(null), result3.getPatternStringSet()); String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞß0123456789"; String replChars = "aaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa9999999999"; checkPattern(chars, replChars, true, recognizer); checkPattern("abcィd", "aaaKa", true, recognizer); checkPattern("abc-d", "aaa-a", true, recognizer); checkPattern("Straße", "Aaaaaa", true, recognizer); checkPattern("トｩンキン", "KkKKK", true, recognizer); checkPattern("とうきょう", "HHHHH", true, recognizer); checkPattern("서울", "GG", true, recognizer); checkPattern("北京", "CC", true, recognizer); Map<String, String> str2Pattern = new HashMap<>(); str2Pattern.put("*-!", "*-!"); str2Pattern.put("1-3", "9-9"); str2Pattern.put("2001-9-10 - 2009-09-08", "9999-9-99 - 9999-99-99"); str2Pattern.put("22. fdsud 1975", "99. aaaaa 9999"); testRecognition(str2Pattern); str2Pattern.clear(); str2Pattern.put("2001-8-20", "yyyy-M-d"); str2Pattern.put("22. july 1975", "d. MMMM yyyy"); testDateRecognition(str2Pattern); }