package edu.msoe.smv.raspi;

import com.google.gson.GsonBuilder;

import java.util.Date;

/**
 * This class represents the state of the vehicle at a specific point in time
 *
 * @author matt
 */
public class DataNode {

	private final Date date;
	private final double rpm;
	private final double speed;

	public DataNode(double rpm, double speed) {
		this.rpm = rpm;
		this.speed = speed;
		this.date = new Date();
	}

	public Date getDate() {
		return date;
	}

	public double getRpm() {
		return rpm;
	}

	/**
	 * 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,
	 *     "date": "Oct 25, 2014 2:04:23 PM",
	 *     "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 date.getTime() + "," + rpm + "," + speed;
	}
}

@@ -63,32 +63,8 @@
 r;%0A%0A
-import java.util.Date;%0A%0A
 /**%0A
@@ -192,250 +192,897 @@
 e %7B%0A
-%0A%09private final Date date;%0A%09private final double rpm;%0A%09private final double speed;%0A%0A%09public DataNode(double rpm, double speed) %7B%0A%09%09this.rpm = rpm;%0A%09%09this.speed = speed;%0A%09%09this.date = new Date();%0A%09%7D%0A%0A%09public Date getDate() %7B%0A%09%09return date;%0A%09%7D%0A
+%09/**%0A%09 * The UNIX epoch when this DataNode was created%0A%09 */%0A%09private final long unixTime;%0A%09/**%0A%09 * The rpm at this DataNode%0A%09 */%0A%09private final double rpm;%0A%09/**%0A%09 * The speed at this DataNode%0A%09 */%0A%09private final double speed;%0A%0A%09/**%0A%09 * Constructs a new DataNode%0A%09 * @param rpm the RPM at this DataNode%0A%09 * @param speed the speed at this DataNode%0A%09 */%0A%09public DataNode(double rpm, double speed) %7B%0A%09%09this.rpm = rpm;%0A%09%09this.speed = speed;%0A%09%09this.unixTime = System.currentTimeMillis();%0A%09%7D%0A%0A%09/**%0A%09 * Returns the UNIX epoch time when this DataNode was created%0A%09 * @return the UNIX epoch time when this DataNode was created%0A%09 */%0A%09public long getUnixTime() %7B%0A%09%09return unixTime;%0A%09%7D%0A%0A%09/**%0A%09 * Returns the RPM at this DataNode%0A%09 * @return the RPM at this DataNode%0A%09 */%0A%09public double getRpm() %7B%0A%09%09return rpm;%0A%09%7D%0A%0A%09/**%0A%09 * Returns the speed at this DataNode%0A%09 * @return the speed at this DataNode%0A%09 */
 %0A%09pu
@@ -1088,35 +1088,37 @@
 ublic double get
-Rpm
+Speed
 () %7B%0A%09%09return rp
@@ -1107,35 +1107,37 @@
 ed() %7B%0A%09%09return 
-rpm
+speed
 ;%0A%09%7D%0A%0A%09/**%0A%09 * R
@@ -1386,40 +1386,29 @@
    %22
-date%22: %22Oct 25, 2014 2:04:23 PM%22
+unixTime%22: 1414263863
 ,%0A%09 
@@ -2038,22 +2038,16 @@
 urn 
-date.get
+unix
 Time
-()
  + %22

Switch DataNode to use UNIX epoch time instead of a Date object