Skip to content

Commit

Permalink
Axoim: Renamed AxiomIdentifier to AxiomName
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 29, 2020
1 parent aa54e9e commit a0d66c0
Show file tree
Hide file tree
Showing 48 changed files with 308 additions and 309 deletions.
Expand Up @@ -19,7 +19,7 @@ public Optional<AxiomItemDefinition> definition() {
}

@Override
public AxiomIdentifier name() {
public AxiomName name() {
return definition.name();
}
}
Expand Up @@ -9,7 +9,7 @@

public interface AxiomItem<V> {

AxiomIdentifier name();
AxiomName name();
Optional<AxiomItemDefinition> definition();

Collection<AxiomValue<V>> values();
Expand Down
Expand Up @@ -11,13 +11,13 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

public class AxiomIdentifier {
public class AxiomName {

public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom/language";
private final String namespace;
private final String localName;

public AxiomIdentifier(String namespace, String localName) {
public AxiomName(String namespace, String localName) {
this.namespace = Preconditions.checkNotNull(namespace, "namespace");
this.localName = Preconditions.checkNotNull(localName, "localName");
}
Expand All @@ -43,9 +43,9 @@ public int hashCode() {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof AxiomIdentifier))
if (!(obj instanceof AxiomName))
return false;
AxiomIdentifier other = (AxiomIdentifier) obj;
AxiomName other = (AxiomName) obj;
if (localName == null) {
if (other.localName != null)
return false;
Expand All @@ -67,31 +67,31 @@ public String toString() {
return "(" + namespace + ")" +localName;
}

public static AxiomIdentifier axiom(String identifier) {
return new AxiomIdentifier(AXIOM_NAMESPACE, identifier);
public static AxiomName axiom(String identifier) {
return new AxiomName(AXIOM_NAMESPACE, identifier);
}

public static AxiomIdentifier from(String namespace, String localName) {
return new AxiomIdentifier(namespace, localName);
public static AxiomName from(String namespace, String localName) {
return new AxiomName(namespace, localName);
}

public boolean sameNamespace(AxiomIdentifier other) {
public boolean sameNamespace(AxiomName other) {
return this.namespace().equals(other.namespace());
}

public AxiomIdentifier localName(String name) {
return AxiomIdentifier.from(namespace, name);
public AxiomName localName(String name) {
return AxiomName.from(namespace, name);
}

public AxiomIdentifier namespace(String targetNamespace) {
return AxiomIdentifier.from(targetNamespace, localName);
public AxiomName namespace(String targetNamespace) {
return AxiomName.from(targetNamespace, localName);
}

public AxiomIdentifier defaultNamespace() {
return AxiomIdentifier.from("", localName);
public AxiomName defaultNamespace() {
return AxiomName.from("", localName);
}

public static AxiomIdentifier local(@NotNull String localName) {
public static AxiomName local(@NotNull String localName) {
return from("", localName);
}

Expand Down
Expand Up @@ -23,7 +23,7 @@ default Optional<AxiomItem<?>> item(AxiomItemDefinition def) {
}

@SuppressWarnings("unchecked")
default <T> Optional<AxiomItem<T>> item(AxiomIdentifier name) {
default <T> Optional<AxiomItem<T>> item(AxiomName name) {
return items().stream().filter(value -> name.equals(value.name())).findFirst().map(v -> (AxiomItem<T>) v);
}

Expand Down
Expand Up @@ -18,7 +18,7 @@ public class AxiomValueBuilder<V,T extends AxiomValue<V>> implements Lazy.Suppli
private final AxiomTypeDefinition type;

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

public AxiomValueBuilder(AxiomTypeDefinition type, AxiomValueFactory<V,T> factory) {
Expand All @@ -38,22 +38,22 @@ public void setValue(V value) {
this.value = value;
}

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

public Supplier<? extends AxiomItem<?>> get(AxiomIdentifier name) {
public Supplier<? extends AxiomItem<?>> get(AxiomName name) {
return children.get(name);
}

public Supplier<? extends AxiomItem<?>> get(AxiomIdentifier name, Function<AxiomIdentifier, ? extends Supplier<? extends AxiomItem<?>>> child) {
public Supplier<? extends AxiomItem<?>> get(AxiomName name, Function<AxiomName, ? extends Supplier<? extends AxiomItem<?>>> child) {
return children.computeIfAbsent(name, child);
}

@Override
public T get() {
Builder<AxiomIdentifier, AxiomItem<?>> builder = ImmutableMap.builder();
for(Entry<AxiomIdentifier, Supplier<? extends AxiomItem<?>>> entry : children.entrySet()) {
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());
}
Expand Down
Expand Up @@ -6,6 +6,6 @@

public interface AxiomValueFactory<V,T extends AxiomValue<V>> {

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

@@ -1,6 +1,6 @@
package com.evolveum.axiom.api.meta;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.api.AxiomName;
import com.evolveum.axiom.api.schema.AxiomItemDefinition;

public interface Inheritance {
Expand All @@ -11,25 +11,25 @@ public interface Inheritance {
Inheritance CURRENT = NO_CHANGE;


static AxiomIdentifier adapt(AxiomIdentifier parent, AxiomIdentifier child) {
static AxiomName adapt(AxiomName parent, AxiomName child) {
return CURRENT.apply(parent, child);
}

static AxiomIdentifier adapt(AxiomIdentifier parent, AxiomItemDefinition child) {
static AxiomName adapt(AxiomName parent, AxiomItemDefinition child) {
return child.inherited() ? adapt(parent, child.name()) : child.name();
}

AxiomIdentifier apply(AxiomIdentifier parent, AxiomIdentifier child);
AxiomName apply(AxiomName parent, AxiomName child);

static AxiomIdentifier inheritNamespace(AxiomIdentifier parent, AxiomIdentifier name) {
static AxiomName inheritNamespace(AxiomName parent, AxiomName name) {
return parent.localName(name.localName());
}

static AxiomIdentifier noNamespace(AxiomIdentifier parent, AxiomIdentifier name) {
static AxiomName noNamespace(AxiomName parent, AxiomName name) {
return name.defaultNamespace();
}

static AxiomIdentifier noChange(AxiomIdentifier parent, AxiomIdentifier name) {
static AxiomName noChange(AxiomName parent, AxiomName name) {
return name;
}
}
Expand Up @@ -3,7 +3,7 @@
import java.util.Collection;
import java.util.Set;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.api.AxiomName;
import com.evolveum.axiom.api.AxiomValue;
import com.google.common.collect.ImmutableSet;

Expand All @@ -18,19 +18,19 @@ default AxiomIdentifierDefinition get() {

Scope scope();

AxiomIdentifier space();
AxiomName space();

enum Scope {
GLOBAL,
PARENT,
LOCAL
}

static AxiomIdentifierDefinition global(AxiomIdentifier name, AxiomItemDefinition... components) {
static AxiomIdentifierDefinition global(AxiomName name, AxiomItemDefinition... components) {
return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.GLOBAL);
}

static AxiomIdentifierDefinition local(AxiomIdentifier name, AxiomItemDefinition... components) {
static AxiomIdentifierDefinition local(AxiomName name, AxiomItemDefinition... components) {
return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.LOCAL);
}

Expand All @@ -47,11 +47,11 @@ static Scope scope(String scope) {
throw new IllegalArgumentException("Unknown scope " + scope);
}

static AxiomIdentifierDefinition from(AxiomIdentifier space, Scope scope, Set<AxiomItemDefinition> members) {
static AxiomIdentifierDefinition from(AxiomName space, Scope scope, Set<AxiomItemDefinition> members) {
return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(members), space, scope);
}

static AxiomIdentifierDefinition parent(AxiomIdentifier name, AxiomItemDefinition... components) {
static AxiomIdentifierDefinition parent(AxiomName name, AxiomItemDefinition... components) {
return new AxiomIdentifierDefinitionImpl(ImmutableSet.copyOf(components), name, Scope.PARENT);
}

Expand Down
Expand Up @@ -3,18 +3,18 @@
import java.util.Optional;
import java.util.Set;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.api.AxiomName;
import com.google.common.collect.ImmutableSet;

class AxiomIdentifierDefinitionImpl implements AxiomIdentifierDefinition {

private Set<AxiomItemDefinition> components;

private AxiomIdentifier space;
private AxiomName space;

private Scope scope;

public AxiomIdentifierDefinitionImpl(Set<AxiomItemDefinition> components, AxiomIdentifier space, Scope scope) {
public AxiomIdentifierDefinitionImpl(Set<AxiomItemDefinition> components, AxiomName space, Scope scope) {
super();
this.components = ImmutableSet.copyOf(components);
this.space = space;
Expand All @@ -32,7 +32,7 @@ public Scope scope() {
}

@Override
public AxiomIdentifier space() {
public AxiomName space() {
return space;
}

Expand Down
Expand Up @@ -6,17 +6,17 @@
*/
package com.evolveum.axiom.api.schema;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.api.AxiomName;
import com.evolveum.axiom.api.AxiomValue;
import com.evolveum.axiom.lang.api.IdentifierSpaceKey;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;

public interface AxiomItemDefinition extends AxiomNamedDefinition, AxiomValue<AxiomItemDefinition> {

AxiomIdentifier ROOT_SPACE = AxiomIdentifier.axiom("AxiomRootDefinition");
AxiomIdentifier SPACE = AxiomIdentifier.axiom("AxiomItemDefinition");
AxiomIdentifier NAME = AxiomIdentifier.axiom("name");
AxiomName ROOT_SPACE = AxiomName.axiom("AxiomRootDefinition");
AxiomName SPACE = AxiomName.axiom("AxiomItemDefinition");
AxiomName NAME = AxiomName.axiom("name");

@Override
default AxiomItemDefinition get() {
Expand Down Expand Up @@ -47,7 +47,7 @@ static String toString(AxiomItemDefinition def) {
.toString();
}

static AxiomItemDefinition derived(AxiomIdentifier name , AxiomItemDefinition source) {
static AxiomItemDefinition derived(AxiomName name , AxiomItemDefinition source) {
return new DelegatedItemDefinition() {

@Override
Expand All @@ -56,13 +56,13 @@ protected AxiomItemDefinition delegate() {
}

@Override
public AxiomIdentifier name() {
public AxiomName name() {
return name;
}
};
}

static IdentifierSpaceKey identifier(AxiomIdentifier name) {
static IdentifierSpaceKey identifier(AxiomName name) {
return IdentifierSpaceKey.from(ImmutableMap.of(NAME, name));
}

Expand All @@ -78,7 +78,7 @@ interface Extended extends AxiomItemDefinition {

}

default AxiomItemDefinition derived(AxiomIdentifier name) {
default AxiomItemDefinition derived(AxiomName name) {
return derived(name, this);
}

Expand Down
Expand Up @@ -6,10 +6,10 @@
*/
package com.evolveum.axiom.api.schema;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.api.AxiomName;

public interface AxiomNamedDefinition {

AxiomIdentifier name();
AxiomName name();
String documentation();
}
Expand Up @@ -3,15 +3,15 @@
import java.util.Collection;
import java.util.Optional;

import com.evolveum.axiom.api.AxiomIdentifier;
import com.evolveum.axiom.api.AxiomName;

public interface AxiomSchemaContext {

Collection<AxiomItemDefinition> roots();

Optional<AxiomItemDefinition> getRoot(AxiomIdentifier type);
Optional<AxiomItemDefinition> getRoot(AxiomName type);

Optional<AxiomTypeDefinition> getType(AxiomIdentifier type);
Optional<AxiomTypeDefinition> getType(AxiomName type);

Collection<AxiomTypeDefinition> types();

Expand Down

0 comments on commit a0d66c0

Please sign in to comment.