@Test(expected = IllegalArgumentException.class) public void sanitizeTopicFilterFail05() { Topics.sanitizeTopicFilter("abc/def/g/#/h"); }
public static List<String> sanitizeTopicFilter(String topicFilter) { if (StringUtils.isEmpty(topicFilter)) throw new IllegalArgumentException("Empty topic filer"); if (!topicFilter.contains("+") && !topicFilter.contains("#")) throw new IllegalArgumentException("Topic filter does not contain wildcard"); List<String> levels = new ArrayList<>(); if (topicFilter.startsWith("/")) topicFilter = EMPTY + topicFilter; if (topicFilter.endsWith("/")) topicFilter = topicFilter + EMPTY; String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicFilter, "/"); for (int i = 0; i < tokens.length; i++) { if (tokens[i].contains("+") && !tokens[i].equals("+")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].contains("#") && !tokens[i].equals("#")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].equals("#") && !(i == tokens.length - 1 || (i == tokens.length - 2 && END.equals(tokens[i + 1])))) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); levels.add(StringUtils.isNotEmpty(tokens[i]) ? tokens[i] : EMPTY); } if (!topicFilter.endsWith(END)) levels.add(END); return levels; }
Topics { public static List<String> sanitizeTopicFilter(String topicFilter) { if (StringUtils.isEmpty(topicFilter)) throw new IllegalArgumentException("Empty topic filer"); if (!topicFilter.contains("+") && !topicFilter.contains("#")) throw new IllegalArgumentException("Topic filter does not contain wildcard"); List<String> levels = new ArrayList<>(); if (topicFilter.startsWith("/")) topicFilter = EMPTY + topicFilter; if (topicFilter.endsWith("/")) topicFilter = topicFilter + EMPTY; String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicFilter, "/"); for (int i = 0; i < tokens.length; i++) { if (tokens[i].contains("+") && !tokens[i].equals("+")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].contains("#") && !tokens[i].equals("#")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].equals("#") && !(i == tokens.length - 1 || (i == tokens.length - 2 && END.equals(tokens[i + 1])))) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); levels.add(StringUtils.isNotEmpty(tokens[i]) ? tokens[i] : EMPTY); } if (!topicFilter.endsWith(END)) levels.add(END); return levels; } }
Topics { public static List<String> sanitizeTopicFilter(String topicFilter) { if (StringUtils.isEmpty(topicFilter)) throw new IllegalArgumentException("Empty topic filer"); if (!topicFilter.contains("+") && !topicFilter.contains("#")) throw new IllegalArgumentException("Topic filter does not contain wildcard"); List<String> levels = new ArrayList<>(); if (topicFilter.startsWith("/")) topicFilter = EMPTY + topicFilter; if (topicFilter.endsWith("/")) topicFilter = topicFilter + EMPTY; String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicFilter, "/"); for (int i = 0; i < tokens.length; i++) { if (tokens[i].contains("+") && !tokens[i].equals("+")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].contains("#") && !tokens[i].equals("#")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].equals("#") && !(i == tokens.length - 1 || (i == tokens.length - 2 && END.equals(tokens[i + 1])))) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); levels.add(StringUtils.isNotEmpty(tokens[i]) ? tokens[i] : EMPTY); } if (!topicFilter.endsWith(END)) levels.add(END); return levels; } private  Topics(); }
Topics { public static List<String> sanitizeTopicFilter(String topicFilter) { if (StringUtils.isEmpty(topicFilter)) throw new IllegalArgumentException("Empty topic filer"); if (!topicFilter.contains("+") && !topicFilter.contains("#")) throw new IllegalArgumentException("Topic filter does not contain wildcard"); List<String> levels = new ArrayList<>(); if (topicFilter.startsWith("/")) topicFilter = EMPTY + topicFilter; if (topicFilter.endsWith("/")) topicFilter = topicFilter + EMPTY; String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicFilter, "/"); for (int i = 0; i < tokens.length; i++) { if (tokens[i].contains("+") && !tokens[i].equals("+")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].contains("#") && !tokens[i].equals("#")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].equals("#") && !(i == tokens.length - 1 || (i == tokens.length - 2 && END.equals(tokens[i + 1])))) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); levels.add(StringUtils.isNotEmpty(tokens[i]) ? tokens[i] : EMPTY); } if (!topicFilter.endsWith(END)) levels.add(END); return levels; } private  Topics(); static String antidote(String topic); static String antidote(List<String> topicLevels); static List<String> sanitize(String topic); static List<String> sanitizeTopicName(String topicName); static List<String> sanitizeTopicFilter(String topicFilter); static boolean isTopicFilter(List<String> topicLevels); }
Topics { public static List<String> sanitizeTopicFilter(String topicFilter) { if (StringUtils.isEmpty(topicFilter)) throw new IllegalArgumentException("Empty topic filer"); if (!topicFilter.contains("+") && !topicFilter.contains("#")) throw new IllegalArgumentException("Topic filter does not contain wildcard"); List<String> levels = new ArrayList<>(); if (topicFilter.startsWith("/")) topicFilter = EMPTY + topicFilter; if (topicFilter.endsWith("/")) topicFilter = topicFilter + EMPTY; String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicFilter, "/"); for (int i = 0; i < tokens.length; i++) { if (tokens[i].contains("+") && !tokens[i].equals("+")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].contains("#") && !tokens[i].equals("#")) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); if (tokens[i].equals("#") && !(i == tokens.length - 1 || (i == tokens.length - 2 && END.equals(tokens[i + 1])))) throw new IllegalArgumentException("Illegal topic filter: " + topicFilter); levels.add(StringUtils.isNotEmpty(tokens[i]) ? tokens[i] : EMPTY); } if (!topicFilter.endsWith(END)) levels.add(END); return levels; } private  Topics(); static String antidote(String topic); static String antidote(List<String> topicLevels); static List<String> sanitize(String topic); static List<String> sanitizeTopicName(String topicName); static List<String> sanitizeTopicFilter(String topicFilter); static boolean isTopicFilter(List<String> topicLevels); static final String EMPTY; static final String END; }