@Test public void testGetTokensForMetricWithOneToken() { String tenantID = "111111"; String metricName = "a"; Locator locator = Locator.createLocatorFromPathComponents(tenantID, metricName); String[] expectedTokens = new String[] {"a"}; String[] expectedParents = new String[] {""}; String[] expectedIds = new String[] {tenantID + ":" + "a:$"}; List<Token> tokens = Token.getTokens(locator); verifyTokenInfos(tenantID, expectedTokens, expectedParents, expectedIds, tokens); }
public static List<Token> getTokens(Locator locator) { if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId())) return new ArrayList<>(); String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX); return IntStream.range(0, tokens.length) .mapToObj(index -> new Token(locator, tokens, index)) .collect(toList()); }
Token { public static List<Token> getTokens(Locator locator) { if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId())) return new ArrayList<>(); String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX); return IntStream.range(0, tokens.length) .mapToObj(index -> new Token(locator, tokens, index)) .collect(toList()); } }
Token { public static List<Token> getTokens(Locator locator) { if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId())) return new ArrayList<>(); String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX); return IntStream.range(0, tokens.length) .mapToObj(index -> new Token(locator, tokens, index)) .collect(toList()); } Token(Locator locator, String[] tokens, int level); }
Token { public static List<Token> getTokens(Locator locator) { if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId())) return new ArrayList<>(); String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX); return IntStream.range(0, tokens.length) .mapToObj(index -> new Token(locator, tokens, index)) .collect(toList()); } Token(Locator locator, String[] tokens, int level); @Override boolean equals(Object o); @Override int hashCode(); String getId(); Locator getLocator(); String getToken(); String getParent(); boolean isLeaf(); static List<Token> getTokens(Locator locator); static Stream<Token> getUniqueTokens(Stream<Locator> locators); @Override String toString(); }
Token { public static List<Token> getTokens(Locator locator) { if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId())) return new ArrayList<>(); String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX); return IntStream.range(0, tokens.length) .mapToObj(index -> new Token(locator, tokens, index)) .collect(toList()); } Token(Locator locator, String[] tokens, int level); @Override boolean equals(Object o); @Override int hashCode(); String getId(); Locator getLocator(); String getToken(); String getParent(); boolean isLeaf(); static List<Token> getTokens(Locator locator); static Stream<Token> getUniqueTokens(Stream<Locator> locators); @Override String toString(); static final String LEAF_NODE_SUFFIX; static final String SEPARATOR; }