summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-10-21 16:22:27 +0200
committerJon Bratseth <bratseth@gmail.com>2021-10-21 16:22:27 +0200
commitc46b73e2271d133d096784b0ff41ac27011f70fc (patch)
tree89b66d1dd2934e46cbeb264662920a6abc40dd44 /config-model/src/main/java/com
parent9abe019606f2367b05e4e13d796de65dddf7c449 (diff)
Use optional
Diffstat (limited to 'config-model/src/main/java/com')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java2
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java33
2 files changed, 16 insertions, 19 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java
index ff0a0d07102..e11f7d370c5 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java
@@ -23,7 +23,7 @@ public class ImplicitSummaryFields extends Processor {
@Override
public void process(boolean validate, boolean documentsOnly) {
for (DocumentSummary docsum : schema.getSummariesInThis().values()) {
- if (docsum.getInherited() != null) continue; // Implicit fields are added to inheriting summaries through their parent
+ if (docsum.inherited().isPresent()) continue; // Implicit fields are added to inheriting summaries through their parent
addField(docsum, new SummaryField("rankfeatures", DataType.STRING, SummaryTransform.RANKFEATURES), validate);
addField(docsum, new SummaryField("summaryfeatures", DataType.STRING, SummaryTransform.SUMMARYFEATURES), validate);
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java
index 967e662dc6b..90ab6ad8fa1 100644
--- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java
+++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java
@@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Optional;
import java.util.logging.Level;
/**
@@ -19,7 +20,7 @@ public class DocumentSummary extends FieldView {
private boolean fromDisk = false;
private boolean omitSummaryFeatures = false;
- private String inherited;
+ private Optional<String> inherited = Optional.empty();
private final Schema owner;
@@ -57,20 +58,16 @@ public class DocumentSummary extends FieldView {
public SummaryField getSummaryField(String name) {
var field = (SummaryField)get(name);
if (field != null) return field;
- if (getInherited() == null) return null;
- return getInherited().getSummaryField(name);
+ if (inherited().isEmpty()) return null;
+ return inherited().get().getSummaryField(name);
}
// TODO: This does not handle overriding in child summaries correctly
public Collection<SummaryField> getSummaryFields() {
var fields = new ArrayList<SummaryField>(getFields().size());
- var parent = getInherited();
- if (parent != null) {
- fields.addAll(parent.getSummaryFields());
- }
- for (var field : getFields()) {
+ inherited().ifPresent(inherited -> fields.addAll(inherited.getSummaryFields()));
+ for (var field : getFields())
fields.add((SummaryField) field);
- }
return fields;
}
@@ -101,12 +98,12 @@ public class DocumentSummary extends FieldView {
/** Sets the parent of this. Both summaries must be present in the same search definition */
public void setInherited(String inherited) {
- this.inherited = inherited;
+ this.inherited = Optional.of(inherited);
}
- /** Returns the parent of this, or null if none is inherited */
- public DocumentSummary getInherited() {
- return owner.getSummary(inherited);
+ /** Returns the parent of this, if any */
+ public Optional<DocumentSummary> inherited() {
+ return inherited.map(name -> owner.getSummary(name));
}
@Override
@@ -115,14 +112,14 @@ public class DocumentSummary extends FieldView {
}
public void validate(DeployLogger logger) {
- if (inherited != null) {
- if ( ! owner.getSummaries().containsKey(inherited)) {
+ if (inherited.isPresent()) {
+ if ( ! owner.getSummaries().containsKey(inherited.get())) {
logger.log(Level.WARNING,
- this + " inherits " + inherited + " but this" + " is not present in " + owner);
+ this + " inherits " + inherited.get() + " but this" + " is not present in " + owner);
logger.logApplicationPackage(Level.WARNING,
- this + " inherits " + inherited + " but this" + " is not present in " + owner);
+ this + " inherits " + inherited.get() + " but this" + " is not present in " + owner);
// TODO: When safe, replace the above by
- // throw new IllegalArgumentException(this + " inherits " + inherited + " but this" +
+ // throw new IllegalArgumentException(this + " inherits " + inherited.get() + " but this" +
// " is not present in " + owner);
// ... and update SummaryTestCase.testValidationOfInheritedSummary
}