@Test public void prevBeforeMin() { assertThrows(RecordCoreException.class, () -> FDBRecordVersion.MIN_VERSION.prev()); }
@Nonnull public FDBRecordVersion prev() { if (isComplete()) { byte[] newVersionBytes = Arrays.copyOf(versionBytes, VERSION_LENGTH); boolean stopped = false; for (int i = newVersionBytes.length - 1; i >= 0; i--) { if (newVersionBytes[i] == 0) { newVersionBytes[i] = (byte)0xff; } else { newVersionBytes[i] = (byte) (((int) newVersionBytes[i] & 0xff) - 1); stopped = true; break; } } if (!stopped) { throw new RecordCoreException("Attempted to decrement minimum version"); } return FDBRecordVersion.complete(newVersionBytes, false); } else { return FDBRecordVersion.incomplete(getLocalVersion() - 1); } }
FDBRecordVersion implements Comparable<FDBRecordVersion> { @Nonnull public FDBRecordVersion prev() { if (isComplete()) { byte[] newVersionBytes = Arrays.copyOf(versionBytes, VERSION_LENGTH); boolean stopped = false; for (int i = newVersionBytes.length - 1; i >= 0; i--) { if (newVersionBytes[i] == 0) { newVersionBytes[i] = (byte)0xff; } else { newVersionBytes[i] = (byte) (((int) newVersionBytes[i] & 0xff) - 1); stopped = true; break; } } if (!stopped) { throw new RecordCoreException("Attempted to decrement minimum version"); } return FDBRecordVersion.complete(newVersionBytes, false); } else { return FDBRecordVersion.incomplete(getLocalVersion() - 1); } } }
FDBRecordVersion implements Comparable<FDBRecordVersion> { @Nonnull public FDBRecordVersion prev() { if (isComplete()) { byte[] newVersionBytes = Arrays.copyOf(versionBytes, VERSION_LENGTH); boolean stopped = false; for (int i = newVersionBytes.length - 1; i >= 0; i--) { if (newVersionBytes[i] == 0) { newVersionBytes[i] = (byte)0xff; } else { newVersionBytes[i] = (byte) (((int) newVersionBytes[i] & 0xff) - 1); stopped = true; break; } } if (!stopped) { throw new RecordCoreException("Attempted to decrement minimum version"); } return FDBRecordVersion.complete(newVersionBytes, false); } else { return FDBRecordVersion.incomplete(getLocalVersion() - 1); } } @Nonnull private  FDBRecordVersion(boolean complete, @Nonnull byte[] versionBytes, boolean copy); }
FDBRecordVersion implements Comparable<FDBRecordVersion> { @Nonnull public FDBRecordVersion prev() { if (isComplete()) { byte[] newVersionBytes = Arrays.copyOf(versionBytes, VERSION_LENGTH); boolean stopped = false; for (int i = newVersionBytes.length - 1; i >= 0; i--) { if (newVersionBytes[i] == 0) { newVersionBytes[i] = (byte)0xff; } else { newVersionBytes[i] = (byte) (((int) newVersionBytes[i] & 0xff) - 1); stopped = true; break; } } if (!stopped) { throw new RecordCoreException("Attempted to decrement minimum version"); } return FDBRecordVersion.complete(newVersionBytes, false); } else { return FDBRecordVersion.incomplete(getLocalVersion() - 1); } } @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(); }
FDBRecordVersion implements Comparable<FDBRecordVersion> { @Nonnull public FDBRecordVersion prev() { if (isComplete()) { byte[] newVersionBytes = Arrays.copyOf(versionBytes, VERSION_LENGTH); boolean stopped = false; for (int i = newVersionBytes.length - 1; i >= 0; i--) { if (newVersionBytes[i] == 0) { newVersionBytes[i] = (byte)0xff; } else { newVersionBytes[i] = (byte) (((int) newVersionBytes[i] & 0xff) - 1); stopped = true; break; } } if (!stopped) { throw new RecordCoreException("Attempted to decrement minimum version"); } return FDBRecordVersion.complete(newVersionBytes, false); } else { return FDBRecordVersion.incomplete(getLocalVersion() - 1); } } @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; }