Interface Instance<N>
- Type Parameters:
N- the node type of the JSON model
- All Known Implementing Classes:
Instance.LogicalInstance, Instance.NodesInstance, Instance.ValueInstance
public sealed interface Instance<N>
permits Instance.ValueInstance<N>, Instance.LogicalInstance<N>, Instance.NodesInstance<N>
An instance of a declared type: a function argument or a function result (RFC 9535, Section 2.4.1, Table 13).
| Declared type | Record | Example of a source in a query |
|---|---|---|
| ValueType | Instance.ValueInstance |
'text', @.price, length(@) |
| LogicalType | Instance.LogicalInstance |
@.a == 1, match(@, 'a.*'), an existence test @.a |
| NodesType | Instance.NodesInstance |
@.*, $..book |
A FunctionExtension receives instances and gives an instance:
// first(NodesType): ValueType. The first node of a nodelist, or Nothing.
// A read-only extension: it runs with each JsonModel, also with a read-only model.
static final class First implements FunctionExtension {
static final FunctionSignature SIGNATURE =
new FunctionSignature("first", FunctionType.VALUE, List.of(FunctionType.NODES));
@Override
public FunctionSignature signature() {
return SIGNATURE;
}
@Override
public <N> Instance<N> apply(List<Instance<N>> arguments, JsonModel<N> model) {
// The evaluator gives one instance for each parameter, of the declared type.
List<Node<N>> nodes = ((Instance.NodesInstance<N>) arguments.getFirst()).nodes();
// A ValueType result is an existing node, or Nothing.
return new Instance.ValueInstance<>(nodes.isEmpty() ? Maybe.none() : Maybe.some(nodes.getFirst().value()));
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordAn instance of LogicalType: LogicalTrue or LogicalFalse.static final recordAn instance of NodesType: a nodelist.static final recordAn instance of ValueType: a node, or Nothing.