/*
 * Copyright © 2014 Cask Data, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package co.cask.cdap.metrics.query;

import co.cask.cdap.metrics.store.timeseries.TimeValue;
import com.google.common.collect.ImmutableList;

import java.util.List;

/**
 * Represents timeseries data response to REST calls. Use {@link #builder(long, long)}
 * to construct and GSON to serialize.
 */
final class TimeSeriesResponse {

  private final long start;
  private final long end;
  private final List<TimeValue> data;

  public static Builder builder(final long start, final long end) {
    final ImmutableList.Builder<TimeValue> timeValues = ImmutableList.builder();

    return new Builder() {
      @Override
      public Builder addData(long timestamp, long value) {
        return addData(new TimeValue(timestamp, value));
      }

      @Override
      public Builder addData(TimeValue timeValue) {
        timeValues.add(timeValue);
        return this;
      }

      @Override
      public TimeSeriesResponse build() {
        return new TimeSeriesResponse(start, end, timeValues.build());
      }
    };
  }

  private TimeSeriesResponse(long start, long end, List<TimeValue> data) {
    this.start = start;
    this.end = end;
    this.data = data;
  }

  public interface Builder {
    Builder addData(long timestamp, long value);

    Builder addData(TimeValue timeValue);

    TimeSeriesResponse build();
  }
}

@@ -631,64 +631,8 @@
 y;%0A%0A
-import co.cask.cdap.metrics.store.timeseries.TimeValue;%0A
 impo
@@ -1225,22 +1225,22 @@
     
-return addData
+timeValues.add
 (new
@@ -1274,120 +1274,8 @@
 ));%0A
-      %7D%0A%0A      @Override%0A      public Builder addData(TimeValue timeValue) %7B%0A        timeValues.add(timeValue);%0A
     
@@ -1595,16 +1595,289 @@
 a;%0A  %7D%0A%0A
+  /**%0A   * Represents metric data point. Used to construct JSON response.%0A   */%0A  static final class TimeValue %7B%0A    private final long time;%0A    private final long value;%0A%0A    TimeValue(long time, long value) %7B%0A      this.time = time;%0A      this.value = value;%0A    %7D%0A  %7D%0A%0A
   public
@@ -1951,51 +1951,8 @@
 );%0A%0A
-    Builder addData(TimeValue timeValue);%0A%0A
     

fix metrics v2 format: time vs timestamp