diff --git a/config-model/src/main/java/com/yahoo/config/model/builder/xml/ConfigModelId.java b/config-model/src/main/java/com/yahoo/config/model/builder/xml/ConfigModelId.java index 5db0c97f8f97..821baac6228d 100644 --- a/config-model/src/main/java/com/yahoo/config/model/builder/xml/ConfigModelId.java +++ b/config-model/src/main/java/com/yahoo/config/model/builder/xml/ConfigModelId.java @@ -22,9 +22,10 @@ private ConfigModelId(String name, Version version) { /** * Create id with a name and version + * * @param tagName Name of the id * @param tagVersion Version of the id - * @return A ConfigModelId instance + * @return a ConfigModelId instance */ public static ConfigModelId fromNameAndVersion(String tagName, String tagVersion) { return new ConfigModelId(tagName, Version.fromString(tagVersion)); @@ -34,7 +35,7 @@ public static ConfigModelId fromNameAndVersion(String tagName, String tagVersion * Create id with given name, using default version 1. * * @param tagName Name of the id - * @return A ConfigModelId instance + * @return a ConfigModelId instance */ public static ConfigModelId fromName(String tagName) { return new ConfigModelId(tagName, new Version(1)); @@ -68,6 +69,7 @@ public int hashCode() { /** * Return the XML element name. + * * @return the name of the config model */ public String getName() { @@ -76,6 +78,7 @@ public String getName() { /** * Return the XML element version. + * * @return the version of the config model */ Version getVersion() { @@ -83,10 +86,7 @@ Version getVersion() { } private String toStringValue() { - StringBuilder sb = new StringBuilder(); - sb.append(name); - sb.append("."); - sb.append(version); - return sb.toString(); + return name + "." + version; } + } diff --git a/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java b/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java index 4a53131ff82c..72cf2af510f1 100644 --- a/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java +++ b/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java @@ -55,9 +55,9 @@ public static String nullIfEmpty(String attribute) { */ public static String getIdString(Element element) { String idString = element.getAttribute("id"); - if (idString == null || idString.trim().equals("")) + if (idString.trim().isEmpty()) idString = element.getAttribute(idReference); - if (idString == null || idString.trim().equals("")) + if (idString.trim().isEmpty()) idString = element.getAttribute("ident"); return idString; } @@ -119,7 +119,7 @@ public static boolean isReference(Element element) { /** * Creates a new XML document builder. * - * @return A new DocumentBuilder instance, or null if we fail to get one. + * @return a new DocumentBuilder instance, or null if we fail to get one. */ public static synchronized DocumentBuilder getDocumentBuilder() { try { @@ -194,4 +194,5 @@ private static DocumentBuilderFactory createDocumentBuilderFactory() { throw new RuntimeException(e); } } + } diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/ConfigDefinitionStore.java b/config-model/src/main/java/com/yahoo/config/model/deploy/ConfigDefinitionStore.java index 7a3290ae5921..3fd2f5d6bab3 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/ConfigDefinitionStore.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/ConfigDefinitionStore.java @@ -11,9 +11,7 @@ */ public interface ConfigDefinitionStore { - /** - * Returns a config definition, or empty if the config definition is not found. - */ + /** Returns a config definition, or empty if the config definition is not found. */ Optional getConfigDefinition(ConfigDefinitionKey defKey); } diff --git a/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraph.java b/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraph.java index d21edef354c7..e6b8edcae6df 100644 --- a/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraph.java +++ b/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraph.java @@ -9,7 +9,6 @@ * A model graph contains the dependency graph of config models. * * @author Ulf Lilleengen - * @since 5.1 */ public class ModelGraph { diff --git a/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraphBuilder.java b/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraphBuilder.java index 1842dd6b871e..90ed0e841a59 100644 --- a/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraphBuilder.java +++ b/config-model/src/main/java/com/yahoo/config/model/graph/ModelGraphBuilder.java @@ -12,7 +12,6 @@ * constructor arguments. * * @author Ulf Lilleengen - * @since 5.1 */ public class ModelGraphBuilder { @@ -49,4 +48,5 @@ public ModelGraph build() { } return new ModelGraph(modelNodes, roots); } + } diff --git a/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java b/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java index dcf1c8629a49..1145ec7e4747 100644 --- a/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java +++ b/config-model/src/main/java/com/yahoo/config/model/graph/ModelNode.java @@ -82,18 +82,14 @@ int addDependenciesFrom(List modelNodes) { } private boolean isCollectionOf(Type type, Class nodeClazz) { - if (type instanceof ParameterizedType) { - ParameterizedType t = (ParameterizedType) type; - // Note: IntelliJ says the following cannot be equal but that is wrong + if (type instanceof ParameterizedType t) { return (t.getRawType().equals(java.util.Collection.class) && t.getActualTypeArguments().length == 1 && t.getActualTypeArguments()[0].equals(nodeClazz)); } return false; } private boolean isCollection(Type type) { - if (type instanceof ParameterizedType) { - ParameterizedType t = (ParameterizedType) type; - // Note: IntelliJ says the following cannot be equal but that is wrong + if (type instanceof ParameterizedType t) { return (t.getRawType().equals(java.util.Collection.class) && t.getActualTypeArguments().length == 1); } return false; @@ -114,7 +110,7 @@ public MODEL createModel(ConfigModelContext context) { if (params.length < 1 || ! params[0].equals(ConfigModelContext.class)) { throw new IllegalArgumentException("Constructor for " + clazz.getName() + " must have as its first argument a " + ConfigModelContext.class.getName()); } - Object arguments[] = new Object[params.length]; + Object[] arguments = new Object[params.length]; arguments[0] = context; for (int i = 1; i < params.length; i++) arguments[i] = findArgument(params[i]); diff --git a/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducerRoot.java b/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducerRoot.java index d844fed16096..5c68f9548277 100644 --- a/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducerRoot.java +++ b/config-model/src/main/java/com/yahoo/config/model/producer/AbstractConfigProducerRoot.java @@ -61,4 +61,5 @@ public Optional getService(String configId) { .filter(Service.class::isInstance) .map(Service.class::cast); } + } diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/Host.java b/config-model/src/main/java/com/yahoo/config/model/provision/Host.java index 05e5c8b6417b..ce2c816457c1 100644 --- a/config-model/src/main/java/com/yahoo/config/model/provision/Host.java +++ b/config-model/src/main/java/com/yahoo/config/model/provision/Host.java @@ -50,8 +50,8 @@ public Host(String hostname, List hostAliases, Optional flavor, @Override public String toString() { - return hostname + (aliases.size() > 0 ? " (aliases: " + aliases + ")" : "" ) + - (flavor.map(value -> " (flavor: " + value + ")").orElse("")); + return hostname + (!aliases.isEmpty() ? " (aliases: " + aliases + ")" : "" ) + + (flavor.map(value -> " (flavor: " + value + ")").orElse("")); } } diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java b/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java index dbfedf05236e..086a0cd9dabd 100644 --- a/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java +++ b/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java @@ -42,8 +42,8 @@ public Hosts(Collection hosts) { private void validateAliases(Collection hosts) { Set aliases = new HashSet<>(); for (Host host : hosts) { - if (host.aliases().size() > 0) { - if (host.aliases().size() < 1) + if (!host.aliases().isEmpty()) { + if (host.aliases().isEmpty()) throw new IllegalArgumentException("Host '" + host.hostname() + "' must have at least one tag."); for (String alias : host.aliases()) { if (aliases.contains(alias)) @@ -65,7 +65,7 @@ public static Hosts readFrom(Reader hostsFile) { Document doc = XmlHelper.getDocument(hostsFile); for (Element hostE : XML.getChildren(doc.getDocumentElement(), "host")) { String name = hostE.getAttribute("name"); - if (name.equals("")) { + if (name.isEmpty()) { throw new IllegalArgumentException("Missing 'name' attribute for host."); } if ("localhost".equals(name)) { @@ -103,12 +103,12 @@ private static List getHostAliases(NodeList hostAliases) { } if (! e.getNodeName().equals("alias")) { throw new IllegalArgumentException("Unexpected tag: '" + e.getNodeName() + "' at node " + - XML.getNodePath(e, " > ") + ", expected 'alias'."); + XML.getNodePath(e, " > ") + ", expected 'alias'."); } String alias = e.getFirstChild().getNodeValue(); - if ((alias == null) || (alias.equals(""))) { + if ((alias == null) || (alias.isEmpty())) { throw new IllegalArgumentException("Missing value for the alias tag at node " + - XML.getNodePath(e, " > ") + "'."); + XML.getNodePath(e, " > ") + "'."); } aliases.add(alias); } diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java b/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java index e42e5edee716..ad73972d3d58 100644 --- a/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java +++ b/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java @@ -17,7 +17,7 @@ /** * A host provisioner used when there is no hosts.xml file (using localhost as the only host) - * No state in this provisioner, i.e it does not know anything about the active + * No state in this provisioner, i.e. it does not know anything about the active * application if one exists. * * @author hmusum diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java index 236f76553f7e..18bb15a37f23 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java @@ -277,13 +277,13 @@ public Builder withServices(String services) { return this; } - public Builder withSearchDefinition(String searchDefinition) { - this.schemas = List.of(searchDefinition); + public Builder withSchema(String schema) { + this.schemas = List.of(schema); return this; } - public Builder withSchemas(List searchDefinition) { - this.schemas = List.copyOf(searchDefinition); + public Builder withSchemas(List schemas) { + this.schemas = List.copyOf(schemas); return this; } diff --git a/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java b/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java index 39b1b7ff6b57..17952332d649 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/DataTypeRepo.java @@ -12,8 +12,8 @@ */ public class DataTypeRepo implements DataTypeCollection { - private Map typeById = new LinkedHashMap<>(); - private Map typeByName = new LinkedHashMap<>(); + private final Map typeById = new LinkedHashMap<>(); + private final Map typeByName = new LinkedHashMap<>(); public DataType getDataType(String name) { return typeByName.get(name); diff --git a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java index 976cf4abc4c6..3fdab960d48d 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java @@ -13,7 +13,7 @@ * we want to end up with NewDocumentType as target type. * * @author arnej - **/ + */ public final class NewDocumentReferenceDataType extends DataType { private final StructuredDataType target; @@ -73,8 +73,7 @@ public Class getValueClass() { @Override public boolean isValueCompatible(FieldValue value) { var dt = value.getDataType(); - if (dt instanceof ReferenceDataType) { - var refType = (ReferenceDataType) dt; + if (dt instanceof ReferenceDataType refType) { var docTypeName = refType.getTargetType().getName(); return docTypeName.equals(target.getName()); } @@ -83,8 +82,7 @@ public boolean isValueCompatible(FieldValue value) { @Override public boolean equals(Object rhs) { - if (rhs instanceof NewDocumentReferenceDataType) { - var other = (NewDocumentReferenceDataType) rhs; + if (rhs instanceof NewDocumentReferenceDataType other) { return super.equals(other) && (temporary == other.temporary) && target.equals(other.target); } return false; diff --git a/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java b/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java index f370be0cd860..6402e9980aa5 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java @@ -8,7 +8,7 @@ * Model for StructDataType declared in a specific document * * @author arnej - **/ + */ public final class OwnedStructDataType extends StructDataType implements OwnedType { private final String ownerName; @@ -53,4 +53,5 @@ public int getId() { public String toString() { return "{OwnedStructDataType "+uniqueName+" id="+getId()+" uid="+getUniqueId()+" enable override="+overrideId+"}"; } + } diff --git a/config-model/src/main/java/com/yahoo/documentmodel/OwnedTemporaryType.java b/config-model/src/main/java/com/yahoo/documentmodel/OwnedTemporaryType.java index 280344c4e5f3..a4ff93ef984d 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/OwnedTemporaryType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/OwnedTemporaryType.java @@ -8,7 +8,7 @@ * Proxy for a struct type declared in a specific document * * @author arnej - **/ + */ public final class OwnedTemporaryType extends StructDataType implements OwnedType { private final String ownerName; @@ -38,4 +38,5 @@ public String getUniqueName() { public String toString() { return "{OwnedTemporaryType "+uniqueName+" id="+getId()+" uid="+getUniqueId()+"}"; } + } diff --git a/config-model/src/main/java/com/yahoo/documentmodel/OwnedType.java b/config-model/src/main/java/com/yahoo/documentmodel/OwnedType.java index 4a4e90f31e65..28387464ae46 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/OwnedType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/OwnedType.java @@ -5,11 +5,13 @@ * API for a type declared in a specific document * * @author arnej - **/ + */ public interface OwnedType { + String getOwnerName(); String getUniqueName(); default int getUniqueId() { return getUniqueName().hashCode(); } + } diff --git a/config-model/src/main/java/com/yahoo/documentmodel/TemporaryUnknownType.java b/config-model/src/main/java/com/yahoo/documentmodel/TemporaryUnknownType.java index f9701da0a9a0..59ea094afc02 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/TemporaryUnknownType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/TemporaryUnknownType.java @@ -7,7 +7,7 @@ * Proxy for an unknown type (must resolve to struct or document) * * @author arnej - **/ + */ public final class TemporaryUnknownType extends StructDataType { public TemporaryUnknownType(String name) { @@ -18,4 +18,5 @@ public TemporaryUnknownType(String name) { public String toString() { return "{TemporaryUnknownType "+getName()+" id="+getId()+"}"; } + } 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 f35a05411d9a..78b51f8dcf02 100644 --- a/config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/schema/DocumentModelBuilder.java @@ -26,7 +26,7 @@ import com.yahoo.schema.document.annotation.TemporaryAnnotationReferenceDataType; import com.yahoo.vespa.documentmodel.DocumentModel; import com.yahoo.vespa.documentmodel.FieldView; -import com.yahoo.vespa.documentmodel.SearchDef; +import com.yahoo.vespa.documentmodel.SchemaDef; import com.yahoo.vespa.documentmodel.SearchField; import java.util.ArrayList; @@ -129,62 +129,62 @@ private Collection tryAdd(Collection schemaList) { private void addToModel(Schema schema) { // Then we add the search specific stuff - SearchDef searchDef = new SearchDef(schema.getName()); - addSearchFields(schema.extraFieldList(), searchDef); + SchemaDef schemaDef = new SchemaDef(schema.getName()); + addSearchFields(schema.extraFieldList(), schemaDef); for (Field f : schema.getDocument().fieldSet()) { - addSearchField((SDField) f, searchDef); + addSearchField((SDField) f, schemaDef); } for (SDField field : schema.allConcreteFields()) { for (Attribute attribute : field.getAttributes().values()) { - if ( ! searchDef.getFields().containsKey(attribute.getName())) { - searchDef.add(new SearchField(new Field(attribute.getName(), field), !field.getIndices().isEmpty(), true)); + if ( ! schemaDef.getFields().containsKey(attribute.getName())) { + schemaDef.add(new SearchField(new Field(attribute.getName(), field), !field.getIndices().isEmpty(), true)); } } } for (Field f : schema.getDocument().fieldSet()) { - addAlias((SDField) f, searchDef); + addAlias((SDField) f, schemaDef); } - model.getSearchManager().add(searchDef); + model.getSearchManager().add(schemaDef); } - private static void addSearchFields(Collection fields, SearchDef searchDef) { + private static void addSearchFields(Collection fields, SchemaDef schemaDef) { for (SDField field : fields) { - addSearchField(field, searchDef); + addSearchField(field, schemaDef); } } - private static void addSearchField(SDField field, SearchDef searchDef) { + private static void addSearchField(SDField field, SchemaDef schemaDef) { SearchField searchField = new SearchField(field, field.getIndices().containsKey(field.getName()) && field.getIndices().get(field.getName()).getType().equals(Index.Type.VESPA), field.getAttributes().containsKey(field.getName())); - searchDef.add(searchField); + schemaDef.add(searchField); // Add field to views - addToView(field.getIndices().keySet(), searchField, searchDef); + addToView(field.getIndices().keySet(), searchField, schemaDef); } - private static void addAlias(SDField field, SearchDef searchDef) { + private static void addAlias(SDField field, SchemaDef schemaDef) { for (Map.Entry entry : field.getAliasToName().entrySet()) { - searchDef.addAlias(entry.getKey(), entry.getValue()); + schemaDef.addAlias(entry.getKey(), entry.getValue()); } } - private static void addToView(Collection views, Field field, SearchDef searchDef) { + private static void addToView(Collection views, Field field, SchemaDef schemaDef) { for (String viewName : views) { - addToView(viewName, field, searchDef); + addToView(viewName, field, schemaDef); } } - private static void addToView(String viewName, Field field, SearchDef searchDef) { - if (searchDef.getViews().containsKey(viewName)) { - searchDef.getViews().get(viewName).add(field); + private static void addToView(String viewName, Field field, SchemaDef schemaDef) { + if (schemaDef.getViews().containsKey(viewName)) { + schemaDef.getViews().get(viewName).add(field); } else { - if (!searchDef.getFields().containsKey(viewName)) { + if (!schemaDef.getFields().containsKey(viewName)) { FieldView view = new FieldView(viewName); view.add(field); - searchDef.add(view); + schemaDef.add(view); } } } diff --git a/config-model/src/main/java/com/yahoo/schema/Schema.java b/config-model/src/main/java/com/yahoo/schema/Schema.java index 127d12594b48..fe81e932093a 100644 --- a/config-model/src/main/java/com/yahoo/schema/Schema.java +++ b/config-model/src/main/java/com/yahoo/schema/Schema.java @@ -195,7 +195,7 @@ public boolean isRawAsBase64() { /** * Sets the stemming default of fields. Default is ALL * - * @param stemming set default stemming for this searchdefinition + * @param stemming set default stemming for this schema * @throws NullPointerException if this is attempted set to null */ public void setStemming(Stemming stemming) { diff --git a/config-model/src/main/java/com/yahoo/schema/derived/Derived.java b/config-model/src/main/java/com/yahoo/schema/derived/Derived.java index f43119125847..7b50f2e4656c 100644 --- a/config-model/src/main/java/com/yahoo/schema/derived/Derived.java +++ b/config-model/src/main/java/com/yahoo/schema/derived/Derived.java @@ -72,10 +72,7 @@ protected void derive(SDDocumentType document, Schema schema) { */ protected void derive(ImmutableSDField field, Schema schema) {} - /** - * Derives the content of this configuration. This - * default does nothing. - */ + /** Derives the content of this configuration. This default does nothing. */ protected void derive(Index index, Schema schema) { } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/AttributeProperties.java b/config-model/src/main/java/com/yahoo/schema/processing/AttributeProperties.java index 5868c9066ea3..5b643ce5f680 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/AttributeProperties.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/AttributeProperties.java @@ -53,7 +53,7 @@ public void process(boolean validate, boolean documentsOnly) { /** * Checks if the attribute has been created bye an indexing statement in this field. * - * @param field a searchdefinition field + * @param field a schema field * @param attributeName name of the attribute * @return true if the attribute has been created by this field, else false */ diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchDef.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SchemaDef.java similarity index 68% rename from config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchDef.java rename to config-model/src/main/java/com/yahoo/vespa/documentmodel/SchemaDef.java index a358f6839cea..4a9fb1bc7902 100644 --- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchDef.java +++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SchemaDef.java @@ -9,45 +9,44 @@ import java.util.logging.Logger; /** - * @author baldersheim - * @since 2010-02-19 + * @author baldersheim */ -public class SearchDef { - private final static Logger log = Logger.getLogger(SearchDef.class.getName()); - /// Name of the searchdefinition - private String name; - /// These are the real backing documenttypes - private DocumentTypeManager sources = new DocumentTypeManager(); - /// Map of all search fields - private Map fields = new HashMap<>(); - /// Map of all views that can be searched. - private Map views = new HashMap<>(); +public class SchemaDef { + + private final static Logger log = Logger.getLogger(SchemaDef.class.getName()); + + /** Name of the schema. */ + private final String name; + + /** These are the real backing document types. */ + private final DocumentTypeManager sources = new DocumentTypeManager(); + + /** Map of all search fields. */ + private final Map fields = new HashMap<>(); + + /** Map of all views that can be searched. */ + private final Map views = new HashMap<>(); + /// Map of all aliases - private Map aliases = new HashMap<>(); + private final Map aliases = new HashMap<>(); - /** - * Will create a SearchDef with the given name - * @param name The name of the searchdefinition - */ - public SearchDef(String name) { + /** Creates a SearchDef with the given name. */ + public SchemaDef(String name) { this.name = name; } - /** - * This will provide you with the name of the searchdefinition. - * @return The name of the searchdefinition. - */ public String getName() { return name; } public Map getFields() { return fields; } public Map getViews() { return views; } /** - * Adds a document that can be mapped to this search. - * @param source A document that can be mapped to this search. + * Adds a document that can be mapped to this schema. + * + * @param source a document that can be mapped to this schema. * @return Itself for chaining. */ - public SearchDef add(DocumentType source) { + public SchemaDef add(DocumentType source) { sources.registerDocumentType(source); return this; } @@ -59,7 +58,7 @@ private void noShadowing(String name) { private void noFieldShadowing(String name) { if (fields.containsKey(name)) { - throw new IllegalArgumentException("Searchdef '" + getName() + "' already contains the fields '" + fields.toString() + + throw new IllegalArgumentException("Schema '" + getName() + "' already contains the fields '" + fields + "'. You are trying to add '" + name + "'. Shadowing is not supported"); } } @@ -72,11 +71,12 @@ private void noViewShadowing(String name) { } /** - * Adds a search field to the definition. - * @param field The field to add. - * @return Itself for chaining. + * Adds a search field to the schema. + * + * @param field the field to add. + * @return this, for chaining. */ - public SearchDef add(SearchField field) { + public SchemaDef add(SearchField field) { try { noFieldShadowing(field.getName()); fields.put(field.getName(), field); @@ -88,7 +88,7 @@ public SearchDef add(SearchField field) { return this; } - public SearchDef addAlias(String alias, String aliased) { + public SchemaDef addAlias(String alias, String aliased) { noShadowing(alias); if (!fields.containsKey(aliased) && !views.containsKey(aliased)) { if (aliased.contains(".")) { @@ -114,7 +114,7 @@ public SearchDef addAlias(String alias, String aliased) { return this; } - public SearchDef add(FieldView view) { + public SchemaDef add(FieldView view) { noViewShadowing(view.getName()); if (views.containsKey(view.getName())) { views.get(view.getName()).add(view); @@ -122,4 +122,5 @@ public SearchDef add(FieldView view) { views.put(view.getName(), view); return this; } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchManager.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchManager.java index a6fa916882c9..148a4ab96bc5 100644 --- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchManager.java +++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/SearchManager.java @@ -4,24 +4,25 @@ import java.util.TreeMap; /** - * @author baldersheim + * @author baldersheim */ public class SearchManager { - /// This is the list of all known search definitions - private TreeMap defs = new TreeMap<>(); + /** The list of all known schemas. */ + private final TreeMap schema = new TreeMap<>(); /** - * This will add a searchdefinition or throw an IllegalArgumentException if the name is already used - * @param def The searchdef to add + * Adds a schema or throw an IllegalArgumentException if the name is already used + * + * @param schema the schema to add * @return itself for chaining purposes. */ - public SearchManager add(SearchDef def) { - if (defs.containsKey(def.getName())) { - throw new IllegalArgumentException("There already exist a searchdefinition with this content:\n" + - defs.get(def.getName()).toString() + "\n No room for : " + def.toString()); + public SearchManager add(SchemaDef schema) { + if (this.schema.containsKey(schema.getName())) { + throw new IllegalArgumentException("There already exist a schema with this content:\n" + + this.schema.get(schema.getName()).toString() + "\n No room for : " + schema); } - defs.put(def.getName(), def); + this.schema.put(schema.getName(), schema); return this; } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java index 052d32269ef4..07af564eb7a9 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/ContentBuilderTest.java @@ -737,7 +737,7 @@ void ensurePruneRemovedDocumentsAgeForHostedVespa() { .endpoints(Set.of(new ContainerEndpoint("search.indexing", ApplicationClusterEndpoint.Scope.zone, List.of("default.example.com")))); VespaModel model = new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() .withServices(hostedXml) - .withSearchDefinition(MockApplicationPackage.MUSIC_SCHEMA) + .withSchema(MockApplicationPackage.MUSIC_SCHEMA) .build()) .create(deployStateBuilder); ProtonConfig config = getProtonConfig(model.getContentClusters().values().iterator().next()); @@ -764,7 +764,7 @@ private ProtonConfig resolveProtonConfig(TestProperties props, String hostedXml) var deployStateBuilder = new DeployState.Builder().properties(props); var model = new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() .withServices(hostedXml) - .withSearchDefinition(MockApplicationPackage.MUSIC_SCHEMA) + .withSchema(MockApplicationPackage.MUSIC_SCHEMA) .build()) .create(deployStateBuilder); return getProtonConfig(model.getContentClusters().values().iterator().next()); @@ -834,7 +834,7 @@ private ApplicationPackage createAppWithMusic(String hosts, String services) { return new MockApplicationPackage.Builder() .withHosts(hosts) .withServices(services) - .withSearchDefinition(MockApplicationPackage.MUSIC_SCHEMA) + .withSchema(MockApplicationPackage.MUSIC_SCHEMA) .build(); } @@ -855,7 +855,7 @@ private ContentCluster createContent(String xml, TestProperties props) { VespaModel m = new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() .withHosts(getHosts()) .withServices(combined) - .withSearchDefinition(MockApplicationPackage.MUSIC_SCHEMA) + .withSchema(MockApplicationPackage.MUSIC_SCHEMA) .build()) .create(deployStateBuilder); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java index 7af06627398b..d0665ee8e66e 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java @@ -61,7 +61,7 @@ private static VespaModel buildMultiTenantVespaModel(String servicesXml) { return new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() .withServices("\n" + servicesXml) - .withSearchDefinition(MockApplicationPackage.MUSIC_SCHEMA) + .withSchema(MockApplicationPackage.MUSIC_SCHEMA) .build()) .create(deployStateBuilder); }