Skip to content

Commit

Permalink
Axiom: Renamed reactor context to reflect Item & Value terminology
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
  • Loading branch information
tonydamage committed May 21, 2020
1 parent d919536 commit aae76b6
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 16 deletions.
Expand Up @@ -17,4 +17,5 @@ default AxiomItemValue<V> onlyValue() {
return Iterables.getOnlyElement(values());
}


}
@@ -0,0 +1,9 @@
package com.evolveum.axiom.lang.api;

import java.util.Collection;

public interface AxiomItemFactory<V> {

AxiomItem<V> create(AxiomItemDefinition def, Collection<? extends AxiomItemValue<?>> axiomItem);

}
Expand Up @@ -21,8 +21,10 @@ default Collection<AxiomItem<?>> items(AxiomIdentifier name) {
return Collections2.filter(items(), value -> name.equals(value.name()));
}


@Override
V get();

interface Factory<V,T extends AxiomItemValue<V>> {
T create(AxiomTypeDefinition def, V value, Collection<AxiomItem<?>> items);
}
}
@@ -0,0 +1,51 @@
package com.evolveum.axiom.lang.api;

import com.evolveum.axiom.concepts.Lazy;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Supplier;

import javax.annotation.concurrent.NotThreadSafe;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;

@NotThreadSafe
public class AxiomItemValueBuilder<V,T extends AxiomItemValue<V>> implements Lazy.Supplier<T> {

private final AxiomTypeDefinition type;

private final AxiomItemValueFactory<V,T> factory;
private Map<AxiomIdentifier, Supplier<? extends AxiomItem<?>>> children = new LinkedHashMap<>();
private V value;

public AxiomItemValueBuilder(AxiomTypeDefinition type, AxiomItemValueFactory<V,T> factory) {
this.type = type;
this.factory = factory;
}

public V getValue() {
return value;
}

public void setValue(V value) {
this.value = value;
}

public void add(AxiomIdentifier name, Supplier<? extends AxiomItem<?>> child) {
children.put(name, child);
}

@Override
public T get() {
Builder<AxiomIdentifier, AxiomItem<?>> builder = ImmutableMap.builder();
for(Entry<AxiomIdentifier, Supplier<? extends AxiomItem<?>>> entry : children.entrySet()) {
builder.put(entry.getKey(), entry.getValue().get());
}
return factory.create(type, value, builder.build().values());
}

}
@@ -0,0 +1,9 @@
package com.evolveum.axiom.lang.api;

import java.util.Collection;

public interface AxiomItemValueFactory<V,T extends AxiomItemValue<V>> {

T create(AxiomTypeDefinition def, V value, Collection<AxiomItem<?>> items);
}

Expand Up @@ -14,11 +14,12 @@
import com.evolveum.axiom.api.AxiomIdentifier;
import com.google.common.collect.ImmutableMap;

public interface AxiomTypeDefinition extends AxiomNamedDefinition, AxiomItemValue<AxiomTypeDefinition> {
public interface AxiomTypeDefinition extends AxiomNamedDefinition {

public final AxiomIdentifier IDENTIFIER_MEMBER = AxiomIdentifier.axiom("name");
public final AxiomIdentifier IDENTIFIER_SPACE = AxiomIdentifier.axiom("AxiomTypeDefinition");

/*
@Override
default AxiomTypeDefinition get() {
return this;
Expand All @@ -27,7 +28,7 @@ default AxiomTypeDefinition get() {
@Override
default Optional<AxiomTypeDefinition> definition() {
return Optional.empty();
}
}*/

Optional<AxiomItemDefinition> argument();

Expand Down
Expand Up @@ -44,7 +44,7 @@ public abstract class StatementContextImpl<V> implements AxiomStatementContext<V

protected void initResult() {
AxiomStatementBuilder<V> builder = new AxiomStatementBuilder<>(definition.name(), typeFactory(definition.type()));
this.result = new StatementContextResult<>(definition, builder);
this.result = new StatementResultContextImpl<>(definition, builder);
}

protected <T> Factory<T, ? extends AxiomStatement<T>> typeFactory(AxiomTypeDefinition type) {
Expand All @@ -56,9 +56,9 @@ public void setValue(Object value) {
mutableResult().setValue((V) value);
}

private StatementContextResult<V> mutableResult() {
if(result instanceof StatementContextResult) {
return (StatementContextResult) result;
private StatementResultContextImpl<V> mutableResult() {
if(result instanceof StatementResultContextImpl) {
return (StatementResultContextImpl) result;
}
return null;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public void setValue(Object value, SourceLocation loc) {
}

public Dependency<AxiomStatement<V>> asRequirement() {
if (result instanceof StatementContextResult) {
if (result instanceof StatementResultContextImpl) {
return Dependency.deffered(result);
}
return result;
Expand Down Expand Up @@ -217,8 +217,8 @@ private void registerLocalParent(AxiomIdentifier space, IdentifierSpaceKey key)

@Override
public V requireValue(Class<V> type) {
if(result instanceof StatementContextResult) {
return type.cast(((StatementContextResult) result).value());
if(result instanceof StatementResultContextImpl) {
return type.cast(((StatementResultContextImpl) result).value());
}
return null;
}
Expand Down
Expand Up @@ -13,7 +13,7 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

class StatementContextResult<V> implements Dependency<AxiomStatement<V>> {
class StatementResultContextImpl<V> implements Dependency<AxiomStatement<V>> {

private V value;
private final List<StatementContextImpl<?>> childrenList = new ArrayList<>();
Expand All @@ -22,7 +22,7 @@ class StatementContextResult<V> implements Dependency<AxiomStatement<V>> {

private final List<StatementRuleContextImpl<V>> rules = new ArrayList<>();

public StatementContextResult(AxiomItemDefinition definition, AxiomStatementBuilder<V> builder) {
public StatementResultContextImpl(AxiomItemDefinition definition, AxiomStatementBuilder<V> builder) {
super();
this.builder = builder;
}
Expand Down
Expand Up @@ -7,17 +7,13 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.checkerframework.checker.units.qual.K;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.concepts.Identifiable;
import com.evolveum.axiom.lang.api.AxiomBuiltIn;
import com.evolveum.axiom.lang.api.AxiomIdentifierDefinition;
import com.evolveum.axiom.lang.api.AxiomItemDefinition;
import com.evolveum.axiom.lang.api.AxiomTypeDefinition;
import com.evolveum.axiom.lang.api.AxiomBuiltIn.Item;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Multimap;

import static com.evolveum.axiom.lang.api.AxiomBuiltIn.Item.*;
Expand Down

0 comments on commit aae76b6

Please sign in to comment.