package edu.msoe.smv.raspi;

import com.google.gson.GsonBuilder;

/**
 * This class represents the state of the vehicle at a specific point in time
 *
 * @author matt
 */
public class DataNode {
	/**
	 * The UNIX epoch when this DataNode was created
	 */
	private final long unixTime;
	/**
	 * The rpm at this DataNode
	 */
	private final double rpm;
	/**
	 * The speed at this DataNode
	 */
	private final double speed;

	/**
	 * Constructs a new DataNode
	 * @param rpm the RPM at this DataNode
	 * @param speed the speed at this DataNode
	 */
	public DataNode(double rpm, double speed) {
		this.rpm = rpm;
		this.speed = speed;
		this.unixTime = System.currentTimeMillis();
	}

	/**
	 * Returns the UNIX epoch time when this DataNode was created
	 * @return the UNIX epoch time when this DataNode was created
	 */
	public long getUnixTime() {
		return unixTime;
	}

	/**
	 * Returns the RPM at this DataNode
	 * @return the RPM at this DataNode
	 */
	public double getRpm() {
		return rpm;
	}

	/**
	 * Returns the speed at this DataNode
	 * @return the speed at this DataNode
	 */
	public double getSpeed() {
		return speed;
	}

	/**
	 * Returns a string representation of this node formatted in JSON.
	 * </p>
	 * Pretty printing is used, that is the resulting string spans multiple lines. For example: </p>
	 * <pre>{
	 *     "altitude": 5.0,
	 *     "batteryVoltage": 2.0,
	 *     "unixTime": 1414263863,
	 *     "latitude": 3.0,
	 *     "longitude": 5.0,
	 *     "rpm": 1.0
	 * }</pre>
	 *
	 * @return a string representation of this node formatted in JSON
	 */
	@Override
	public String toString() {
		return new GsonBuilder().setPrettyPrinting().create().toJson(this);
	}

	/**
	 * Returns a string representation of this DataNode as comma-separated values.
	 * <p/>
	 * Example result: <pre>12345678,200,20</pre> where the first value is the Unix time, the second is the RPM, and
	 * the third is the speed.
	 *
	 * @return a string representation of this DataNode as comma-separated values
	 */
	public String toCSV() {
		return unixTime + "," + rpm + "," + speed;
	}
}

@@ -413,16 +413,167 @@
 e speed;
+%0A%09/**%0A%09 * Counts the number of DataNodes created.%0A%09 * %3Cp/%3E%0A%09 * This is used to track how far the vehicle has gone.%0A%09 */%0A%09private static long count = 0;
 %0A%0A%09/**%0A%09
@@ -593,32 +593,36 @@
  a new DataNode%0A
+%09 *%0A
 %09 * @param rpm t
@@ -620,16 +620,21 @@
 ram rpm 
+     
 the RPM 
@@ -667,16 +667,19 @@
 m speed 
+   
 the spee
@@ -689,32 +689,95 @@
 t this DataNode%0A
+%09 * @param realData false if this DataNode is a dummy DataNode%0A
 %09 */%0A%09public Dat
@@ -806,16 +806,34 @@
 le speed
+, boolean realData
 ) %7B%0A%09%09th
@@ -913,16 +913,51 @@
 illis();
+%0A%0A%09%09if (realData) %7B%0A%09%09%09count++;%0A%09%09%7D
 %0A%09%7D%0A%0A%09/*
@@ -1021,16 +1021,20 @@
 created%0A
+%09 *%0A
 %09 * @ret
@@ -1179,32 +1179,36 @@
 t this DataNode%0A
+%09 *%0A
 %09 * @return the 
@@ -1317,24 +1317,28 @@
 is DataNode%0A
+%09 *%0A
 %09 * @return 
@@ -1493,21 +1493,13 @@
 SON.
-%0A%09 *
  %3C/p%3E
-%0A%09 *
  Pre
@@ -1531,16 +1531,20 @@
 t is the
+%0A%09 *
  resulti
@@ -1608,64 +1608,8 @@
 e%3E%7B%0A
-%09 *     %22altitude%22: 5.0,%0A%09 *     %22batteryVoltage%22: 2.0,%0A
 %09 * 
@@ -1649,20 +1649,15 @@
    %22
-latitude%22: 3
+rpm%22: 1
 .0,%0A
@@ -1669,21 +1669,17 @@
    %22
-longitude%22: 5
+speed%22: 2
 .0,%0A
@@ -1687,25 +1687,26 @@
  *     %22
-rpm%22: 1.0
+count%22: 23
 %0A%09 * %7D%3C/
@@ -2287,19 +2287,33 @@
  %22,%22 + speed
+ + %22,%22 + count
 ;%0A%09%7D%0A%7D%0A

Add counter to DataNodes that count how the number of revolutions