net.opentsdb.core
Class Tags

java.lang.Object
  extended by net.opentsdb.core.Tags

public final class Tags
extends Object

Helper functions to deal with tags.


Method Summary
static void parse(HashMap<String,String> tags, String tag)
          Parses a tag into a HashMap.
static long parseLong(CharSequence s)
          Parses an integer value as a long from the given character sequence.
static String parseWithMetric(String metric, HashMap<String,String> tags)
          Parses the metric and tags out of the given string.
static String[] splitString(String s, char c)
          Optimized version of String#split that doesn't use regexps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

splitString

public static String[] splitString(String s,
                                   char c)
Optimized version of String#split that doesn't use regexps. This function works in O(5n) where n is the length of the string to split.

Parameters:
s - The string to split.
c - The separator to use to split the string.
Returns:
A non-null, non-empty array.

parse

public static void parse(HashMap<String,String> tags,
                         String tag)
Parses a tag into a HashMap.

Parameters:
tags - The HashMap into which to store the tag.
tag - A String of the form "tag=value".
Throws:
IllegalArgumentException - if the tag is malformed.
IllegalArgumentException - if the tag was already in tags with a different value.

parseWithMetric

public static String parseWithMetric(String metric,
                                     HashMap<String,String> tags)
Parses the metric and tags out of the given string.

Parameters:
metric - A string of the form "metric" or "metric{tag=value,...}".
tags - The map to populate with the tags parsed out of the first argument.
Returns:
The name of the metric.
Throws:
IllegalArgumentException - if the metric is malformed.

parseLong

public static long parseLong(CharSequence s)
Parses an integer value as a long from the given character sequence.

This is equivalent to Long.parseLong(String) except it's up to 100% faster on String and always works in O(1) space even with StringBuilder buffers (where it's 2x to 5x faster).

Parameters:
s - The character sequence containing the integer value to parse.
Returns:
The value parsed.
Throws:
NumberFormatException - if the value is malformed or overflows.