All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.palantir.atlasdb.timelock.api.ConjureLockResponse Maven / Gradle / Ivy

There is a newer version: 0.1152.0
Show newest version
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.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;

@Generated("com.palantir.conjure.java.types.UnionGenerator")
public final class ConjureLockResponse {
    private final Base value;

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    private ConjureLockResponse(Base value) {
        this.value = value;
    }

    @JsonValue
    private Base getValue() {
        return value;
    }

    public static ConjureLockResponse successful(SuccessfulLockResponse value) {
        return new ConjureLockResponse(new SuccessfulWrapper(value));
    }

    public static ConjureLockResponse unsuccessful(UnsuccessfulLockResponse value) {
        return new ConjureLockResponse(new UnsuccessfulWrapper(value));
    }

    public static ConjureLockResponse unknown(@Safe String type, Object value) {
        switch (Preconditions.checkNotNull(type, "Type is required")) {
            case "successful":
                throw new SafeIllegalArgumentException(
                        "Unknown type cannot be created as the provided type is known: successful");
            case "unsuccessful":
                throw new SafeIllegalArgumentException(
                        "Unknown type cannot be created as the provided type is known: unsuccessful");
            default:
                return new ConjureLockResponse(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 ConjureLockResponse && equalTo((ConjureLockResponse) other));
    }

    private boolean equalTo(ConjureLockResponse other) {
        return this.value.equals(other.value);
    }

    @Override
    public int hashCode() {
        return this.value.hashCode();
    }

    @Override
    public String toString() {
        return "ConjureLockResponse{value: " + value + '}';
    }

    public interface Visitor {
        T visitSuccessful(SuccessfulLockResponse value);

        T visitUnsuccessful(UnsuccessfulLockResponse value);

        T visitUnknown(@Safe String unknownType);

        static  SuccessfulStageVisitorBuilder builder() {
            return new VisitorBuilder();
        }
    }

    private static final class VisitorBuilder
            implements SuccessfulStageVisitorBuilder,
                    UnsuccessfulStageVisitorBuilder,
                    UnknownStageVisitorBuilder,
                    Completed_StageVisitorBuilder {
        private Function successfulVisitor;

        private Function unsuccessfulVisitor;

        private Function unknownVisitor;

        @Override
        public UnsuccessfulStageVisitorBuilder successful(
                @Nonnull Function successfulVisitor) {
            Preconditions.checkNotNull(successfulVisitor, "successfulVisitor cannot be null");
            this.successfulVisitor = successfulVisitor;
            return this;
        }

        @Override
        public UnknownStageVisitorBuilder unsuccessful(
                @Nonnull Function unsuccessfulVisitor) {
            Preconditions.checkNotNull(unsuccessfulVisitor, "unsuccessfulVisitor cannot be null");
            this.unsuccessfulVisitor = unsuccessfulVisitor;
            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 'ConjureLockResponse' union", SafeArg.of("unknownType", unknownType));
            };
            return this;
        }

        @Override
        public Visitor build() {
            final Function successfulVisitor = this.successfulVisitor;
            final Function unsuccessfulVisitor = this.unsuccessfulVisitor;
            final Function unknownVisitor = this.unknownVisitor;
            return new Visitor() {
                @Override
                public T visitSuccessful(SuccessfulLockResponse value) {
                    return successfulVisitor.apply(value);
                }

                @Override
                public T visitUnsuccessful(UnsuccessfulLockResponse value) {
                    return unsuccessfulVisitor.apply(value);
                }

                @Override
                public T visitUnknown(String value) {
                    return unknownVisitor.apply(value);
                }
            };
        }
    }

    public interface SuccessfulStageVisitorBuilder {
        UnsuccessfulStageVisitorBuilder successful(@Nonnull Function successfulVisitor);
    }

    public interface UnsuccessfulStageVisitorBuilder {
        UnknownStageVisitorBuilder unsuccessful(@Nonnull Function unsuccessfulVisitor);
    }

    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(SuccessfulWrapper.class), @JsonSubTypes.Type(UnsuccessfulWrapper.class)})
    @JsonIgnoreProperties(ignoreUnknown = true)
    private interface Base {
         T accept(Visitor visitor);
    }

    @JsonTypeName("successful")
    private static final class SuccessfulWrapper implements Base {
        private final SuccessfulLockResponse value;

        @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
        private SuccessfulWrapper(@JsonSetter("successful") @Nonnull SuccessfulLockResponse value) {
            Preconditions.checkNotNull(value, "successful cannot be null");
            this.value = value;
        }

        @JsonProperty(value = "type", index = 0)
        private String getType() {
            return "successful";
        }

        @JsonProperty("successful")
        private SuccessfulLockResponse getValue() {
            return value;
        }

        @Override
        public  T accept(Visitor visitor) {
            return visitor.visitSuccessful(value);
        }

        @Override
        public boolean equals(@Nullable Object other) {
            return this == other || (other instanceof SuccessfulWrapper && equalTo((SuccessfulWrapper) other));
        }

        private boolean equalTo(SuccessfulWrapper other) {
            return this.value.equals(other.value);
        }

        @Override
        public int hashCode() {
            return this.value.hashCode();
        }

        @Override
        public String toString() {
            return "SuccessfulWrapper{value: " + value + '}';
        }
    }

    @JsonTypeName("unsuccessful")
    private static final class UnsuccessfulWrapper implements Base {
        private final UnsuccessfulLockResponse value;

        @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
        private UnsuccessfulWrapper(@JsonSetter("unsuccessful") @Nonnull UnsuccessfulLockResponse value) {
            Preconditions.checkNotNull(value, "unsuccessful cannot be null");
            this.value = value;
        }

        @JsonProperty(value = "type", index = 0)
        private String getType() {
            return "unsuccessful";
        }

        @JsonProperty("unsuccessful")
        private UnsuccessfulLockResponse getValue() {
            return value;
        }

        @Override
        public  T accept(Visitor visitor) {
            return visitor.visitUnsuccessful(value);
        }

        @Override
        public boolean equals(@Nullable Object other) {
            return this == other || (other instanceof UnsuccessfulWrapper && equalTo((UnsuccessfulWrapper) other));
        }

        private boolean equalTo(UnsuccessfulWrapper other) {
            return this.value.equals(other.value);
        }

        @Override
        public int hashCode() {
            return this.value.hashCode();
        }

        @Override
        public String toString() {
            return "UnsuccessfulWrapper{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 + '}';
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy