HybridTimestamp implements Comparable<HybridTimestamp>, SerializableComparable<BigInteger> { public long update() { long physicalTime = physicalTimeProvider.getPhysicalTime(); if (compare(logicalTime, physicalTime) < 0) { logicalTime = physicalTime; logicalCounter = 0; } else { logicalCounter++; } return timestamp(); } HybridTimestamp();  HybridTimestamp(PhysicalTimeProvider physicalTimeProvider);  HybridTimestamp(PhysicalTimeProvider physicalTimeProvider, long timestamp);  HybridTimestamp(PhysicalTimeProvider physicalTimeProvider, long logicalTime, long logicalCounter);  HybridTimestamp(PhysicalTimeProvider physicalTimeProvider, HybridTimestamp ts); @LayoutConstructor  HybridTimestamp(long logicalTime, long logicalCounter); HybridTimestamp clone(); @Override int compareTo(HybridTimestamp o); static int compare(long time1, long time2); @Override boolean equals(Object obj); static int compare(TimeStamp t1, TimeStamp t2); long update(); long update(HybridTimestamp ts); long update(long eventLogicalTime, long eventLogicalCounter); long timestamp(); String toString(); @Override BigInteger getSerializableComparable();  }
@Test public void test() { long ts, ts_; HybridTimestamp timestamp = new HybridTimestamp(physicalTimeProvider, 0, 0); ts = (long) 1 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update(); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(0, timestamp.getLogicalCounter()); ts = (long) 1 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update(); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(1, timestamp.getLogicalCounter()); ts = (long) 0 << 32 | 1; physicalTimeProvider.setPhysicalTime(ts); ts_ = timestamp.getLogicalTime(); timestamp.update(); assertEquals(ts_, timestamp.getLogicalTime()); assertEquals(2, timestamp.getLogicalCounter()); ts = (long) 2 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update(); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(0, timestamp.getLogicalCounter()); ts = (long) 3 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 1 << 32 | 2, 3); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(0, timestamp.getLogicalCounter()); ts = (long) 3 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 1 << 32 | 2, 3); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(1, timestamp.getLogicalCounter()); ts = (long) 3 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 3 << 32 | 0, 1); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(2, timestamp.getLogicalCounter()); ts = (long) 3 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 3 << 32 | 0, 99); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(100, timestamp.getLogicalCounter()); ts = (long) 3 << 32 | 5; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 4 << 32 | 4, 100); assertEquals((long) 4 << 32 | 4, timestamp.getLogicalTime()); assertEquals(101, timestamp.getLogicalCounter()); ts = (long) 5 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 4 << 32 | 5, 0); assertEquals(ts, timestamp.getLogicalTime()); assertEquals(0, timestamp.getLogicalCounter()); ts = (long) 4 << 32 | 9; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 5 << 32 | 0, 99); assertEquals((long) 5 << 32 | 0, timestamp.getLogicalTime()); assertEquals(100, timestamp.getLogicalCounter()); ts = (long) 0 << 32 | 0; physicalTimeProvider.setPhysicalTime(ts); timestamp.update((long) 5 << 32 | 0, 50); assertEquals((long) 5 << 32 | 0, timestamp.getLogicalTime()); assertEquals(101, timestamp.getLogicalCounter()); timestamp.update(timestamp); assertEquals((long) 5 << 32 | 0, timestamp.getLogicalTime()); assertEquals(102, timestamp.getLogicalCounter()); }