summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java103
-rw-r--r--config-model/src/main/java/com/yahoo/schema/document/SDDocumentType.java36
-rw-r--r--config-model/src/main/java/com/yahoo/schema/document/SDField.java13
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java10
4 files changed, 61 insertions, 101 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java b/config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java
index 57867bc7807..be3788a36c3 100644
--- a/config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java
+++ b/config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java
@@ -243,10 +243,9 @@ public class DocumentModelBuilder {
if (other == null || other == type) {
throw new IllegalArgumentException("No replacement found for temporary type: " + type);
}
- if (other instanceof OwnedStructDataType) {
+ if (other instanceof OwnedStructDataType otherOwned) {
var owned = (OwnedTemporaryType) type;
String ownedBy = owned.getOwnerName();
- var otherOwned = (OwnedStructDataType) other;
String otherOwnedBy = otherOwned.getOwnerName();
if (! ownedBy.equals(otherOwnedBy)) {
throw new IllegalArgumentException("Wrong document for type: " + otherOwnedBy + " but expected " + ownedBy);
@@ -268,12 +267,11 @@ public class DocumentModelBuilder {
if (other != null) {
type = other;
}
- } else if (type instanceof StructDataType) {
+ } else if (type instanceof StructDataType sdt) {
// trick avoids infinite recursion:
var old = replacements.put(original, type);
assert(old == null);
- StructDataType dt = (StructDataType) type;
- for (com.yahoo.document.Field field : dt.getFields()) {
+ for (com.yahoo.document.Field field : sdt.getFields()) {
var ft = field.getDataType();
var newft = resolveTemporariesRecurse(ft, repo, docs, replacements);
if (ft != newft) {
@@ -284,37 +282,33 @@ public class DocumentModelBuilder {
old = replacements.remove(original);
assert(old == type);
}
- else if (type instanceof MapDataType) {
- MapDataType t = (MapDataType) type;
- var old_kt = t.getKeyType();
- var old_vt = t.getValueType();
+ else if (type instanceof MapDataType mdt) {
+ var old_kt = mdt.getKeyType();
+ var old_vt = mdt.getValueType();
var kt = resolveTemporariesRecurse(old_kt, repo, docs, replacements);
var vt = resolveTemporariesRecurse(old_vt, repo, docs, replacements);
if (kt != old_kt || vt != old_vt) {
- type = new MapDataType(kt, vt, t.getId());
+ type = new MapDataType(kt, vt, mdt.getId());
}
}
- else if (type instanceof ArrayDataType) {
- ArrayDataType t = (ArrayDataType) type;
- var old_nt = t.getNestedType();
+ else if (type instanceof ArrayDataType adt) {
+ var old_nt = adt.getNestedType();
var nt = resolveTemporariesRecurse(old_nt, repo, docs, replacements);
if (nt != old_nt) {
- type = new ArrayDataType(nt, t.getId());
+ type = new ArrayDataType(nt, adt.getId());
}
}
- else if (type instanceof WeightedSetDataType) {
- WeightedSetDataType t = (WeightedSetDataType) type;
- var old_nt = t.getNestedType();
+ else if (type instanceof WeightedSetDataType wdt) {
+ var old_nt = wdt.getNestedType();
var nt = resolveTemporariesRecurse(old_nt, repo, docs, replacements);
if (nt != old_nt) {
- boolean c = t.createIfNonExistent();
- boolean r = t.removeIfZero();
- type = new WeightedSetDataType(nt, c, r, t.getId());
+ boolean c = wdt.createIfNonExistent();
+ boolean r = wdt.removeIfZero();
+ type = new WeightedSetDataType(nt, c, r, wdt.getId());
}
}
- else if (type instanceof NewDocumentReferenceDataType) {
- var t = (NewDocumentReferenceDataType) type;
- var doc = getDocumentType(docs, t.getTargetTypeName());
+ else if (type instanceof NewDocumentReferenceDataType rft) {
+ var doc = getDocumentType(docs, rft.getTargetTypeName());
type = doc.getReferenceDataType();
}
if (type != original) {
@@ -445,19 +439,16 @@ public class DocumentModelBuilder {
return;
}
inProgress.put(type, this);
- if (type instanceof StructDataType) {
- StructDataType tmp = (StructDataType) type;
- extractDataTypesFromFields(tmp.getFieldsThisTypeOnly());
- } else if (type instanceof CollectionDataType) {
- CollectionDataType tmp = (CollectionDataType) type;
- extractNestedTypes(tmp.getNestedType());
- addType(tmp.getNestedType());
- } else if (type instanceof MapDataType) {
- MapDataType tmp = (MapDataType) type;
- extractNestedTypes(tmp.getKeyType());
- extractNestedTypes(tmp.getValueType());
- addType(tmp.getKeyType());
- addType(tmp.getValueType());
+ if (type instanceof StructDataType sdt) {
+ extractDataTypesFromFields(sdt.getFieldsThisTypeOnly());
+ } else if (type instanceof CollectionDataType cdt) {
+ extractNestedTypes(cdt.getNestedType());
+ addType(cdt.getNestedType());
+ } else if (type instanceof MapDataType mdt) {
+ extractNestedTypes(mdt.getKeyType());
+ extractNestedTypes(mdt.getValueType());
+ addType(mdt.getKeyType());
+ addType(mdt.getValueType());
} else if (type instanceof TemporaryAnnotationReferenceDataType) {
throw new IllegalArgumentException(type.toString());
}
@@ -479,11 +470,9 @@ public class DocumentModelBuilder {
return false;
}
if (targetDt.getDataType(type.getId()) == null) {
- if ((oldType instanceof OwnedStructDataType)
- && (type instanceof OwnedStructDataType))
+ if ((oldType instanceof OwnedStructDataType oldOwned)
+ && (type instanceof OwnedStructDataType newOwned))
{
- var oldOwned = (OwnedStructDataType) oldType;
- var newOwned = (OwnedStructDataType) type;
if (newOwned.getOwnerName().equals(targetDt.getName()) &&
! oldOwned.getOwnerName().equals(targetDt.getName()))
{
@@ -494,10 +483,8 @@ public class DocumentModelBuilder {
}
}
}
- if ((type instanceof StructDataType) && (oldType instanceof StructDataType)) {
- StructDataType s = (StructDataType) type;
- StructDataType os = (StructDataType) oldType;
- if ((os.getFieldCount() == 0) && (s.getFieldCount() > os.getFieldCount())) {
+ if ((type instanceof StructDataType sdt) && (oldType instanceof StructDataType oldSdt)) {
+ if ((oldSdt.getFieldCount() == 0) && (sdt.getFieldCount() > oldSdt.getFieldCount())) {
if ( ! dryRun) {
targetDt.replace(type);
}
@@ -519,8 +506,7 @@ public class DocumentModelBuilder {
private DataType specialHandleAnnotationReferenceRecurse(String fieldName,
DataType dataType) {
- if (dataType instanceof TemporaryAnnotationReferenceDataType) {
- TemporaryAnnotationReferenceDataType refType = (TemporaryAnnotationReferenceDataType)dataType;
+ if (dataType instanceof TemporaryAnnotationReferenceDataType refType) {
if (refType.getId() != 0) {
return null;
}
@@ -533,35 +519,32 @@ public class DocumentModelBuilder {
addType(dataType);
return dataType;
}
- else if (dataType instanceof MapDataType) {
- MapDataType t = (MapDataType)dataType;
- DataType valueType = specialHandleAnnotationReferenceRecurse(fieldName, t.getValueType());
+ else if (dataType instanceof MapDataType mdt) {
+ DataType valueType = specialHandleAnnotationReferenceRecurse(fieldName, mdt.getValueType());
if (valueType == null) {
return null;
}
- var mapType = new MapDataType(t.getKeyType(), valueType, t.getId());
+ var mapType = new MapDataType(mdt.getKeyType(), valueType, mdt.getId());
addType(mapType);
return mapType;
}
- else if (dataType instanceof ArrayDataType) {
- ArrayDataType t = (ArrayDataType) dataType;
- DataType nestedType = specialHandleAnnotationReferenceRecurse(fieldName, t.getNestedType());
+ else if (dataType instanceof ArrayDataType adt) {
+ DataType nestedType = specialHandleAnnotationReferenceRecurse(fieldName, adt.getNestedType());
if (nestedType == null) {
return null;
}
- var lstType = new ArrayDataType(nestedType, t.getId());
+ var lstType = new ArrayDataType(nestedType, adt.getId());
addType(lstType);
return lstType;
}
- else if (dataType instanceof WeightedSetDataType) {
- WeightedSetDataType t = (WeightedSetDataType) dataType;
- DataType nestedType = specialHandleAnnotationReferenceRecurse(fieldName, t.getNestedType());
+ else if (dataType instanceof WeightedSetDataType wdt) {
+ DataType nestedType = specialHandleAnnotationReferenceRecurse(fieldName, wdt.getNestedType());
if (nestedType == null) {
return null;
}
- boolean c = t.createIfNonExistent();
- boolean r = t.removeIfZero();
- var lstType = new WeightedSetDataType(nestedType, c, r, t.getId());
+ boolean c = wdt.createIfNonExistent();
+ boolean r = wdt.removeIfZero();
+ var lstType = new WeightedSetDataType(nestedType, c, r, wdt.getId());
addType(lstType);
return lstType;
}
diff --git a/config-model/src/main/java/com/yahoo/schema/document/SDDocumentType.java b/config-model/src/main/java/com/yahoo/schema/document/SDDocumentType.java
index d300bd08bfd..d19b62ce555 100644
--- a/config-model/src/main/java/com/yahoo/schema/document/SDDocumentType.java
+++ b/config-model/src/main/java/com/yahoo/schema/document/SDDocumentType.java
@@ -15,8 +15,6 @@ import com.yahoo.schema.DocumentReferences;
import com.yahoo.schema.FieldSets;
import com.yahoo.schema.Schema;
-import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -33,7 +31,7 @@ import java.util.Set;
* @author Thomas Gundersen
* @author bratseth
*/
-public class SDDocumentType implements Cloneable, Serializable {
+public class SDDocumentType implements Cloneable {
public static final SDDocumentType VESPA_DOCUMENT;
private final Map<DataTypeName, SDDocumentType> inheritedTypes = new LinkedHashMap<>();
@@ -45,7 +43,7 @@ public class SDDocumentType implements Cloneable, Serializable {
// to ensure that the full Search and this SDDocumentType is built first.
private FieldSets fieldSets;
// Document references
- private Optional<DocumentReferences> documentReferences = Optional.empty();
+ private DocumentReferences documentReferences;
private TemporaryImportedFields temporaryImportedFields;
static {
@@ -72,7 +70,7 @@ public class SDDocumentType implements Cloneable, Serializable {
NewDocumentType.Name name = new NewDocumentType.Name(dt.getName());
if (getType(name) != null)
throw new IllegalArgumentException("Data type '" + name + "' has already been used.");
- if (name.getName() == docType.getName())
+ if (name.getName().equals(docType.getName()))
throw new IllegalArgumentException("Data type '" + name + "' can not have same name as its defining document.");
ownedTypes.put(name, dt);
return this;
@@ -80,9 +78,6 @@ public class SDDocumentType implements Cloneable, Serializable {
public final SDDocumentType getOwnedType(String name) {
return getOwnedType(new NewDocumentType.Name(name));
}
- public SDDocumentType getOwnedType(DataTypeName name) {
- return getOwnedType(name.getName());
- }
public SDDocumentType getOwnedType(NewDocumentType.Name name) {
return ownedTypes.get(name);
@@ -105,9 +100,8 @@ public class SDDocumentType implements Cloneable, Serializable {
return type;
}
- public SDDocumentType addAnnotation(AnnotationType annotation) {
+ public void addAnnotation(AnnotationType annotation) {
annotationTypes.register(annotation);
- return this;
}
/** Returns all owned datatypes. */
@@ -117,15 +111,6 @@ public class SDDocumentType implements Cloneable, Serializable {
public Map<String, AnnotationType> getAnnotations() { return annotationTypes.getTypes(); }
public AnnotationType findAnnotation(String name) { return annotationTypes.getType(name); }
- public Collection<SDDocumentType> getAllTypes() {
- Collection<SDDocumentType> list = new ArrayList<>();
- list.addAll(getTypes());
- for (SDDocumentType inherited : inheritedTypes.values()) {
- list.addAll(inherited.getAllTypes());
- }
- return list;
- }
-
public Map<NewDocumentType.Name, SDDocumentType> allTypes() {
Map<NewDocumentType.Name, SDDocumentType> map = new LinkedHashMap<>();
for (SDDocumentType inherited : inheritedTypes.values())
@@ -219,8 +204,7 @@ public class SDDocumentType implements Cloneable, Serializable {
String subFieldName = name.substring(name.indexOf(".")+1);
Field f = docType.getField(superFieldName);
if (f != null) {
- if (f instanceof SDField) {
- SDField superField = (SDField)f;
+ if (f instanceof SDField superField) {
return superField.getStructField(subFieldName);
} else {
throw new IllegalArgumentException("Field " + f.getName() + " is not an SDField");
@@ -268,7 +252,7 @@ public class SDDocumentType implements Cloneable, Serializable {
return field;
}
- public Field addField(String fName, DataType dataType, boolean header, int code) {
+ public Field addField(String fName, DataType dataType, int code) {
SDField field = new SDField(this, fName, code, dataType);
addField(field);
return field;
@@ -294,10 +278,6 @@ public class SDDocumentType implements Cloneable, Serializable {
return new LinkedHashSet<>(map.values());
}
- public Iterator<Field> fieldIterator() {
- return fieldSet().iterator();
- }
-
/** Returns the number of fields in this only, not including inherited fields */
// TODO: Remove
public int getFieldCount() {
@@ -329,11 +309,11 @@ public class SDDocumentType implements Cloneable, Serializable {
}
public Optional<DocumentReferences> getDocumentReferences() {
- return documentReferences;
+ return Optional.ofNullable(documentReferences);
}
public void setDocumentReferences(DocumentReferences documentReferences) {
- this.documentReferences = Optional.of(documentReferences);
+ this.documentReferences = documentReferences;
}
public TemporaryImportedFields getTemporaryImportedFields() {
diff --git a/config-model/src/main/java/com/yahoo/schema/document/SDField.java b/config-model/src/main/java/com/yahoo/schema/document/SDField.java
index 8f285bdd113..943d6c6fc14 100644
--- a/config-model/src/main/java/com/yahoo/schema/document/SDField.java
+++ b/config-model/src/main/java/com/yahoo/schema/document/SDField.java
@@ -280,8 +280,7 @@ public class SDField extends Field implements TypedKey, ImmutableSDField {
structFields.put(fieldName, subField);
};
- if (dataType instanceof MapDataType) {
- MapDataType mdt = (MapDataType) dataType;
+ if (dataType instanceof MapDataType mdt) {
supplyStructField.accept("key", mdt.getKeyType());
supplyStructField.accept("value", mdt.getValueType());
} else {
@@ -308,8 +307,7 @@ public class SDField extends Field implements TypedKey, ImmutableSDField {
for (Field field : subType.fieldSet()) {
supplyStructField.accept(field.getName(), field.getDataType());
}
- } else if (dataType instanceof StructDataType) {
- var sdt = (StructDataType) dataType;
+ } else if (dataType instanceof StructDataType sdt) {
for (Field field : sdt.getFields()) {
supplyStructField.accept(field.getName(), field.getDataType());
}
@@ -322,13 +320,12 @@ public class SDField extends Field implements TypedKey, ImmutableSDField {
// populate struct fields with matching
if (subType != null) {
for (Field f : subType.fieldSet()) {
- if (f instanceof SDField) {
- SDField field = (SDField) f;
- SDField subField = structFields.get(field.getName());
+ if (f instanceof SDField sdField) {
+ SDField subField = structFields.get(sdField.getName());
if (subField != null) {
// we just made this with a copy of our matching (see above)
Matching subFieldMatching = subField.getMatching();
- subFieldMatching.merge(field.getMatching());
+ subFieldMatching.merge(sdField.getMatching());
subField.setMatching(subFieldMatching);
}
} else {
diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java
index 92a75cb051b..ed6668f0d0d 100644
--- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java
+++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryField.java
@@ -22,7 +22,7 @@ public class SummaryField extends Field implements Cloneable, TypedKey {
*/
public static class Source implements Serializable {
- private String name;
+ private final String name;
private boolean override = false;
public Source(String name) {
this.name = name;
@@ -54,7 +54,7 @@ public class SummaryField extends Field implements Cloneable, TypedKey {
}
/** The transform to perform on the stored source */
- private SummaryTransform transform=SummaryTransform.NONE;
+ private SummaryTransform transform;
/** The command used per field in vsmsummary */
private VsmCommand vsmCommand = VsmCommand.NONE;
@@ -156,7 +156,7 @@ public class SummaryField extends Field implements Cloneable, TypedKey {
return destinations;
}
- private String toString(Collection<?> collection) {
+ public String toString(Collection<?> collection) {
StringBuilder buffer=new StringBuilder();
for (Iterator<?> i=collection.iterator(); i.hasNext(); ) {
buffer.append(i.next().toString());
@@ -283,8 +283,8 @@ public class SummaryField extends Field implements Cloneable, TypedKey {
FLATTENSPACE("FLATTENSPACE"),
FLATTENJUNIPER("FLATTENJUNIPER");
- private String cmd="";
- private VsmCommand(String cmd) {
+ private final String cmd;
+ VsmCommand(String cmd) {
this.cmd=cmd;
}
@Override