@Test public void testCompare() { Timestamp[] timestamps = { new Timestamp(12344, 999999999), new Timestamp(12345, 0), new Timestamp(12345, 1), new Timestamp(12345, 99999999), new Timestamp(12345, 100000000), new Timestamp(12345, 100000001), new Timestamp(12346, 0) }; for (int i = 0; i < timestamps.length - 1; ++i) { assertThat(timestamps[i].compareTo(timestamps[i + 1])).isEqualTo(-1); assertThat(timestamps[i + 1].compareTo(timestamps[i])).isEqualTo(1); } }
@Override public int compareTo(@NonNull Timestamp other) { if (seconds == other.seconds) { return Integer.signum(nanoseconds - other.nanoseconds); } return Long.signum(seconds - other.seconds); }
Timestamp implements Comparable<Timestamp>, Parcelable { @Override public int compareTo(@NonNull Timestamp other) { if (seconds == other.seconds) { return Integer.signum(nanoseconds - other.nanoseconds); } return Long.signum(seconds - other.seconds); } }
Timestamp implements Comparable<Timestamp>, Parcelable { @Override public int compareTo(@NonNull Timestamp other) { if (seconds == other.seconds) { return Integer.signum(nanoseconds - other.nanoseconds); } return Long.signum(seconds - other.seconds); } Timestamp(long seconds, int nanoseconds); protected  Timestamp(@NonNull Parcel in);  Timestamp(@NonNull Date date); }
Timestamp implements Comparable<Timestamp>, Parcelable { @Override public int compareTo(@NonNull Timestamp other) { if (seconds == other.seconds) { return Integer.signum(nanoseconds - other.nanoseconds); } return Long.signum(seconds - other.seconds); } Timestamp(long seconds, int nanoseconds); protected  Timestamp(@NonNull Parcel in);  Timestamp(@NonNull Date date); @NonNull static Timestamp now(); long getSeconds(); int getNanoseconds(); @NonNull Date toDate(); @Override int describeContents(); @Override void writeToParcel(@NonNull Parcel dest, int flags); @Override int compareTo(@NonNull Timestamp other); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); }
Timestamp implements Comparable<Timestamp>, Parcelable { @Override public int compareTo(@NonNull Timestamp other) { if (seconds == other.seconds) { return Integer.signum(nanoseconds - other.nanoseconds); } return Long.signum(seconds - other.seconds); } Timestamp(long seconds, int nanoseconds); protected  Timestamp(@NonNull Parcel in);  Timestamp(@NonNull Date date); @NonNull static Timestamp now(); long getSeconds(); int getNanoseconds(); @NonNull Date toDate(); @Override int describeContents(); @Override void writeToParcel(@NonNull Parcel dest, int flags); @Override int compareTo(@NonNull Timestamp other); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @NonNull
  static final Parcelable.Creator<Timestamp> CREATOR; }