FDBRecordVersion implements Comparable<FDBRecordVersion> { @Nonnull public static FDBRecordVersion fromBytes(@Nonnull byte[] versionBytes) { return fromBytes(versionBytes, true); } @Nonnull private  FDBRecordVersion(boolean complete, @Nonnull byte[] versionBytes, boolean copy); @Nonnull static FDBRecordVersion complete(@Nonnull byte[] globalVersion, int localVersion); @Nonnull static FDBRecordVersion complete(@Nonnull byte[] versionBytes); @Nonnull static FDBRecordVersion complete(@Nonnull byte[] versionBytes, boolean copy); @Nonnull static FDBRecordVersion incomplete(int localVersion); @Nonnull static FDBRecordVersion fromBytes(@Nonnull byte[] versionBytes); @Nonnull static FDBRecordVersion fromBytes(@Nonnull byte[] versionBytes, boolean copy); @Nonnull static FDBRecordVersion fromVersionstamp(@Nonnull Versionstamp versionstamp); @Nonnull static FDBRecordVersion fromVersionstamp(@Nonnull Versionstamp versionstamp, boolean copy); @Nonnull static FDBRecordVersion firstInDBVersion(long dbVersion); static FDBRecordVersion firstInGlobalVersion(@Nonnull byte[] globalVersion); static FDBRecordVersion lastInDBVersion(long dbVersion); static FDBRecordVersion lastInGlobalVersion(@Nonnull byte[] globalVersion); @Nonnull Versionstamp toVersionstamp(); @Nonnull Versionstamp toVersionstamp(boolean copy); @Nonnull byte[] toBytes(); @Nonnull @SpotBugsSuppressWarnings(value = "EI", justification = "option is explicitly set to do this") byte[] toBytes(boolean copy); @Nonnull ByteBuffer writeTo(@Nonnull ByteBuffer buffer); int writeTo(@Nonnull byte[] bytes); int writeTo(@Nonnull byte[] bytes, int offset); boolean isComplete(); int getLocalVersion(); @Nonnull @SpotBugsSuppressWarnings(value = "EI", justification = "not mutated later") byte[] getGlobalVersion(); long getDBVersion(); @Nonnull FDBRecordVersion next(); @Nonnull FDBRecordVersion prev(); @Nonnull FDBRecordVersion withCommittedVersion(@Nullable byte[] committedVersion); @Override boolean equals(Object o); @Override int compareTo(@Nonnull FDBRecordVersion other); @Override int hashCode(); @Override @Nonnull String toString(); static final int GLOBAL_VERSION_LENGTH; static final int VERSION_LENGTH; static final FDBRecordVersion MIN_VERSION; static final FDBRecordVersion MAX_VERSION; }
@Test public void fromBytes() { FDBRecordVersion version1 = FDBRecordVersion.incomplete(1); FDBRecordVersion version2 = FDBRecordVersion.fromBytes(version1.toBytes()); assertFalse(version2.isComplete()); assertEquals(1, version2.getLocalVersion()); assertEquals(version1, version2); assertTrue(version2.toBytes(false) != version1.toBytes(false)); FDBRecordVersion version3 = FDBRecordVersion.complete(VERSION_BYTES_THREE, 2); FDBRecordVersion version4 = FDBRecordVersion.fromBytes(version3.toBytes()); assertTrue(version4.isComplete()); assertEquals(2, version4.getLocalVersion()); assertArrayEquals(VERSION_BYTES_THREE, version4.getGlobalVersion()); assertEquals(version3, version4); assertTrue(version3.toBytes(false) != version4.toBytes(false)); FDBRecordVersion version5 = FDBRecordVersion.fromBytes(version3.toBytes(false), false); assertTrue(version5.isComplete()); assertEquals(2, version5.getLocalVersion()); assertArrayEquals(VERSION_BYTES_THREE, version5.getGlobalVersion()); assertEquals(version3, version5); assertEquals(version4, version5); assertTrue(version3.toBytes(false) == version5.toBytes(false)); FDBRecordVersion version6 = FDBRecordVersion.fromBytes(VERSION_BYTES_FOUR, false); assertTrue(version6.toBytes(false) == VERSION_BYTES_FOUR); assertEquals(0, version6.getLocalVersion()); assertTrue(version6.isComplete()); FDBRecordVersion version7 = FDBRecordVersion.fromBytes(VERSION_BYTES_FIVE); assertTrue(version7.toBytes(false) != VERSION_BYTES_FIVE); assertArrayEquals(VERSION_BYTES_FIVE, version7.toBytes(false)); assertEquals(0xffff, version7.getLocalVersion()); assertThat(version7.getLocalVersion(), greaterThan(0)); }