/** * @return true if the message has a valid timestamp. */ public boolean isTimestamped() { return getTimestamp() != null; }
@Override public boolean equals(Object obj) { if(obj == null) { return false; } if(this == obj) { return true; } final VehicleMessage other = (VehicleMessage) obj; return Objects.equal(getTimestamp(), other.getTimestamp()) && Objects.equal(mExtras, other.mExtras); }
public int compareTo(VehicleMessage other) { return getTimestamp().compareTo(other.getTimestamp()); }
public Date getDate() { if (!isTimestamped()) { return null; } return new Date(getTimestamp()); }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("timestamp", getTimestamp()) .add("extras", getExtras()) .toString(); }
@Override public void writeToParcel(Parcel out, int flags) { out.writeString(getClass().getName()); out.writeValue(getTimestamp()); out.writeValue(getExtras()); }
@Test public void setAutomaticTriggeredTimestamp() { message = new VehicleMessage(); message.timestamp(); assertTrue(message.isTimestamped()); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(message.getTimestamp()); // Catch a regression where we didn't divide by 1000 before storing // timestamp as a double. assertThat(calendar.get(Calendar.YEAR), equalTo(Calendar.getInstance().get(Calendar.YEAR))); }
@Test public void cantRetimestamp() { message.timestamp(); Long timestamp = message.getTimestamp(); message.timestamp(); assertEquals(timestamp, message.getTimestamp()); }
waitForNextRecord(startingTime, measurement.getTimestamp()); } catch (NumberFormatException e) { Log.w(TAG, "A trace line was not in the expected " +
@Test public void differentValuesNotEqual() { extras.put("another", "foo"); // This also tests that the values map is copied and we don't have the // same reference from outside the class VehicleMessage anotherMessage = new VehicleMessage( message.getTimestamp(), extras); assertFalse(message.equals(anotherMessage)); }
@Test public void setManualTimestamp() { message = new VehicleMessage(Long.valueOf(10000), extras); assertTrue(message.isTimestamped()); assertEquals(Long.valueOf(10000), message.getTimestamp()); }
@Test public void sameValuesEquals() { VehicleMessage anotherMessage = new VehicleMessage( message.getTimestamp(), extras); assertEquals(message, anotherMessage); }