package producerrandom; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; @SuppressWarnings("WeakerAccess") public class Price implements Serializable { private static final long serialVersionUID = 1L; public String symbol; public long timestamp; // expected to be System.currentTimeMillis() public Double value; @SuppressWarnings("unused") public Price() { // default constructor } // so that the class can be used as a POJO public Price(String symbol, long timestamp, Double value) { this.symbol = symbol; this.timestamp = timestamp; this.value = value; } public String toString() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Date date = new Date(this.timestamp); String value_formatted = String.format("%.3f", this.value); // align positive and negative values using // an extra whitespace for positive values: if (!value_formatted.startsWith("-")) { value_formatted = " " + value_formatted; } return "Price{symbol='" + this.symbol + "', timestamp=" + simpleDateFormat.format(date) + ", value=" + value_formatted + "}"; } public String toSimpleString() { return this.timestamp + "," + this.value; } }