@Test public void testLookup() { final Subscription existingSubscription = clientSubOnTopic("TempSensor1", "/temp"); sut.add(existingSubscription); final Optional<CNode> matchedNode = sut.lookup(asTopic("/humidity")); assertFalse("Node on path /humidity can't be present", matchedNode.isPresent()); }
Optional<CNode> lookup(Topic topic) { INode inode = this.root; Token token = topic.headToken(); while (!topic.isEmpty() && (inode.mainNode().anyChildrenMatch(token))) { topic = topic.exceptHeadToken(); inode = inode.mainNode().childOf(token); token = topic.headToken(); } if (inode == null || !topic.isEmpty()) { return Optional.empty(); } return Optional.of(inode.mainNode()); }
CTrieSubscriptionDirectory implements ISubscriptionsDirectory { Optional<CNode> lookup(Topic topic) { INode inode = this.root; Token token = topic.headToken(); while (!topic.isEmpty() && (inode.mainNode().anyChildrenMatch(token))) { topic = topic.exceptHeadToken(); inode = inode.mainNode().childOf(token); token = topic.headToken(); } if (inode == null || !topic.isEmpty()) { return Optional.empty(); } return Optional.of(inode.mainNode()); } }
CTrieSubscriptionDirectory implements ISubscriptionsDirectory { Optional<CNode> lookup(Topic topic) { INode inode = this.root; Token token = topic.headToken(); while (!topic.isEmpty() && (inode.mainNode().anyChildrenMatch(token))) { topic = topic.exceptHeadToken(); inode = inode.mainNode().childOf(token); token = topic.headToken(); } if (inode == null || !topic.isEmpty()) { return Optional.empty(); } return Optional.of(inode.mainNode()); }  }
CTrieSubscriptionDirectory implements ISubscriptionsDirectory { Optional<CNode> lookup(Topic topic) { INode inode = this.root; Token token = topic.headToken(); while (!topic.isEmpty() && (inode.mainNode().anyChildrenMatch(token))) { topic = topic.exceptHeadToken(); inode = inode.mainNode().childOf(token); token = topic.headToken(); } if (inode == null || !topic.isEmpty()) { return Optional.empty(); } return Optional.of(inode.mainNode()); }  void init(SessionsRepository sessionsRepository); @Override List<Subscription> matches(Topic topic); Action cleanTomb(INode inode, INode iParent); void add(Subscription newSubscription); void removeSubscription(Topic topic, String clientID); int size(); String dumpTree(); }
CTrieSubscriptionDirectory implements ISubscriptionsDirectory { Optional<CNode> lookup(Topic topic) { INode inode = this.root; Token token = topic.headToken(); while (!topic.isEmpty() && (inode.mainNode().anyChildrenMatch(token))) { topic = topic.exceptHeadToken(); inode = inode.mainNode().childOf(token); token = topic.headToken(); } if (inode == null || !topic.isEmpty()) { return Optional.empty(); } return Optional.of(inode.mainNode()); }  void init(SessionsRepository sessionsRepository); @Override List<Subscription> matches(Topic topic); Action cleanTomb(INode inode, INode iParent); void add(Subscription newSubscription); void removeSubscription(Topic topic, String clientID); int size(); String dumpTree();  }