// This file is part of OpenTSDB.
// Copyright (C) 2013  The OpenTSDB Authors.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version.  This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.  You should have received a copy
// of the GNU Lesser General Public License along with this program.  If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.core;

import java.util.HashMap;
import java.util.Map;

/**
 * Bridging class that stores a normalized data point parsed from the "put" 
 * RPC methods and gets it ready for storage. Also has some helper methods that
 * were formerly in the Tags class for parsing values.
 * <p>
 * The data point value is a string in order to accept a wide range of values
 * including floating point and scientific. Before storage, the value will
 * be parsed to the appropriate numeric type.
 * <p>
 * Note the class is not marked as final since some serializers may want to
 * overload with their own fields or parsing methods.
 * @since 2.0
 */
public class IncomingDataPoint {
  /** The incoming metric name */
  private String metric;
  
  /** The incoming timestamp in Unix epoch seconds or milliseconds */
  private long timestamp;
  
  /** The incoming value as a string, we'll parse it to float or int later */
  private String value;
  
  /** A hash map of tag name/values */
  private HashMap<String, String> tags;
  
  /**
   * Empty constructor necessary for some de/serializers
   */
  public IncomingDataPoint() {
    
  }
  
  /**
   * Constructor used to initialize all values
   * @param metric The metric name
   * @param timestamp The Unix epoch timestamp
   * @param value The value as a string
   * @param tags The tag name/value map
   */
  public IncomingDataPoint(final String metric,
      final long timestamp,
      final String value,
      final HashMap<String, String> tags) {
    this.metric = metric;
    this.timestamp = timestamp;
    this.value = value;
    this.tags = tags;
  }
  
  /**
   * @return information about this object
   */
  @Override
  public String toString() {
    final StringBuilder buf = new StringBuilder();
    buf.append("metric=").append(this.metric);
    buf.append(" ts=").append(this.timestamp);
    buf.append(" value=").append(this.value).append(" ");
    if (this.tags != null) {
      for (Map.Entry<String, String> entry : this.tags.entrySet()) {
        buf.append(entry.getKey()).append("=").append(entry.getValue());
      }
    }
    return buf.toString();
  }
  
  /** @return the metric */
  public final String getMetric() {
    return metric;
  }

  /** @return the timestamp */
  public final long getTimestamp() {
    return timestamp;
  }

  /** @return the value */
  public final String getValue() {
    return value;
  }

  /** @return the tags */
  public final HashMap<String, String> getTags() {
    return tags;
  }

  /** @param metric the metric to set */
  public final void setMetric(String metric) {
    this.metric = metric;
  }

  /** @param timestamp the timestamp to set */
  public final void setTimestamp(long timestamp) {
    this.timestamp = timestamp;
  }

  /** @param value the value to set */
  public final void setValue(String value) {
    this.value = value;
  }

  /** * @param tags the tags to set */
  public final void setTags(HashMap<String, String> tags) {
    this.tags = tags;
  }
}

@@ -1768,30 +1768,91 @@
 g%3E tags;%0A  %0A
+  /** TSUID for the data point */%0A  private String tsuid;%0A  %0A
   /**%0A
-
    * Empty c
@@ -1977,31 +1977,42 @@
 sed 
-to initialize all value
+when working with a metric and tag
 s%0A  
@@ -2436,24 +2436,388 @@
  %7D%0A  %0A  /**%0A
+   * Constructor used when working with tsuids%0A   * @param tsuid The TSUID%0A   * @param timestamp The Unix epoch timestamp%0A   * @param value The value as a string%0A   */%0A  public IncomingDataPoint(final String tsuid,%0A      final long timestamp,%0A      final String value) %7B%0A    this.tsuid = tsuid;%0A    this.timestamp = timestamp;%0A    this.value = value;%0A  %7D%0A  %0A  /**%0A
    * @return
@@ -3679,24 +3679,111 @@
  tags;%0A  %7D%0A%0A
+  /** @return the TSUID */%0A  public final String getTSUID() %7B%0A    return tsuid;%0A  %7D%0A  %0A
   /** @param
@@ -4142,18 +4142,16 @@
 %7D%0A%0A  /**
- *
  @param 
@@ -4226,32 +4226,32 @@
 String%3E tags) %7B%0A
-
     this.tags = 
@@ -4259,11 +4259,124 @@
 ags;%0A  %7D
+%0A%0A  /** @param tsuid the TSUID to set */%0A  public final void setTSUID(String tsuid) %7B%0A    this.tsuid = tsuid;%0A  %7D
 %0A%7D%0A

Add tsuid as a string to the IncomingDataPoint class for use with last data point queries