@Test public void noDefinition() throws Exception { NonBreakPointsLoader nullLoader = new NonBreakPointsLoader() { @Override public List<String> loadNBSP(String lang) { return null; } }; assertEquals("some text with spaces", new NonBreakPointsEnhancer(nullLoader).enhance("some text with spaces", "cs")); }
public String enhance(String input, String lang) { if (input == null) return null; if (input.isEmpty()) return ""; if (lang == null || lang.isEmpty()) return input; List<String> rules = loader.loadNBSP(lang); if (rules == null) return input; for (String r : rules) { Matcher m = Pattern.compile(r).matcher(input); if (m.groupCount() != 3) { throw new IllegalArgumentException("Expression must contain exactly 3 groups! " + r); } if (m.find()) { input = m.replaceAll("$1\u00A0$3"); } } return input; }
NonBreakPointsEnhancer { public String enhance(String input, String lang) { if (input == null) return null; if (input.isEmpty()) return ""; if (lang == null || lang.isEmpty()) return input; List<String> rules = loader.loadNBSP(lang); if (rules == null) return input; for (String r : rules) { Matcher m = Pattern.compile(r).matcher(input); if (m.groupCount() != 3) { throw new IllegalArgumentException("Expression must contain exactly 3 groups! " + r); } if (m.find()) { input = m.replaceAll("$1\u00A0$3"); } } return input; } }
NonBreakPointsEnhancer { public String enhance(String input, String lang) { if (input == null) return null; if (input.isEmpty()) return ""; if (lang == null || lang.isEmpty()) return input; List<String> rules = loader.loadNBSP(lang); if (rules == null) return input; for (String r : rules) { Matcher m = Pattern.compile(r).matcher(input); if (m.groupCount() != 3) { throw new IllegalArgumentException("Expression must contain exactly 3 groups! " + r); } if (m.find()) { input = m.replaceAll("$1\u00A0$3"); } } return input; } NonBreakPointsEnhancer();   NonBreakPointsEnhancer(NonBreakPointsLoader loader); }
NonBreakPointsEnhancer { public String enhance(String input, String lang) { if (input == null) return null; if (input.isEmpty()) return ""; if (lang == null || lang.isEmpty()) return input; List<String> rules = loader.loadNBSP(lang); if (rules == null) return input; for (String r : rules) { Matcher m = Pattern.compile(r).matcher(input); if (m.groupCount() != 3) { throw new IllegalArgumentException("Expression must contain exactly 3 groups! " + r); } if (m.find()) { input = m.replaceAll("$1\u00A0$3"); } } return input; } NonBreakPointsEnhancer();   NonBreakPointsEnhancer(NonBreakPointsLoader loader); String enhance(String input, String lang); }
NonBreakPointsEnhancer { public String enhance(String input, String lang) { if (input == null) return null; if (input.isEmpty()) return ""; if (lang == null || lang.isEmpty()) return input; List<String> rules = loader.loadNBSP(lang); if (rules == null) return input; for (String r : rules) { Matcher m = Pattern.compile(r).matcher(input); if (m.groupCount() != 3) { throw new IllegalArgumentException("Expression must contain exactly 3 groups! " + r); } if (m.find()) { input = m.replaceAll("$1\u00A0$3"); } } return input; } NonBreakPointsEnhancer();   NonBreakPointsEnhancer(NonBreakPointsLoader loader); String enhance(String input, String lang);  }