@Test(expected = ParseException.class) public void testSplitTopicMultiInTheMiddleNotValid() throws ParseException { store.splitTopic("finance/#/closingprice"); }
protected static List<Token> splitTopic(String topic) throws ParseException { List res = new ArrayList<Token>(); String[] splitted = topic.split("/"); if (splitted.length == 0) { res.add(Token.EMPTY); } for (int i = 0; i < splitted.length; i++) { String s = splitted[i]; if (s.isEmpty()) { if (i != 0) { throw new ParseException("Bad format of topic, expetec topic name between separators", i); } res.add(Token.EMPTY); } else if (s.equals("#")) { if (i != splitted.length - 1) { throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i); } res.add(Token.MULTI); } else if (s.contains("#")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else if (s.equals("+")) { res.add(Token.SINGLE); } else if (s.contains("+")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else { res.add(new Token(s)); } } return res; }
SubscriptionsStore { protected static List<Token> splitTopic(String topic) throws ParseException { List res = new ArrayList<Token>(); String[] splitted = topic.split("/"); if (splitted.length == 0) { res.add(Token.EMPTY); } for (int i = 0; i < splitted.length; i++) { String s = splitted[i]; if (s.isEmpty()) { if (i != 0) { throw new ParseException("Bad format of topic, expetec topic name between separators", i); } res.add(Token.EMPTY); } else if (s.equals("#")) { if (i != splitted.length - 1) { throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i); } res.add(Token.MULTI); } else if (s.contains("#")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else if (s.equals("+")) { res.add(Token.SINGLE); } else if (s.contains("+")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else { res.add(new Token(s)); } } return res; } }
SubscriptionsStore { protected static List<Token> splitTopic(String topic) throws ParseException { List res = new ArrayList<Token>(); String[] splitted = topic.split("/"); if (splitted.length == 0) { res.add(Token.EMPTY); } for (int i = 0; i < splitted.length; i++) { String s = splitted[i]; if (s.isEmpty()) { if (i != 0) { throw new ParseException("Bad format of topic, expetec topic name between separators", i); } res.add(Token.EMPTY); } else if (s.equals("#")) { if (i != splitted.length - 1) { throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i); } res.add(Token.MULTI); } else if (s.contains("#")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else if (s.equals("+")) { res.add(Token.SINGLE); } else if (s.contains("+")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else { res.add(new Token(s)); } } return res; }  }
SubscriptionsStore { protected static List<Token> splitTopic(String topic) throws ParseException { List res = new ArrayList<Token>(); String[] splitted = topic.split("/"); if (splitted.length == 0) { res.add(Token.EMPTY); } for (int i = 0; i < splitted.length; i++) { String s = splitted[i]; if (s.isEmpty()) { if (i != 0) { throw new ParseException("Bad format of topic, expetec topic name between separators", i); } res.add(Token.EMPTY); } else if (s.equals("#")) { if (i != splitted.length - 1) { throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i); } res.add(Token.MULTI); } else if (s.contains("#")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else if (s.equals("+")) { res.add(Token.SINGLE); } else if (s.contains("+")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else { res.add(new Token(s)); } } return res; }  void init(IStorageService storageService); void add(Subscription newSubscription); void removeSubscription(String topic, String clientID); void clearAllSubscriptions(); void removeForClient(String clientID); void deactivate(String clientID); void activate(String clientID); List<Subscription> matches(String topic); boolean contains(Subscription sub); int size(); String dumpTree(); static boolean matchTopics(String msgTopic, String subscriptionTopic); }
SubscriptionsStore { protected static List<Token> splitTopic(String topic) throws ParseException { List res = new ArrayList<Token>(); String[] splitted = topic.split("/"); if (splitted.length == 0) { res.add(Token.EMPTY); } for (int i = 0; i < splitted.length; i++) { String s = splitted[i]; if (s.isEmpty()) { if (i != 0) { throw new ParseException("Bad format of topic, expetec topic name between separators", i); } res.add(Token.EMPTY); } else if (s.equals("#")) { if (i != splitted.length - 1) { throw new ParseException("Bad format of topic, the multi symbol (#) has to be the last one after a separator", i); } res.add(Token.MULTI); } else if (s.contains("#")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else if (s.equals("+")) { res.add(Token.SINGLE); } else if (s.contains("+")) { throw new ParseException("Bad format of topic, invalid subtopic name: " + s, i); } else { res.add(new Token(s)); } } return res; }  void init(IStorageService storageService); void add(Subscription newSubscription); void removeSubscription(String topic, String clientID); void clearAllSubscriptions(); void removeForClient(String clientID); void deactivate(String clientID); void activate(String clientID); List<Subscription> matches(String topic); boolean contains(Subscription sub); int size(); String dumpTree(); static boolean matchTopics(String msgTopic, String subscriptionTopic);  }