code: public static String parseWithMetric(final String metric,
        final List<Pair<String, String>> tags) {
      final int curly = metric.indexOf('{');
      if (curly < 0) {
        if (metric.isEmpty()) {
          throw new IllegalArgumentException("Metric string was empty");
        }
        return metric;
      }
      final int len = metric.length();
      if (metric.charAt(len - 1) != '}') {  // "foo{"
        throw new IllegalArgumentException("Missing '}' at the end of: " + metric);
      } else if (curly == len - 2) {  // "foo{}"
        if (metric.charAt(0) == '{') {
          throw new IllegalArgumentException("Missing metric and tags: " + metric);
        }
        return metric.substring(0, len - 2);
      }
      // substring the tags out of "foo{a=b,...,x=y}" and parse them.
      for (final String tag : splitString(metric.substring(curly + 1, len - 1),
             ',')) {
      try {
        parse(tags, tag);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("When parsing tag '" + tag
                  + "': " + e.getMessage());
        }
      }
      // Return the "foo" part of "foo{a=b,...,x=y}"
      if (metric.charAt(0) == '{') {
        return null;
      }
      return metric.substring(0, curly);
    }
docs: Parses an optional metric and tags out of the given string, any of
  which may be null. Requires at least one metric, tagk or tagv.
  @param metric A string of the form "metric" or "metric{tag=value,...}"
  or even "{tag=value,...}" where the metric may be missing.
  @param tags The list to populate with parsed tag pairs
  @return The name of the metric if it exists, null otherwise
  @throws IllegalArgumentException if the metric is malformed.
  @since 2.1