blob: 31bbd3e9234fa3793d1ada912a5efa5b84db03d2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Copyright Vespa.ai. 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.FieldValue;
import com.yahoo.document.datatypes.StructuredFieldValue;
/**
* This adds an Extractor to the Field that can be used to access the backed value
* used in the concrete document types.
* @author baldersheim
*/
public class ExtendedField extends Field {
public interface Extract {
Object get(StructuredFieldValue doc);
void set(StructuredFieldValue doc, Object value);
}
private final Extract extract;
public ExtendedField(String name, DataType type, Extract extract) {
super(name, type);
this.extract = extract;
}
public FieldValue getFieldValue(StructuredFieldValue doc) {
Object raw = extract.get(doc);
return raw == null ? null : getDataType().createFieldValue(raw);
}
public FieldValue setFieldValue(StructuredFieldValue doc, FieldValue fv) {
FieldValue old = getFieldValue(doc);
extract.set(doc, (fv == null) ? null : fv.getWrappedValue());
return old;
}
}
|