diff --git a/java/core/src/main/java/ws/epigraph/data/BooleanDatum.java b/java/core/src/main/java/ws/epigraph/data/BooleanDatum.java index e9c81011f..40313df2f 100644 --- a/java/core/src/main/java/ws/epigraph/data/BooleanDatum.java +++ b/java/core/src/main/java/ws/epigraph/data/BooleanDatum.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Sumo Logic + * Copyright 2017 Sumo Logic * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,6 +193,7 @@ public static final class Raw extends BooleanDatum.Builder implements BooleanDat public Raw(@NotNull BooleanType type, @NotNull Boolean val) { super(type); + if (val == null) throw new IllegalArgumentException(); this.val = val; } diff --git a/java/core/src/main/java/ws/epigraph/data/IntegerDatum.java b/java/core/src/main/java/ws/epigraph/data/IntegerDatum.java index 484cc0b69..b8593f54a 100644 --- a/java/core/src/main/java/ws/epigraph/data/IntegerDatum.java +++ b/java/core/src/main/java/ws/epigraph/data/IntegerDatum.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Sumo Logic + * Copyright 2017 Sumo Logic * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,6 +193,7 @@ public static final class Raw extends IntegerDatum.Builder implements IntegerDat public Raw(@NotNull IntegerType type, @NotNull Integer val) { super(type); + if (val == null) throw new IllegalArgumentException(); this.val = val; } diff --git a/java/core/src/main/java/ws/epigraph/data/ListDatum.java b/java/core/src/main/java/ws/epigraph/data/ListDatum.java index f203062cd..5d87b592b 100644 --- a/java/core/src/main/java/ws/epigraph/data/ListDatum.java +++ b/java/core/src/main/java/ws/epigraph/data/ListDatum.java @@ -156,6 +156,7 @@ protected Impl( super(type); // TODO check types are compatible this.raw = raw; // TODO validate raw internals is kosher? + if (raw == null) throw new IllegalArgumentException(); this.value = immValConstructor.apply(new Val.Imm.Raw.DatumVal(this)); } diff --git a/java/core/src/main/java/ws/epigraph/data/LongDatum.java b/java/core/src/main/java/ws/epigraph/data/LongDatum.java index 69db53385..962b053ff 100644 --- a/java/core/src/main/java/ws/epigraph/data/LongDatum.java +++ b/java/core/src/main/java/ws/epigraph/data/LongDatum.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Sumo Logic + * Copyright 2017 Sumo Logic * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,6 +193,7 @@ public static final class Raw extends LongDatum.Builder implements LongDatum.Raw public Raw(@NotNull LongType type, @NotNull Long val) { super(type); + if (val == null) throw new IllegalArgumentException(); this.val = val; } diff --git a/java/core/src/main/java/ws/epigraph/data/MapDatum.java b/java/core/src/main/java/ws/epigraph/data/MapDatum.java index d68b01d6d..fa028d2df 100644 --- a/java/core/src/main/java/ws/epigraph/data/MapDatum.java +++ b/java/core/src/main/java/ws/epigraph/data/MapDatum.java @@ -163,6 +163,7 @@ protected Impl( super(type); // TODO check types are compatible this.raw = raw; // TODO validate raw internals is kosher (i.e. contains static datums)? + if (raw == null) throw new IllegalArgumentException(); this.value = immValConstructor.apply(new Val.Imm.Raw.DatumVal(this)); } diff --git a/java/core/src/main/java/ws/epigraph/data/StringDatum.java b/java/core/src/main/java/ws/epigraph/data/StringDatum.java index 0188ec8e0..e5d8a334c 100644 --- a/java/core/src/main/java/ws/epigraph/data/StringDatum.java +++ b/java/core/src/main/java/ws/epigraph/data/StringDatum.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Sumo Logic + * Copyright 2017 Sumo Logic * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -195,6 +195,7 @@ public static final class Raw extends StringDatum.Builder public Raw(@NotNull StringType type, @NotNull String val) { super(type); + if (val == null) throw new IllegalArgumentException(); this.val = val; } diff --git a/java/core/src/main/java/ws/epigraph/types/StringType.java b/java/core/src/main/java/ws/epigraph/types/StringType.java index b1a68d55f..b03818458 100644 --- a/java/core/src/main/java/ws/epigraph/types/StringType.java +++ b/java/core/src/main/java/ws/epigraph/types/StringType.java @@ -124,11 +124,19 @@ protected Static( return datumBuilderConstructor.apply(new StringDatum.Builder.Raw(this, val)); } + public final @NotNull MyDatumBuilder createBuilder(@NotNull CharSequence val) { + return createBuilder(val.toString()); + } + @Override public final @NotNull MyImmVal createValueOfNullable(@Nullable String val) { return val == null ? createValue(null) : createBuilder(val).asValue().toImmutable(); } + public final @NotNull MyImmVal createValueOfNullable(@Nullable CharSequence val) { + return createValueOfNullable(val == null ? null : val.toString()); + } + @Override public final @NotNull MyImmVal createValue(@Nullable ErrorValue errorOrNull) { return immValConstructor.apply(Val.Imm.Raw.create(errorOrNull)); diff --git a/java/util/src/main/java/ws/epigraph/util/WordUtil.java b/java/util/src/main/java/ws/epigraph/util/WordUtil.java index 8e98ad643..800c046c5 100644 --- a/java/util/src/main/java/ws/epigraph/util/WordUtil.java +++ b/java/util/src/main/java/ws/epigraph/util/WordUtil.java @@ -37,7 +37,7 @@ public static String suggest(String mistype, Collection options, String return toDistance.entrySet().stream() .filter(e -> e.getValue() >= threshold) .max(Map.Entry.comparingByValue()) - .map(e -> String.format(format, e.getValue())) + .map(e -> String.format(format, e.getKey())) .orElse(noSuggestion); }