diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-06-03 10:55:18 +0000 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-06-08 11:45:31 +0200 |
commit | 0b3579b8af74a1bdbab5759a51bd592fdbc11cb8 (patch) | |
tree | a078096d65da6b15e5bedb00a6a911bbfc078ed9 /document/src/main | |
parent | e337a30ca89055a6aa3f7aa9267d2f1e523e7bdd (diff) |
more cleanup of DocumentTypeManager API
Diffstat (limited to 'document/src/main')
-rw-r--r-- | document/src/main/java/com/yahoo/document/DocumentTypeManager.java | 38 | ||||
-rw-r--r-- | document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java | 10 |
2 files changed, 23 insertions, 25 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManager.java b/document/src/main/java/com/yahoo/document/DocumentTypeManager.java index a32772adb31..ee9366285a9 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManager.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManager.java @@ -65,7 +65,7 @@ public class DocumentTypeManager { DocumentTypeManagerConfigurer.configureNewManager(config, this); } - public void assign(DocumentTypeManager other) { + void internalAssign(DocumentTypeManager other) { dataTypes = other.dataTypes; documentTypes = other.documentTypes; annotationTypeRegistry = other.annotationTypeRegistry; @@ -103,7 +103,7 @@ public class DocumentTypeManager { } } - public boolean hasDataType(String name) { + boolean hasDataTypeInternal(String name) { if (name.startsWith("tensor(")) return true; // built-in dynamic: Always present for (DataType type : dataTypes.values()) { if (type.getName().equalsIgnoreCase(name)) { @@ -114,19 +114,6 @@ public class DocumentTypeManager { } /** - * Use constants and factories in DataType instead. - * For structs, use getStructType() in DocumentType. - * For annotation payloads, use getDataType() in AnnotationType. - */ - DataType getDataType(String name) { - var type = getDataTypeInternal(name); - if (type == null) { - throw new IllegalArgumentException("No datatype named " + name); - } - return type; - } - - /** * For internal use only, avoid whenever possible. * Use constants and factories in DataType instead. * For structs, use getStructType() in DocumentType. @@ -163,7 +150,12 @@ public class DocumentTypeManager { return foundTypes.get(0); } - DataType getDataType(int code) { return getDataType(code, ""); } + /** + * Return a data type instance + * + * @param code the code of the data type to return, which must be either built in or present in this manager + */ + DataType getDataTypeByCode(int code) { return getDataTypeByCode(code, ""); } /** * Return a data type instance @@ -172,7 +164,7 @@ public class DocumentTypeManager { * @param detailedType detailed type information, or the empty string if none * @return the appropriate DataType instance */ - DataType getDataType(int code, String detailedType) { + DataType getDataTypeByCode(int code, String detailedType) { if (code == DataType.tensorDataTypeCode) // built-in dynamic return new TensorDataType(TensorType.fromSpec(detailedType)); @@ -202,7 +194,6 @@ public class DocumentTypeManager { * * @param type The datatype to register */ - @SuppressWarnings("deprecation") void registerSingleType(DataType type) { if (type instanceof TensorDataType) return; // built-in dynamic: Created on the fly if (dataTypes.containsKey(type.getId())) { @@ -259,6 +250,15 @@ public class DocumentTypeManager { return documentTypes.get(new DataTypeName(name)); } + /** + * Convenience method + * @param name the name of a document type + * @return returns true if a document type having this name is registered in this manager + */ + public boolean hasDocumentType(String name) { + return (getDocumentType(name) != null); + } + final public Document createDocument(GrowableByteBuffer buf) { DocumentDeserializer data = DocumentDeserializerFactory.create6(this, buf); return new Document(data); @@ -293,7 +293,7 @@ public class DocumentTypeManager { * Clears the DocumentTypeManager. After this operation, * only the default document type and data types are available. */ - void clear() { + void internalClear() { documentTypes.clear(); dataTypes.clear(); registerDefaultDataTypes(); diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java index 17ecd2b9659..f11b1ae9531 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java @@ -163,14 +163,13 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub return type; } - @SuppressWarnings("deprecation") private DataType getOrCreateType(int id) { if (typesById.containsKey(id)) { return typesById.get(id); } var config = configMap.remove(id); if (config == null) { - return manager.getDataType(id); + return manager.getDataTypeByCode(id); } assert(id == config.id()); for (var o : config.arraytype()) { @@ -215,7 +214,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub } DataType fieldType = typesById.get(field.datatype()); if (fieldType == null) { - fieldType = manager.getDataType(field.datatype(), field.detailedtype()); + fieldType = manager.getDataTypeByCode(field.datatype(), field.detailedtype()); } if (field.id().size() == 1) { type.addField(new Field(field.name(), field.id().get(0).id(), fieldType)); @@ -301,11 +300,10 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub } } - @SuppressWarnings("deprecation") private void addAnnotationTypePayloads(DocumentmanagerConfig config) { for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) { AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annType.id()); - DataType payload = manager.getDataType(annType.datatype(), ""); + DataType payload = manager.getDataTypeByCode(annType.datatype(), ""); if (! payload.equals(DataType.NONE)) { annotationType.setDataType(payload); } @@ -621,7 +619,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub if (this.managerToConfigure.getDataTypes().size() != defaultTypeCount) { log.log(Level.FINE, "Live document config overwritten with new config."); } - managerToConfigure.assign(manager); + managerToConfigure.internalAssign(manager); } } |