diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-13 10:56:31 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-05-13 10:56:31 +0200 |
commit | 1e62a108f450145f30e3b2da01b812c507870d2f (patch) | |
tree | 707262dada37388b9eae234925c6f0c14f8457be /config-model/src/main/java/com/yahoo | |
parent | 21f9fc667fdef60be1692cc2e3468879d3cc4cc0 (diff) |
Make immutable
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java index c9b0ed2f628..8de86beacdb 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/FileDistributedConstants.java @@ -20,54 +20,30 @@ import java.util.function.Function; */ public class FileDistributedConstants { - private final FileRegistry fileRegistry; - - private final Map<String, DistributableConstant> constants = new LinkedHashMap<>(); + private final Map<String, DistributableConstant> constants; public FileDistributedConstants(FileRegistry fileRegistry, Collection<RankProfile.Constant> constants) { - this.fileRegistry = fileRegistry; + Map<String, DistributableConstant> distributableConstants = new LinkedHashMap<>(); for (var constant : constants) { - if (constant.valuePath().isPresent()) - add(new DistributableConstant(constant.name().simpleArgument().get(), - constant.type(), - constant.valuePath().get(), - constant.pathType().get())); + if ( ! constant.valuePath().isPresent()) continue; + + var distributableConstant = new DistributableConstant(constant.name().simpleArgument().get(), + constant.type(), + constant.valuePath().get(), + constant.pathType().get()); + distributableConstant.validate(); + distributableConstant.register(fileRegistry); + distributableConstants.put(distributableConstant.getName(), distributableConstant); } - } - - public void add(DistributableConstant constant) { - constant.validate(); - constant.register(fileRegistry); - String name = constant.getName(); - DistributableConstant prev = constants.putIfAbsent(name, constant); - if ( prev != null ) - throw new IllegalArgumentException("Constant '" + name + "' defined twice"); - } - - public void putIfAbsent(DistributableConstant constant) { - constant.validate(); - constant.register(fileRegistry); - String name = constant.getName(); - constants.putIfAbsent(name, constant); - } - - public void computeIfAbsent(String name, Function<? super String, ? extends DistributableConstant> createConstant) { - constants.computeIfAbsent(name, key -> { - DistributableConstant constant = createConstant.apply(key); - constant.validate(); - constant.register(fileRegistry); - return constant; - }); + this.constants = Collections.unmodifiableMap(distributableConstants); } /** Returns a read-only map of the constants in this indexed by name. */ - public Map<String, DistributableConstant> asMap() { - return Collections.unmodifiableMap(constants); - } + public Map<String, DistributableConstant> asMap() { return constants; } public static class DistributableConstant extends DistributableResource { - private TensorType tensorType; + private final TensorType tensorType; public DistributableConstant(String name, TensorType type, String fileName) { this(name, type, fileName, PathType.FILE); @@ -79,10 +55,6 @@ public class FileDistributedConstants { validate(); } - public void setType(TensorType type) { - this.tensorType = type; - } - public TensorType getTensorType() { return tensorType; } public String getType() { return tensorType.toString(); } |