package org.kairosdb.core.datapoints;


import org.json.JSONException;
import org.json.JSONWriter;

import java.io.DataOutput;
import java.io.IOException;
import java.nio.ByteBuffer;

/**
 Created with IntelliJ IDEA.
 User: bhawkins
 Date: 8/31/13
 Time: 7:20 AM
 To change this template use File | Settings | File Templates.
 */
public class DoubleDataPoint extends DataPointHelper
{
	private double m_value;

	public DoubleDataPoint(long timestamp, double value)
	{
		super(timestamp);
		m_value = value;
	}

	@Override
	public double getDoubleValue()
	{
		return (m_value);
	}

	/*@Override
	public ByteBuffer toByteBuffer()
	{
		return DoubleDataPointFactoryImpl.writeToByteBuffer(this);
	}*/

	@Override
	public void writeValueToBuffer(DataOutput buffer) throws IOException
	{
		DoubleDataPointFactoryImpl.writeToByteBuffer(buffer, this);
	}

	@Override
	public void writeValueToJson(JSONWriter writer) throws JSONException
	{
		if (m_value != m_value || Double.isInfinite(m_value))
			throw new IllegalStateException("NaN or Infinity:" + m_value + " data point=" + this);

		writer.value(m_value);
	}

	@Override
	public String getApiDataType()
	{
		return API_DOUBLE;
	}

	@Override
	public String getDataStoreDataType()
	{
		return DoubleDataPointFactoryImpl.DST_DOUBLE;
	}

	@Override
	public boolean isLong()
	{
		return false;
	}

	@Override
	public long getLongValue()
	{
		return (long)m_value;
	}

	@Override
	public boolean isDouble()
	{
		return true;
	}

	@Override
	public boolean equals(Object o)
	{
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		DoubleDataPoint that = (DoubleDataPoint) o;

		if (Double.compare(that.m_value, m_value) != 0) return false;

		return true;
	}

	@Override
	public int hashCode()
	{
		long temp = Double.doubleToLongBits(m_value);
		return (int) (temp ^ (temp >>> 32));
	}
}

@@ -924,19 +924,59 @@
 ption%0A%09%7B
+%09//m_value != m_value?? maybe is a bug
 %0A%09%09
+//
 if (m_va
@@ -1021,16 +1021,142 @@
 value))%0A
+%09%09//%09throw new IllegalStateException(%22NaN or Infinity:%22 + m_value + %22 data point=%22 + this);%0A%09%09if (Double.isInfinite(m_value))%0A
 %09%09%09throw
@@ -1237,16 +1237,19 @@
  this);%0A
+%09%09%09
 %0A%09%09write

Update DoubleDataPoint.java