diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-20 03:33:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-20 03:33:41 +0100 |
commit | f5dba6ff3c3451cc4688dcd90ca72c6e4e301946 (patch) | |
tree | 46a4a4e518971da3193d504e4f6b5bedd01b049b /vespajlib/src/main/java/com/yahoo/tensor/TensorType.java | |
parent | e63afccea9618396374a6488519b7a894f94ac3c (diff) | |
parent | 04677306ef130fad59efa29141b6fe7b185927fe (diff) |
Merge branch 'master' into balder/reduce-timestamp-usage
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/TensorType.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/TensorType.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java index ca3f8ff28a4..58cb151875e 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java @@ -2,9 +2,9 @@ package com.yahoo.tensor; import com.google.common.collect.ImmutableList; +import com.yahoo.text.Ascii7BitMatcher; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; @@ -15,6 +15,8 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import static com.yahoo.text.Ascii7BitMatcher.charsAndNumbers; + /** * A tensor type with its dimensions. This is immutable. * <p> @@ -25,6 +27,8 @@ import java.util.stream.Collectors; */ public class TensorType { + static Ascii7BitMatcher labelMatcher = new Ascii7BitMatcher("-_@" + charsAndNumbers(), "_@$" + charsAndNumbers()); + /** The permissible cell value types. Default is double. */ public enum Value { @@ -292,8 +296,7 @@ public class TensorType { private final String name; private Dimension(String name) { - Objects.requireNonNull(name, "A tensor name cannot be null"); - this.name = name; + this.name = requireIdentifier(name); } public final String name() { return name; } @@ -361,6 +364,14 @@ public class TensorType { return new MappedDimension(name); } + static private String requireIdentifier(String name) { + if (name == null) + throw new IllegalArgumentException("A dimension name cannot be null"); + if ( ! TensorType.labelMatcher.matches(name)) + throw new IllegalArgumentException("A dimension name must be an identifier or integer, not '" + name + "'"); + return name; + } + } public static class IndexedBoundDimension extends TensorType.Dimension { |