com.palantir.atlasdb.timelock.api.ConjureChangeMetadata 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.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.Unsafe;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
@Unsafe
@Generated("com.palantir.conjure.java.types.UnionGenerator")
public final class ConjureChangeMetadata {
private final Base value;
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
private ConjureChangeMetadata(Base value) {
this.value = value;
}
@JsonValue
private Base getValue() {
return value;
}
public static ConjureChangeMetadata unchanged(ConjureUnchangedChangeMetadata value) {
return new ConjureChangeMetadata(new UnchangedWrapper(value));
}
public static ConjureChangeMetadata updated(ConjureUpdatedChangeMetadata value) {
return new ConjureChangeMetadata(new UpdatedWrapper(value));
}
public static ConjureChangeMetadata deleted(ConjureDeletedChangeMetadata value) {
return new ConjureChangeMetadata(new DeletedWrapper(value));
}
public static ConjureChangeMetadata created(ConjureCreatedChangeMetadata value) {
return new ConjureChangeMetadata(new CreatedWrapper(value));
}
public static ConjureChangeMetadata unknown(@Safe String type, Object value) {
switch (Preconditions.checkNotNull(type, "Type is required")) {
case "unchanged":
throw new SafeIllegalArgumentException(
"Unknown type cannot be created as the provided type is known: unchanged");
case "updated":
throw new SafeIllegalArgumentException(
"Unknown type cannot be created as the provided type is known: updated");
case "deleted":
throw new SafeIllegalArgumentException(
"Unknown type cannot be created as the provided type is known: deleted");
case "created":
throw new SafeIllegalArgumentException(
"Unknown type cannot be created as the provided type is known: created");
default:
return new ConjureChangeMetadata(new UnknownWrapper(type, Collections.singletonMap(type, value)));
}
}
public T accept(Visitor visitor) {
return value.accept(visitor);
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof ConjureChangeMetadata && equalTo((ConjureChangeMetadata) other));
}
private boolean equalTo(ConjureChangeMetadata other) {
return this.value.equals(other.value);
}
@Override
public int hashCode() {
return this.value.hashCode();
}
@Override
@Unsafe
public String toString() {
return "ConjureChangeMetadata{value: " + value + '}';
}
public interface Visitor {
T visitUnchanged(ConjureUnchangedChangeMetadata value);
T visitUpdated(ConjureUpdatedChangeMetadata value);
T visitDeleted(ConjureDeletedChangeMetadata value);
T visitCreated(ConjureCreatedChangeMetadata value);
T visitUnknown(@Safe String unknownType);
static CreatedStageVisitorBuilder builder() {
return new VisitorBuilder();
}
}
private static final class VisitorBuilder
implements CreatedStageVisitorBuilder,
DeletedStageVisitorBuilder,
UnchangedStageVisitorBuilder,
UpdatedStageVisitorBuilder,
UnknownStageVisitorBuilder,
Completed_StageVisitorBuilder {
private Function createdVisitor;
private Function deletedVisitor;
private Function unchangedVisitor;
private Function updatedVisitor;
private Function unknownVisitor;
@Override
public DeletedStageVisitorBuilder created(
@Nonnull Function createdVisitor) {
Preconditions.checkNotNull(createdVisitor, "createdVisitor cannot be null");
this.createdVisitor = createdVisitor;
return this;
}
@Override
public UnchangedStageVisitorBuilder deleted(
@Nonnull Function deletedVisitor) {
Preconditions.checkNotNull(deletedVisitor, "deletedVisitor cannot be null");
this.deletedVisitor = deletedVisitor;
return this;
}
@Override
public UpdatedStageVisitorBuilder unchanged(
@Nonnull Function unchangedVisitor) {
Preconditions.checkNotNull(unchangedVisitor, "unchangedVisitor cannot be null");
this.unchangedVisitor = unchangedVisitor;
return this;
}
@Override
public UnknownStageVisitorBuilder updated(
@Nonnull Function updatedVisitor) {
Preconditions.checkNotNull(updatedVisitor, "updatedVisitor cannot be null");
this.updatedVisitor = updatedVisitor;
return this;
}
@Override
public Completed_StageVisitorBuilder unknown(@Nonnull Function unknownVisitor) {
Preconditions.checkNotNull(unknownVisitor, "unknownVisitor cannot be null");
this.unknownVisitor = unknownVisitor;
return this;
}
@Override
public Completed_StageVisitorBuilder throwOnUnknown() {
this.unknownVisitor = unknownType -> {
throw new SafeIllegalArgumentException(
"Unknown variant of the 'ConjureChangeMetadata' union", SafeArg.of("unknownType", unknownType));
};
return this;
}
@Override
public Visitor build() {
final Function createdVisitor = this.createdVisitor;
final Function deletedVisitor = this.deletedVisitor;
final Function unchangedVisitor = this.unchangedVisitor;
final Function updatedVisitor = this.updatedVisitor;
final Function unknownVisitor = this.unknownVisitor;
return new Visitor() {
@Override
public T visitCreated(ConjureCreatedChangeMetadata value) {
return createdVisitor.apply(value);
}
@Override
public T visitDeleted(ConjureDeletedChangeMetadata value) {
return deletedVisitor.apply(value);
}
@Override
public T visitUnchanged(ConjureUnchangedChangeMetadata value) {
return unchangedVisitor.apply(value);
}
@Override
public T visitUpdated(ConjureUpdatedChangeMetadata value) {
return updatedVisitor.apply(value);
}
@Override
public T visitUnknown(String value) {
return unknownVisitor.apply(value);
}
};
}
}
public interface CreatedStageVisitorBuilder {
DeletedStageVisitorBuilder created(@Nonnull Function createdVisitor);
}
public interface DeletedStageVisitorBuilder {
UnchangedStageVisitorBuilder deleted(@Nonnull Function deletedVisitor);
}
public interface UnchangedStageVisitorBuilder {
UpdatedStageVisitorBuilder unchanged(@Nonnull Function unchangedVisitor);
}
public interface UpdatedStageVisitorBuilder {
UnknownStageVisitorBuilder updated(@Nonnull Function updatedVisitor);
}
public interface UnknownStageVisitorBuilder {
Completed_StageVisitorBuilder unknown(@Nonnull Function unknownVisitor);
Completed_StageVisitorBuilder throwOnUnknown();
}
public interface Completed_StageVisitorBuilder {
Visitor build();
}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true,
defaultImpl = UnknownWrapper.class)
@JsonSubTypes({
@JsonSubTypes.Type(UnchangedWrapper.class),
@JsonSubTypes.Type(UpdatedWrapper.class),
@JsonSubTypes.Type(DeletedWrapper.class),
@JsonSubTypes.Type(CreatedWrapper.class)
})
@JsonIgnoreProperties(ignoreUnknown = true)
private interface Base {
T accept(Visitor visitor);
}
@JsonTypeName("unchanged")
private static final class UnchangedWrapper implements Base {
private final ConjureUnchangedChangeMetadata value;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private UnchangedWrapper(@JsonSetter("unchanged") @Nonnull ConjureUnchangedChangeMetadata value) {
Preconditions.checkNotNull(value, "unchanged cannot be null");
this.value = value;
}
@JsonProperty(value = "type", index = 0)
private String getType() {
return "unchanged";
}
@JsonProperty("unchanged")
private ConjureUnchangedChangeMetadata getValue() {
return value;
}
@Override
public T accept(Visitor visitor) {
return visitor.visitUnchanged(value);
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof UnchangedWrapper && equalTo((UnchangedWrapper) other));
}
private boolean equalTo(UnchangedWrapper other) {
return this.value.equals(other.value);
}
@Override
public int hashCode() {
return this.value.hashCode();
}
@Override
public String toString() {
return "UnchangedWrapper{value: " + value + '}';
}
}
@JsonTypeName("updated")
private static final class UpdatedWrapper implements Base {
private final ConjureUpdatedChangeMetadata value;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private UpdatedWrapper(@JsonSetter("updated") @Nonnull ConjureUpdatedChangeMetadata value) {
Preconditions.checkNotNull(value, "updated cannot be null");
this.value = value;
}
@JsonProperty(value = "type", index = 0)
private String getType() {
return "updated";
}
@JsonProperty("updated")
private ConjureUpdatedChangeMetadata getValue() {
return value;
}
@Override
public T accept(Visitor visitor) {
return visitor.visitUpdated(value);
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof UpdatedWrapper && equalTo((UpdatedWrapper) other));
}
private boolean equalTo(UpdatedWrapper other) {
return this.value.equals(other.value);
}
@Override
public int hashCode() {
return this.value.hashCode();
}
@Override
public String toString() {
return "UpdatedWrapper{value: " + value + '}';
}
}
@JsonTypeName("deleted")
private static final class DeletedWrapper implements Base {
private final ConjureDeletedChangeMetadata value;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private DeletedWrapper(@JsonSetter("deleted") @Nonnull ConjureDeletedChangeMetadata value) {
Preconditions.checkNotNull(value, "deleted cannot be null");
this.value = value;
}
@JsonProperty(value = "type", index = 0)
private String getType() {
return "deleted";
}
@JsonProperty("deleted")
private ConjureDeletedChangeMetadata getValue() {
return value;
}
@Override
public T accept(Visitor visitor) {
return visitor.visitDeleted(value);
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof DeletedWrapper && equalTo((DeletedWrapper) other));
}
private boolean equalTo(DeletedWrapper other) {
return this.value.equals(other.value);
}
@Override
public int hashCode() {
return this.value.hashCode();
}
@Override
public String toString() {
return "DeletedWrapper{value: " + value + '}';
}
}
@JsonTypeName("created")
private static final class CreatedWrapper implements Base {
private final ConjureCreatedChangeMetadata value;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private CreatedWrapper(@JsonSetter("created") @Nonnull ConjureCreatedChangeMetadata value) {
Preconditions.checkNotNull(value, "created cannot be null");
this.value = value;
}
@JsonProperty(value = "type", index = 0)
private String getType() {
return "created";
}
@JsonProperty("created")
private ConjureCreatedChangeMetadata getValue() {
return value;
}
@Override
public T accept(Visitor visitor) {
return visitor.visitCreated(value);
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof CreatedWrapper && equalTo((CreatedWrapper) other));
}
private boolean equalTo(CreatedWrapper other) {
return this.value.equals(other.value);
}
@Override
public int hashCode() {
return this.value.hashCode();
}
@Override
public String toString() {
return "CreatedWrapper{value: " + value + '}';
}
}
private static final class UnknownWrapper implements Base {
private final String type;
private final Map value;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private UnknownWrapper(@JsonProperty("type") String type) {
this(type, new HashMap());
}
private UnknownWrapper(@Nonnull String type, @Nonnull Map value) {
Preconditions.checkNotNull(type, "type cannot be null");
Preconditions.checkNotNull(value, "value cannot be null");
this.type = type;
this.value = value;
}
@JsonProperty
private String getType() {
return type;
}
@JsonAnyGetter
private Map getValue() {
return value;
}
@JsonAnySetter
private void put(String key, Object val) {
value.put(key, val);
}
@Override
public T accept(Visitor visitor) {
return visitor.visitUnknown(type);
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof UnknownWrapper && equalTo((UnknownWrapper) other));
}
private boolean equalTo(UnknownWrapper other) {
return this.type.equals(other.type) && this.value.equals(other.value);
}
@Override
public int hashCode() {
int hash = 1;
hash = 31 * hash + this.type.hashCode();
hash = 31 * hash + this.value.hashCode();
return hash;
}
@Override
public String toString() {
return "UnknownWrapper{type: " + type + ", value: " + value + '}';
}
}
}