@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); }
private static DataType valueTypeForMapUpdate(DataType parentType) { if (parentType instanceof WeightedSetDataType) { return DataType.INT; } else if (parentType instanceof CollectionDataType) { return ((CollectionDataType) parentType).getNestedType(); } else if (parentType instanceof MapDataType) { return ((MapDataType) parentType).getValueType(); } else { throw new UnsupportedOperationException("Unexpected parent type: " + parentType); } }
public DataType getFirstStructOrMapRecursive() { DataType dataType = getDataType(); while (dataType instanceof CollectionDataType) { // Currently no nesting of collections dataType = ((CollectionDataType)dataType).getNestedType(); } return (dataType instanceof StructDataType || dataType instanceof MapDataType) ? dataType : null; }
private void replaceTemporaryTypesInCollection(CollectionDataType collectionDataType, List<DataType> seenStructs) { if (collectionDataType.getNestedType() instanceof TemporaryDataType) { collectionDataType.setNestedType(getDataType(collectionDataType.getNestedType().getCode(), "")); } else { replaceTemporaryTypes(collectionDataType.getNestedType(), seenStructs); } }
public void verifyElementCompatibility(T o) { if (!getDataType().getNestedType().isValueCompatible(o)) { throw new IllegalArgumentException( "Incompatible data types. Got " + o.getDataType() + ", expected " + getDataType().getNestedType()); } }
private void validateDataTypeForCollectionField(SDField field) { if (((CollectionDataType)field.getDataType()).getNestedType() instanceof TensorDataType) fail(search, field, "A field with collection type of tensor is not supported. Use simple type 'tensor' instead."); }
@Override public void write(RemoveValueUpdate update, DataType superType) { writeValue(this, ((CollectionDataType)superType).getNestedType(), update.getValue()); }
@Override public void write(RemoveValueUpdate update, DataType superType) { writeValue(this, ((CollectionDataType)superType).getNestedType(), update.getValue()); }
public StructDataType getFirstStructRecursive() { DataType dataType = getDataType(); while (true) { // Currently no nesting of collections if (dataType instanceof CollectionDataType) { dataType = ((CollectionDataType)dataType).getNestedType(); } else if (dataType instanceof MapDataType) { dataType = ((MapDataType)dataType).getValueType(); } else { break; } } return (dataType instanceof StructDataType) ? (StructDataType)dataType : null; }
private boolean doCheck(SDField field) { if (field.getDataType() instanceof NumericDataType) return true; if (field.getDataType() instanceof CollectionDataType) { if (((CollectionDataType)field.getDataType()).getNestedType() instanceof NumericDataType) { return true; } } return false; } }
private boolean isUriField(ImmutableSDField field) { DataType fieldType = field.getDataType(); if (DataType.URI.equals(fieldType)) { return true; } if (fieldType instanceof CollectionDataType && DataType.URI.equals(((CollectionDataType)fieldType).getNestedType())) { return true; } return false; }
@Override protected void checkCompatibility(DataType fieldType) { if (!(fieldType instanceof CollectionDataType)) { throw new UnsupportedOperationException("Expected collection, got " + fieldType.getName() + "."); } fieldType = ((CollectionDataType)fieldType).getNestedType(); if (value != null && !value.getDataType().equals(fieldType)) { throw new IllegalArgumentException("Expected " + fieldType.getName() + ", got " + value.getDataType().getName()); } }
@Override protected void checkCompatibility(DataType fieldType) { if (!(fieldType instanceof CollectionDataType)) { throw new UnsupportedOperationException("Expected collection, got " + fieldType.getName() + "."); } fieldType = ((CollectionDataType)fieldType).getNestedType(); if (value != null && !value.getDataType().equals(fieldType)) { throw new IllegalArgumentException("Expected " + fieldType.getName() + ", got " + value.getDataType().getName()); } }
@Override public void write(AddValueUpdate update, DataType superType) { writeValue(this, ((CollectionDataType)superType).getNestedType(), update.getValue()); putInt(null, update.getWeight()); }
@Override public void write(AddValueUpdate update, DataType superType) { writeValue(this, ((CollectionDataType)superType).getNestedType(), update.getValue()); putInt(null, update.getWeight()); }
@Override public void process(boolean validate, boolean documentsOnly) { for (SDField field : search.allConcreteFields()) { if (field.doesIndexing()) { DataType fieldType = field.getDataType(); if (fieldType instanceof CollectionDataType) { fieldType = ((CollectionDataType)fieldType).getNestedType(); } if (fieldType == DataType.URI) { processField(search, field); } } } }
@Override public void write(MapValueUpdate update, DataType superType) { if (superType instanceof ArrayDataType) { CollectionDataType type = (CollectionDataType) superType; IntegerFieldValue index = (IntegerFieldValue) update.getValue(); index.serialize(this); putInt(null, update.getUpdate().getValueUpdateClassID().id); update.getUpdate().serialize(this, type.getNestedType()); } else if (superType instanceof WeightedSetDataType) { writeValue(this, ((CollectionDataType)superType).getNestedType(), update.getValue()); putInt(null, update.getUpdate().getValueUpdateClassID().id); update.getUpdate().serialize(this, DataType.INT); } else { throw new SerializationException("MapValueUpdate only works for arrays and weighted sets"); } }
@Override public void write(MapValueUpdate update, DataType superType) { if (superType instanceof ArrayDataType) { CollectionDataType type = (CollectionDataType) superType; IntegerFieldValue index = (IntegerFieldValue) update.getValue(); index.serialize(this); putInt(null, update.getUpdate().getValueUpdateClassID().id); update.getUpdate().serialize(this, type.getNestedType()); } else if (superType instanceof WeightedSetDataType) { writeValue(this, ((CollectionDataType)superType).getNestedType(), update.getValue()); putInt(null, update.getUpdate().getValueUpdateClassID().id); update.getUpdate().serialize(this, DataType.INT); } else { throw new SerializationException("MapValueUpdate only works for arrays and weighted sets"); } }
public void read(FieldUpdate fieldUpdate) { int fieldId = getInt(null); Field field = fieldUpdate.getDocumentType().getField(fieldId, fieldUpdate.getSerializationVersion()); if (field == null) { throw new DeserializationException( "Cannot deserialize FieldUpdate, field fieldId " + fieldId + " not found in " + fieldUpdate.getDocumentType()); } fieldUpdate.setField(field); int size = getInt(null); for (int i = 0; i < size; i++) { if (field.getDataType() instanceof CollectionDataType) { CollectionDataType collType = (CollectionDataType) field.getDataType(); fieldUpdate.addValueUpdate(getValueUpdate(collType, collType.getNestedType())); } else { fieldUpdate.addValueUpdate(getValueUpdate(field.getDataType(), null)); } } }
public void read(FieldUpdate fieldUpdate) { int fieldId = getInt(null); Field field = fieldUpdate.getDocumentType().getField(fieldId, fieldUpdate.getSerializationVersion()); if (field == null) { throw new DeserializationException( "Cannot deserialize FieldUpdate, field fieldId " + fieldId + " not found in " + fieldUpdate.getDocumentType()); } fieldUpdate.setField(field); int size = getInt(null); for (int i = 0; i < size; i++) { if (field.getDataType() instanceof CollectionDataType) { CollectionDataType collType = (CollectionDataType) field.getDataType(); fieldUpdate.addValueUpdate(getValueUpdate(collType, collType.getNestedType())); } else { fieldUpdate.addValueUpdate(getValueUpdate(field.getDataType(), null)); } } }