NealSun96 commented on a change in pull request #731: Add TrieRoutingData constructor URL: https://github.com/apache/helix/pull/731#discussion_r377210986
########## File path: helix-rest/src/main/java/org/apache/helix/rest/metadatastore/TrieRoutingData.java ########## @@ -37,15 +39,26 @@ private final TrieNode _rootNode; - // TODO: THIS IS A TEMPORARY PLACEHOLDER. A proper constructor will be created, which will not - // take in a TrieNode; it instead initializes the rootNode and creates a trie based on - // some input data. The constructor is blocked by the implementation of RoutingDataAccessor, and - // will therefore be implemented later. - public TrieRoutingData(TrieNode rootNode) { - _rootNode = rootNode; + public TrieRoutingData(Map<String, List<String>> routingData) throws InvalidRoutingDataException { + if (routingData == null || routingData.isEmpty()) { + throw new InvalidRoutingDataException("Missing routing data"); + } + + if (isRootShardingKey(routingData)) { + Map.Entry<String, List<String>> entry = routingData.entrySet().iterator().next(); + _rootNode = new TrieNode(Collections.emptyMap(), "/", true, entry.getKey()); + } else { + _rootNode = new TrieNode(new HashMap<>(), "/", false, ""); + constructTrie(routingData); + } } - public Map<String, String> getAllMappingUnderPath(String path) { + public Map<String, String> getAllMappingUnderPath(String path) throws IllegalArgumentException { + if (path.isEmpty() || !path.substring(0, 1).equals(DELIMITER)) { + throw new IllegalArgumentException( + "Provided path is empty or does not have a leading delimiter: " + path); Review comment: I'll replace the "delimiter" text with the actual delimiter character to make it more clear. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org