-
Notifications
You must be signed in to change notification settings - Fork 188
/
AxiomValue.java
54 lines (38 loc) · 1.56 KB
/
AxiomValue.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (C) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.axiom.api;
import java.util.Map;
import java.util.Optional;
import com.evolveum.axiom.api.schema.AxiomTypeDefinition;
public interface AxiomValue<V> extends AxiomInfraValue {
AxiomName TYPE = AxiomName.axiom("type");
AxiomName VALUE = AxiomName.axiom("value");
AxiomName METADATA = AxiomName.axiom("metadata");
Optional<AxiomTypeDefinition> type();
V value();
default Optional<? extends AxiomComplexValue> metadata() {
return infraItem(METADATA).flatMap(v -> v.onlyValue().asComplex());
}
default Optional<? extends AxiomItem<?>> metadata(AxiomName name) {
return metadata().flatMap(m -> m.item(name));
}
default Optional<AxiomComplexValue> asComplex() {
if(this instanceof AxiomComplexValue) {
return Optional.of((AxiomComplexValue) this);
}
return Optional.empty();
}
interface Factory<V,T extends AxiomValue<V>> extends AxiomInfraValue.Factory<T> {
@Override
default T create(Map<AxiomName, AxiomItem<?>> infraItems) {
AxiomTypeDefinition type = (AxiomTypeDefinition) infraItems.get(TYPE).onlyValue().value();
V value = (V) infraItems.get(VALUE).onlyValue().value();
return create(type, value, infraItems);
}
T create(AxiomTypeDefinition type, V value, Map<AxiomName, AxiomItem<?>> infraItems);
}
}