Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tony Tkacik <tony.tkacik@evolveum.com>
- Loading branch information
1 parent
30904b5
commit 3f4cd87
Showing
16 changed files
with
176 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 27 additions & 7 deletions
34
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,48 @@ | ||
package com.evolveum.axiom.api; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import com.evolveum.axiom.api.schema.AxiomTypeDefinition; | ||
|
||
|
||
public interface AxiomValue<V> { | ||
|
||
Optional<AxiomTypeDefinition> type(); | ||
|
||
default Collection<AxiomItem<?>> metadata() { | ||
return Collections.emptyList(); | ||
} | ||
AxiomName TYPE = AxiomName.axiom("type"); | ||
AxiomName VALUE = AxiomName.axiom("value"); | ||
|
||
Optional<AxiomTypeDefinition> type(); | ||
|
||
V value(); | ||
|
||
default <C> C value(Class<C> type) { | ||
V value = value(); | ||
if(type.isInstance(value)) { | ||
return type.cast(value); | ||
} | ||
return null; | ||
} | ||
|
||
default Optional<AxiomComplexValue> asComplex() { | ||
if(this instanceof AxiomComplexValue) { | ||
return Optional.of((AxiomComplexValue) this); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
default Optional<AxiomItem<?>> infraItem(AxiomName name) { | ||
return Optional.empty(); | ||
} | ||
|
||
interface InfraFactory<V, T extends AxiomValue<V>> { | ||
|
||
default T create(Map<AxiomName, AxiomItem<?>> infraItems) { | ||
AxiomTypeDefinition type = infraItems.get(TYPE).onlyValue().value(AxiomTypeDefinition.class); | ||
V value = (V) infraItems.get(VALUE).onlyValue().value(); | ||
return create(type, value, infraItems); | ||
} | ||
|
||
T create(AxiomTypeDefinition valueType, V value, Map<AxiomName,AxiomItem<?>> infraItems); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomValueInfraBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.evolveum.axiom.api; | ||
|
||
import com.evolveum.axiom.concepts.Lazy; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableMap.Builder; | ||
|
||
public class AxiomValueInfraBuilder<V,T extends AxiomValue<V>> implements Lazy.Supplier<T> { | ||
|
||
private AxiomValue.InfraFactory<V,T> factory; | ||
private Map<AxiomName, Supplier<? extends AxiomItem<?>>> children = new LinkedHashMap<>(); | ||
|
||
protected AxiomValueInfraBuilder(AxiomValue.InfraFactory<V,T> factory) { | ||
this.factory = factory; | ||
} | ||
|
||
public static <V,T extends AxiomValue<V>> AxiomValueInfraBuilder<V,T> from(AxiomValue.InfraFactory<V,T> type) { | ||
return new AxiomValueInfraBuilder<>(type); | ||
} | ||
|
||
public void addInfra(AxiomName name, Supplier<? extends AxiomItem<?>> child) { | ||
children.put(name, child); | ||
} | ||
|
||
public Supplier<? extends AxiomItem<?>> getInfra(AxiomName name) { | ||
return children.get(name); | ||
} | ||
|
||
public Supplier<? extends AxiomItem<?>> getInfra(AxiomName name, Function<AxiomName, ? extends Supplier<? extends AxiomItem<?>>> child) { | ||
return children.computeIfAbsent(name, child); | ||
} | ||
|
||
@Override | ||
public T get() { | ||
Builder<AxiomName, AxiomItem<?>> builder = ImmutableMap.builder(); | ||
for(Entry<AxiomName, Supplier<? extends AxiomItem<?>>> entry : children.entrySet()) { | ||
AxiomItem<?> item = entry.getValue().get(); | ||
builder.put(entry.getKey(), entry.getValue().get()); | ||
} | ||
return factory.create(builder.build()); | ||
} | ||
|
||
} |
44 changes: 0 additions & 44 deletions
44
infra/axiom/src/main/java/com/evolveum/axiom/api/CompactAxiomItem.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.