private String shardN()

in spectator-ext-ipc/src/main/java/com/netflix/spectator/ipc/ServerGroup.java [147:174]


  private String shardN(char n) {
    if (d1 != 0 && d2 > 0) {
      int matchStart = -1;
      int matchEnd = -1;
      // Shards must be the first part of the detail, loop until we find a gap
      int s = d2;
      while (s != -1) {
        int nextDash = asg.indexOf('-', s + 2);
        int e = (nextDash == -1) ? dN : nextDash;
        if (e <= s + 3 || asg.charAt(s + 1) != 'x' || !nonZeroDigit(asg.charAt(s + 2))) {
          // Shard value must be at least 1 character
          // The number prefix must match
          break;
        } else if (asg.charAt(s + 2) == n && !isDigit(asg.charAt(s + 3))) {
          // If the first character of the value is numeric, means shard number is too high
          // skip and move to the next. Otherwise we have a match. Since the match could get
          // overwritten later, record positions for now and keep checking.
          matchStart = s + 3;
          matchEnd = e;
        }
        s = nextDash;
      }
      return (matchStart > 0) ? substr(asg, matchStart, matchEnd) : null;
    } else {
      // No detail means no shards
      return null;
    }
  }