Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
data containers: check that val is non-null
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Sobolev committed Nov 13, 2017
1 parent c2b9794 commit af091d6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion java/core/src/main/java/ws/epigraph/data/BooleanDatum.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion java/core/src/main/java/ws/epigraph/data/IntegerDatum.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions java/core/src/main/java/ws/epigraph/data/ListDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
3 changes: 2 additions & 1 deletion java/core/src/main/java/ws/epigraph/data/LongDatum.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions java/core/src/main/java/ws/epigraph/data/MapDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
3 changes: 2 additions & 1 deletion java/core/src/main/java/ws/epigraph/data/StringDatum.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions java/core/src/main/java/ws/epigraph/types/StringType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion java/util/src/main/java/ws/epigraph/util/WordUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static String suggest(String mistype, Collection<String> 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);
}

Expand Down

0 comments on commit af091d6

Please sign in to comment.