diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /document/src/main/java/com/yahoo/document/CollectionDataType.java |
Publish
Diffstat (limited to 'document/src/main/java/com/yahoo/document/CollectionDataType.java')
-rw-r--r-- | document/src/main/java/com/yahoo/document/CollectionDataType.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/document/src/main/java/com/yahoo/document/CollectionDataType.java b/document/src/main/java/com/yahoo/document/CollectionDataType.java new file mode 100644 index 00000000000..87f1f2947bf --- /dev/null +++ b/document/src/main/java/com/yahoo/document/CollectionDataType.java @@ -0,0 +1,87 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.document; + +import com.yahoo.document.datatypes.CollectionFieldValue; +import com.yahoo.document.datatypes.FieldValue; +import com.yahoo.vespa.objects.Ids; +import com.yahoo.vespa.objects.ObjectVisitor; + +import java.util.List; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public abstract class CollectionDataType extends DataType { + // The global class identifier shared with C++. + public static int classId = registerClass(Ids.document + 53, CollectionDataType.class); + + private DataType nestedType; + + protected CollectionDataType(String name, int code, DataType nestedType) { + super(name, code); + this.nestedType = nestedType; + } + + @Override + public abstract CollectionFieldValue createFieldValue(); + + @Override + public CollectionDataType clone() { + CollectionDataType type = (CollectionDataType) super.clone(); + type.nestedType = nestedType.clone(); + return type; + } + + @SuppressWarnings("deprecation") + public DataType getNestedType() { + return nestedType; + } + + @Override + protected FieldValue createByReflection(Object arg) { return null; } + + /** + * Sets the nested type of this CollectionDataType. WARNING! Do not use! Only to be used by config system! + */ + public void setNestedType(DataType nestedType) { + this.nestedType = nestedType; + } + + @Override + public PrimitiveDataType getPrimitiveType() { + return nestedType.getPrimitiveType(); + } + + @Override + public boolean isValueCompatible(FieldValue value) { + if (!(value instanceof CollectionFieldValue)) { + return false; + } + CollectionFieldValue cfv = (CollectionFieldValue) value; + if (equals(cfv.getDataType())) { + //the field value if of this type: + return true; + } + return false; + } + + @Override + protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { + seenTypes.add(this); + if (!seenTypes.contains(getNestedType())) { + //we haven't seen this one before, register it: + getNestedType().register(manager, seenTypes); + } + super.register(manager, seenTypes); + } + + @Override + public void visitMembers(ObjectVisitor visitor) { + super.visitMembers(visitor); + visitor.visit("nestedType", nestedType); + } + + @Override + public boolean isMultivalue() { return true; } + +} |