private static FieldValue wrapValue(DataType type, Object val) { if (val == null) { return null; } if (val instanceof FieldValue) { return (FieldValue)val; } FieldValue ret = type.createFieldValue(); ret.assign(val); return ret; }
public static FieldValue create(FieldReader reader, DataType type) { FieldValue value = type.createFieldValue(); value.deserialize(reader); return value; }
private static void writeValue(VespaDocumentSerializer6 serializer, DataType dataType, Object value) { FieldValue fieldValue; if (value instanceof FieldValue) { fieldValue = (FieldValue)value; } else { fieldValue = dataType.createFieldValue(value); } fieldValue.serialize(serializer); }
private static void writeValue(VespaDocumentSerializer42 serializer, DataType dataType, Object value) { FieldValue fieldValue; if (value instanceof FieldValue) { fieldValue = (FieldValue)value; } else { fieldValue = dataType.createFieldValue(value); } fieldValue.serialize(serializer); }
public final boolean isAssignableFrom(DataType dataType) { // TODO: Reverse this so that isValueCompatible() uses this instead. return isValueCompatible(dataType.createFieldValue()); }
private static FieldValue keyTypeForMapUpdate(TokenBuffer.Token element, DataType expectedType) { FieldValue v; if (expectedType instanceof ArrayDataType) { v = new IntegerFieldValue(Integer.valueOf(element.text)); } else if (expectedType instanceof WeightedSetDataType) { v = ((WeightedSetDataType) expectedType).getNestedType().createFieldValue(element.text); } else if (expectedType instanceof MapDataType) { v = ((MapDataType) expectedType).getKeyType().createFieldValue(element.text); } else { throw new IllegalArgumentException("Container type " + expectedType + " not supported for match update."); } return v; } }
private static FieldValue readReferenceFieldValue(final String refText, DataType expectedType) { final FieldValue value = expectedType.createFieldValue(); if (!refText.isEmpty()) { value.assign(new DocumentId(refText)); } return value; } }
public FieldValue getFieldValue(StructuredFieldValue doc) { Object raw = extract.get(doc); return raw == null ? null : getDataType().createFieldValue(raw); } public FieldValue setFieldValue(StructuredFieldValue doc, FieldValue fv) {
public static FieldValue readAtomic(String field, DataType expectedType) { if (expectedType.equals(DataType.RAW)) { return expectedType.createFieldValue(new Base64().decode(field)); } else if (expectedType.equals(PositionDataType.INSTANCE)) { return PositionDataType.fromString(field); } else if (expectedType instanceof ReferenceDataType) { return readReferenceFieldValue(field, expectedType); } else { return expectedType.createFieldValue(field); } }
public void read(AddFieldPathUpdate update) { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); dt.createFieldValue(); fv.deserialize(this); if (!(fv instanceof Array)) { throw new DeserializationException("Add only applicable to array types"); } update.setNewValues((Array)fv); }
public void read(AddFieldPathUpdate update) { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); dt.createFieldValue(); fv.deserialize(this); if (!(fv instanceof Array)) { throw new DeserializationException("Add only applicable to array types"); } update.setNewValues((Array)fv); }
FieldUpdate readAssign(DocumentUpdate update) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("field".equals(reader.getAttributeName(i).toString())) { Field f = update.getDocumentType().getField(reader.getAttributeValue(i)); if (f == null) { throw newDeserializeException("Field " + reader.getAttributeValue(i) + " not found."); } FieldValue value = f.getDataType().createFieldValue(); value.deserialize(f, this); return FieldUpdate.createAssign(f, value); } } throw newDeserializeException("Assignment update without field attribute"); }
public static void applyUpdate(Field field, ValueUpdate update, Document doc) { doc.setFieldValue(field, createFieldValue(field.getDataType().createFieldValue(), update)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void iterateThroughWeightedSet(TokenBuffer buffer, int initNesting, DataType valueType, WeightedSet weightedSet) { while (buffer.nesting() >= initNesting) { // XXX the keys are defined in the spec to always be represented as strings FieldValue v = valueType.createFieldValue(buffer.currentName()); weightedSet.put(v, Integer.valueOf(buffer.currentText())); buffer.next(); } } }
public <T extends FieldValue> void read(FieldBase field, Array<T> array) { int numElements = getNumCollectionElems(); ArrayList<T> list = new ArrayList<T>(numElements); ArrayDataType type = array.getDataType(); for (int i = 0; i < numElements; i++) { if (version < 7) { getInt(null); // We don't need size for anything } FieldValue fv = type.getNestedType().createFieldValue(); fv.deserialize(null, this); list.add((T) fv); } array.clear(); array.addAll(list); }
public <T extends FieldValue> void read(FieldBase field, Array<T> array) { int numElements = getNumCollectionElems(); ArrayList<T> list = new ArrayList<T>(numElements); ArrayDataType type = array.getDataType(); for (int i = 0; i < numElements; i++) { if (version < 7) { getInt(null); // We don't need size for anything } FieldValue fv = type.getNestedType().createFieldValue(); fv.deserialize(null, this); list.add((T) fv); } array.clear(); array.addAll(list); }
public static FieldValue readSingleValue(TokenBuffer buffer, DataType expectedType) { if (buffer.currentToken().isScalarValue()) { return readAtomic(buffer.currentText(), expectedType); } else { FieldValue fieldValue = expectedType.createFieldValue(); CompositeReader.populateComposite(buffer, fieldValue); return fieldValue; } }
public void read(AddFieldPathUpdate update) { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); fv.deserialize(resolveField(update), this); update.setNewValues((Array)fv); }
public void read(AssignFieldPathUpdate update) { byte flags = getByte(null); update.setRemoveIfZero((flags & AssignFieldPathUpdate.REMOVE_IF_ZERO) != 0); update.setCreateMissingPath((flags & AssignFieldPathUpdate.CREATE_MISSING_PATH) != 0); if ((flags & AssignFieldPathUpdate.ARITHMETIC_EXPRESSION) != 0) { update.setExpression(getString(null)); } else { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); fv.deserialize(this); update.setNewValue(fv); } }
public void read(AssignFieldPathUpdate update) { byte flags = getByte(null); update.setRemoveIfZero((flags & AssignFieldPathUpdate.REMOVE_IF_ZERO) != 0); update.setCreateMissingPath((flags & AssignFieldPathUpdate.CREATE_MISSING_PATH) != 0); if ((flags & AssignFieldPathUpdate.ARITHMETIC_EXPRESSION) != 0) { update.setExpression(getString(null)); } else { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); fv.deserialize(this); update.setNewValue(fv); } }