com.palantir.atlasdb.timelock.api.ConjureTimestampRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timelock-api-objects Show documentation
Show all versions of timelock-api-objects Show documentation
Palantir open source project
package com.palantir.atlasdb.timelock.api;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
/**
* A contiguous range of timestamps, covering the range [start, start + count). This format is chosen to balance
* efficiency and readability.
*/
@JsonDeserialize(builder = ConjureTimestampRange.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureTimestampRange {
private final long start;
private final long count;
private int memoizedHashCode;
private ConjureTimestampRange(long start, long count) {
this.start = start;
this.count = count;
}
@JsonProperty("start")
public long getStart() {
return this.start;
}
@JsonProperty("count")
public long getCount() {
return this.count;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof ConjureTimestampRange && equalTo((ConjureTimestampRange) other));
}
private boolean equalTo(ConjureTimestampRange other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.start == other.start && this.count == other.count;
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
int hash = 1;
hash = 31 * hash + Long.hashCode(this.start);
hash = 31 * hash + Long.hashCode(this.count);
result = hash;
memoizedHashCode = result;
}
return result;
}
@Override
public String toString() {
return "ConjureTimestampRange{start: " + start + ", count: " + count + '}';
}
public static ConjureTimestampRange of(long start, long count) {
return builder().start(start).count(count).build();
}
public static Builder builder() {
return new Builder();
}
@Generated("com.palantir.conjure.java.types.BeanBuilderGenerator")
@JsonIgnoreProperties(ignoreUnknown = true)
public static final class Builder {
boolean _buildInvoked;
private long start;
private long count;
private boolean _startInitialized = false;
private boolean _countInitialized = false;
private Builder() {}
public Builder from(ConjureTimestampRange other) {
checkNotBuilt();
start(other.getStart());
count(other.getCount());
return this;
}
@JsonSetter("start")
public Builder start(long start) {
checkNotBuilt();
this.start = start;
this._startInitialized = true;
return this;
}
@JsonSetter("count")
public Builder count(long count) {
checkNotBuilt();
this.count = count;
this._countInitialized = true;
return this;
}
private void validatePrimitiveFieldsHaveBeenInitialized() {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, _startInitialized, "start");
missingFields = addFieldIfMissing(missingFields, _countInitialized, "count");
if (missingFields != null) {
throw new SafeIllegalArgumentException(
"Some required fields have not been set", SafeArg.of("missingFields", missingFields));
}
}
private static List addFieldIfMissing(List prev, boolean initialized, String fieldName) {
List missingFields = prev;
if (!initialized) {
if (missingFields == null) {
missingFields = new ArrayList<>(2);
}
missingFields.add(fieldName);
}
return missingFields;
}
public ConjureTimestampRange build() {
checkNotBuilt();
this._buildInvoked = true;
validatePrimitiveFieldsHaveBeenInitialized();
return new ConjureTimestampRange(start, count);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}