-
Notifications
You must be signed in to change notification settings - Fork 188
/
AxiomStructuredValue.java
57 lines (43 loc) · 1.75 KB
/
AxiomStructuredValue.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
55
56
57
/*
* 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.Collection;
import java.util.Map;
import java.util.Optional;
import com.evolveum.axiom.api.schema.AxiomItemDefinition;
import com.evolveum.axiom.api.schema.AxiomTypeDefinition;
public interface AxiomStructuredValue extends AxiomValue<Collection<AxiomItem<?>>> {
@Override
default Collection<AxiomItem<?>> value() {
return itemMap().values();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
default Optional<AxiomItem<?>> item(AxiomItemDefinition def) {
return (Optional) item(def.name());
}
default Optional<? extends AxiomItem<?>> item(AxiomName name) {
return Optional.ofNullable(itemMap().get(name));
}
default <T> Optional<AxiomValue<T>> onlyValue(Class<T> type, AxiomItemDefinition... components) {
Optional<AxiomValue<?>> current = Optional.of(this);
for(AxiomItemDefinition name : components) {
current = current.get().asComplex().flatMap(c -> c.item(name)).map(i -> i.onlyValue());
if(!current.isPresent()) {
return Optional.empty();
}
}
return (Optional) current;
}
Map<AxiomName, AxiomItem<?>> itemMap();
interface Factory extends AxiomValueFactory<Collection<AxiomItem<?>>> {
@Override
default AxiomValue<Collection<AxiomItem<?>>> createSimple(AxiomTypeDefinition def,
Collection<AxiomItem<?>> value, Map<AxiomName, AxiomItem<?>> infraItems) {
throw new IllegalStateException("Factory is only for complex types");
}
}
}