Skip to content

Commit

Permalink
Conjure enums are no longer case sensitive
Browse files Browse the repository at this point in the history
The Conjure specification requires upper case string values for
enum constants. Updated null validation to use safe-loggable
exceptions.
  • Loading branch information
carterkozak committed Jan 10, 2019
1 parent 76b90c7 commit cc534b7
Show file tree
Hide file tree
Showing 29 changed files with 223 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -219,12 +220,12 @@ public Builder from(AliasAsMapKeyExample other) {
@JsonSetter("strings")
public Builder strings(Map<StringAliasExample, ManyFieldExample> strings) {
this.strings.clear();
this.strings.putAll(Objects.requireNonNull(strings, "strings cannot be null"));
this.strings.putAll(Preconditions.checkNotNull(strings, "strings cannot be null"));
return this;
}

public Builder putAllStrings(Map<StringAliasExample, ManyFieldExample> strings) {
this.strings.putAll(Objects.requireNonNull(strings, "strings cannot be null"));
this.strings.putAll(Preconditions.checkNotNull(strings, "strings cannot be null"));
return this;
}

Expand All @@ -236,12 +237,12 @@ public Builder strings(StringAliasExample key, ManyFieldExample value) {
@JsonSetter("rids")
public Builder rids(Map<RidAliasExample, ManyFieldExample> rids) {
this.rids.clear();
this.rids.putAll(Objects.requireNonNull(rids, "rids cannot be null"));
this.rids.putAll(Preconditions.checkNotNull(rids, "rids cannot be null"));
return this;
}

public Builder putAllRids(Map<RidAliasExample, ManyFieldExample> rids) {
this.rids.putAll(Objects.requireNonNull(rids, "rids cannot be null"));
this.rids.putAll(Preconditions.checkNotNull(rids, "rids cannot be null"));
return this;
}

Expand All @@ -254,14 +255,14 @@ public Builder rids(RidAliasExample key, ManyFieldExample value) {
public Builder bearertokens(Map<BearerTokenAliasExample, ManyFieldExample> bearertokens) {
this.bearertokens.clear();
this.bearertokens.putAll(
Objects.requireNonNull(bearertokens, "bearertokens cannot be null"));
Preconditions.checkNotNull(bearertokens, "bearertokens cannot be null"));
return this;
}

public Builder putAllBearertokens(
Map<BearerTokenAliasExample, ManyFieldExample> bearertokens) {
this.bearertokens.putAll(
Objects.requireNonNull(bearertokens, "bearertokens cannot be null"));
Preconditions.checkNotNull(bearertokens, "bearertokens cannot be null"));
return this;
}

Expand All @@ -273,12 +274,12 @@ public Builder bearertokens(BearerTokenAliasExample key, ManyFieldExample value)
@JsonSetter("integers")
public Builder integers(Map<IntegerAliasExample, ManyFieldExample> integers) {
this.integers.clear();
this.integers.putAll(Objects.requireNonNull(integers, "integers cannot be null"));
this.integers.putAll(Preconditions.checkNotNull(integers, "integers cannot be null"));
return this;
}

public Builder putAllIntegers(Map<IntegerAliasExample, ManyFieldExample> integers) {
this.integers.putAll(Objects.requireNonNull(integers, "integers cannot be null"));
this.integers.putAll(Preconditions.checkNotNull(integers, "integers cannot be null"));
return this;
}

Expand All @@ -290,12 +291,14 @@ public Builder integers(IntegerAliasExample key, ManyFieldExample value) {
@JsonSetter("safelongs")
public Builder safelongs(Map<SafeLongAliasExample, ManyFieldExample> safelongs) {
this.safelongs.clear();
this.safelongs.putAll(Objects.requireNonNull(safelongs, "safelongs cannot be null"));
this.safelongs.putAll(
Preconditions.checkNotNull(safelongs, "safelongs cannot be null"));
return this;
}

public Builder putAllSafelongs(Map<SafeLongAliasExample, ManyFieldExample> safelongs) {
this.safelongs.putAll(Objects.requireNonNull(safelongs, "safelongs cannot be null"));
this.safelongs.putAll(
Preconditions.checkNotNull(safelongs, "safelongs cannot be null"));
return this;
}

Expand All @@ -307,12 +310,14 @@ public Builder safelongs(SafeLongAliasExample key, ManyFieldExample value) {
@JsonSetter("datetimes")
public Builder datetimes(Map<DateTimeAliasExample, ManyFieldExample> datetimes) {
this.datetimes.clear();
this.datetimes.putAll(Objects.requireNonNull(datetimes, "datetimes cannot be null"));
this.datetimes.putAll(
Preconditions.checkNotNull(datetimes, "datetimes cannot be null"));
return this;
}

public Builder putAllDatetimes(Map<DateTimeAliasExample, ManyFieldExample> datetimes) {
this.datetimes.putAll(Objects.requireNonNull(datetimes, "datetimes cannot be null"));
this.datetimes.putAll(
Preconditions.checkNotNull(datetimes, "datetimes cannot be null"));
return this;
}

Expand All @@ -324,12 +329,12 @@ public Builder datetimes(DateTimeAliasExample key, ManyFieldExample value) {
@JsonSetter("uuids")
public Builder uuids(Map<UuidAliasExample, ManyFieldExample> uuids) {
this.uuids.clear();
this.uuids.putAll(Objects.requireNonNull(uuids, "uuids cannot be null"));
this.uuids.putAll(Preconditions.checkNotNull(uuids, "uuids cannot be null"));
return this;
}

public Builder putAllUuids(Map<UuidAliasExample, ManyFieldExample> uuids) {
this.uuids.putAll(Objects.requireNonNull(uuids, "uuids cannot be null"));
this.uuids.putAll(Preconditions.checkNotNull(uuids, "uuids cannot be null"));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -100,7 +101,7 @@ public Builder from(AnyExample other) {

@JsonSetter("any")
public Builder any(Object any) {
this.any = Objects.requireNonNull(any, "any cannot be null");
this.any = Preconditions.checkNotNull(any, "any cannot be null");
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -104,12 +105,12 @@ public Builder from(AnyMapExample other) {
@JsonSetter("items")
public Builder items(Map<String, Object> items) {
this.items.clear();
this.items.putAll(Objects.requireNonNull(items, "items cannot be null"));
this.items.putAll(Preconditions.checkNotNull(items, "items cannot be null"));
return this;
}

public Builder putAllItems(Map<String, Object> items) {
this.items.putAll(Objects.requireNonNull(items, "items cannot be null"));
this.items.putAll(Preconditions.checkNotNull(items, "items cannot be null"));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 com.palantir.tokens.auth.BearerToken;
Expand Down Expand Up @@ -103,7 +104,7 @@ public Builder from(BearerTokenExample other) {
@JsonSetter("bearerTokenValue")
public Builder bearerTokenValue(BearerToken bearerTokenValue) {
this.bearerTokenValue =
Objects.requireNonNull(bearerTokenValue, "bearerTokenValue cannot be null");
Preconditions.checkNotNull(bearerTokenValue, "bearerTokenValue cannot be null");
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.nio.ByteBuffer;
Expand Down Expand Up @@ -101,7 +102,7 @@ public Builder from(BinaryExample other) {

@JsonSetter("binary")
public Builder binary(ByteBuffer binary) {
Objects.requireNonNull(binary, "binary cannot be null");
Preconditions.checkNotNull(binary, "binary cannot be null");
this.binary = ByteBuffer.allocate(binary.remaining()).put(binary.duplicate());
this.binary.rewind();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.palantir.conjure.java.lib.internal.ConjureCollections;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
Expand Down Expand Up @@ -124,13 +125,13 @@ public Builder from(CovariantListExample other) {
public Builder items(Iterable<?> items) {
this.items.clear();
ConjureCollections.addAll(
this.items, Objects.requireNonNull(items, "items cannot be null"));
this.items, Preconditions.checkNotNull(items, "items cannot be null"));
return this;
}

public Builder addAllItems(Iterable<?> items) {
ConjureCollections.addAll(
this.items, Objects.requireNonNull(items, "items cannot be null"));
this.items, Preconditions.checkNotNull(items, "items cannot be null"));
return this;
}

Expand All @@ -144,15 +145,15 @@ public Builder externalItems(Iterable<? extends ExampleExternalReference> extern
this.externalItems.clear();
ConjureCollections.addAll(
this.externalItems,
Objects.requireNonNull(externalItems, "externalItems cannot be null"));
Preconditions.checkNotNull(externalItems, "externalItems cannot be null"));
return this;
}

public Builder addAllExternalItems(
Iterable<? extends ExampleExternalReference> externalItems) {
ConjureCollections.addAll(
this.externalItems,
Objects.requireNonNull(externalItems, "externalItems cannot be null"));
Preconditions.checkNotNull(externalItems, "externalItems cannot be null"));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -103,12 +104,12 @@ public Builder from(CovariantOptionalExample other) {

@JsonSetter("item")
public Builder item(Optional<?> item) {
this.item = (Optional<Object>) Objects.requireNonNull(item, "item cannot be null");
this.item = (Optional<Object>) Preconditions.checkNotNull(item, "item cannot be null");
return this;
}

public Builder item(Object item) {
this.item = Optional.of(Objects.requireNonNull(item, "item cannot be null"));
this.item = Optional.of(Preconditions.checkNotNull(item, "item cannot be null"));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.time.OffsetDateTime;
Expand Down Expand Up @@ -102,7 +103,7 @@ public Builder from(DateTimeExample other) {

@JsonSetter("datetime")
public Builder datetime(OffsetDateTime datetime) {
this.datetime = Objects.requireNonNull(datetime, "datetime cannot be null");
this.datetime = Preconditions.checkNotNull(datetime, "datetime cannot be null");
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Locale;
import java.util.Objects;
import com.palantir.conjure.java.lib.internal.ConjureEnums;
import com.palantir.logsafe.Preconditions;
import javax.annotation.Generated;

/**
Expand Down Expand Up @@ -61,17 +61,17 @@ public int hashCode() {

@JsonCreator
public static EnumExample valueOf(String value) {
Objects.requireNonNull(value, "value cannot be null");
String upperCasedValue = value.toUpperCase(Locale.ROOT);
switch (upperCasedValue) {
Preconditions.checkNotNull(value, "value cannot be null");
switch (value) {
case "ONE":
return ONE;
case "TWO":
return TWO;
case "ONE_HUNDRED":
return ONE_HUNDRED;
default:
return new EnumExample(Value.UNKNOWN, upperCasedValue);
ConjureEnums.validate(value);
return new EnumExample(Value.UNKNOWN, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -101,7 +102,7 @@ public Builder from(EnumFieldExample other) {

@JsonSetter("enum")
public Builder enum_(EnumExample enum_) {
this.enum_ = Objects.requireNonNull(enum_, "enum cannot be null");
this.enum_ = Preconditions.checkNotNull(enum_, "enum cannot be null");
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.palantir.conjure.java.lib.internal.ConjureCollections;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
Expand Down Expand Up @@ -145,13 +146,13 @@ public Builder from(ListExample other) {
public Builder items(Iterable<String> items) {
this.items.clear();
ConjureCollections.addAll(
this.items, Objects.requireNonNull(items, "items cannot be null"));
this.items, Preconditions.checkNotNull(items, "items cannot be null"));
return this;
}

public Builder addAllItems(Iterable<String> items) {
ConjureCollections.addAll(
this.items, Objects.requireNonNull(items, "items cannot be null"));
this.items, Preconditions.checkNotNull(items, "items cannot be null"));
return this;
}

Expand All @@ -165,14 +166,14 @@ public Builder primitiveItems(Iterable<Integer> primitiveItems) {
this.primitiveItems.clear();
ConjureCollections.addAll(
this.primitiveItems,
Objects.requireNonNull(primitiveItems, "primitiveItems cannot be null"));
Preconditions.checkNotNull(primitiveItems, "primitiveItems cannot be null"));
return this;
}

public Builder addAllPrimitiveItems(Iterable<Integer> primitiveItems) {
ConjureCollections.addAll(
this.primitiveItems,
Objects.requireNonNull(primitiveItems, "primitiveItems cannot be null"));
Preconditions.checkNotNull(primitiveItems, "primitiveItems cannot be null"));
return this;
}

Expand All @@ -186,14 +187,14 @@ public Builder doubleItems(Iterable<Double> doubleItems) {
this.doubleItems.clear();
ConjureCollections.addAll(
this.doubleItems,
Objects.requireNonNull(doubleItems, "doubleItems cannot be null"));
Preconditions.checkNotNull(doubleItems, "doubleItems cannot be null"));
return this;
}

public Builder addAllDoubleItems(Iterable<Double> doubleItems) {
ConjureCollections.addAll(
this.doubleItems,
Objects.requireNonNull(doubleItems, "doubleItems cannot be null"));
Preconditions.checkNotNull(doubleItems, "doubleItems cannot be null"));
return this;
}

Expand Down
Loading

0 comments on commit cc534b7

Please sign in to comment.