Skip to content

Commit

Permalink
Axiom: Added AxiomPath and related concepts
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkacik <tony.tkacik@evolveum.com>
  • Loading branch information
tonydamage committed Jun 29, 2020
1 parent 1b22585 commit 34a645d
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 5 deletions.
@@ -0,0 +1,9 @@
package com.evolveum.axiom.api;

public class AxiomInfraName extends NamedPathComponent implements AxiomPath.InfraItem {

AxiomInfraName(AxiomItemName name) {
super(name);
}

}
Expand Up @@ -16,6 +16,7 @@
public interface AxiomItem<V> {

AxiomName name();

Optional<AxiomItemDefinition> definition();

Collection<? extends AxiomValue<V>> values();
Expand All @@ -42,5 +43,4 @@ static <V> AxiomItem<V> from(AxiomItemDefinition def, AxiomValue<V> value) {
return AxiomItemImpl.from(def, Collections.singleton(value));
}


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

import com.google.common.collect.Interner;
import com.google.common.collect.Interners;

public class AxiomItemName extends AxiomName implements AxiomPath.Item {

private static final Interner<AxiomItemName> INTERNER = Interners.newWeakInterner();

AxiomItemName(AxiomName name) {
super(name.namespace(), name.localName());
}

AxiomItemName(String namespace, String localName) {
super(namespace, localName);
}

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

public static AxiomItemName of(AxiomName name) {
if(name instanceof AxiomItemName) {
return (AxiomItemName) name;
}
return INTERNER.intern(new AxiomItemName(name));
}

}
10 changes: 7 additions & 3 deletions infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomName.java
Expand Up @@ -14,6 +14,8 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;

public class AxiomName {

Expand All @@ -23,12 +25,14 @@ public class AxiomName {
public static final String TYPE_NAMESPACE = "https://schema.evolveum.com/ns/axiom/types";
public static final String DATA_NAMESPACE = "https://schema.evolveum.com/ns/axiom/data";

private static final Interner<AxiomName> INTERNER = Interners.newWeakInterner();

private final String namespace;
private final String localName;

private static final Splitter HASH_SYMBOL = Splitter.on('#');

public AxiomName(String namespace, String localName) {
AxiomName(String namespace, String localName) {
this.namespace = Preconditions.checkNotNull(namespace, "namespace");
this.localName = Preconditions.checkNotNull(localName, "localName");
}
Expand Down Expand Up @@ -79,11 +83,11 @@ public String toString() {
}

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

public static AxiomName from(String namespace, String localName) {
return new AxiomName(namespace, localName);
return INTERNER.intern(new AxiomName(namespace, localName));
}

public boolean sameNamespace(AxiomName other) {
Expand Down
39 changes: 39 additions & 0 deletions infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomPath.java
@@ -0,0 +1,39 @@
package com.evolveum.axiom.api;

import java.util.Collection;

public interface AxiomPath {

Collection<Component<?>> components();

/**
*
* Marker interface for AxiomPath Arguments
*
* @param <T> Specialization type
*/
interface Component<T extends Component<T>> {

}

static AxiomItemName item(AxiomName name) {
return AxiomItemName.of(name);
}

interface Variable extends Component<Variable> {
AxiomName name();
}

interface InfraItem extends Component<InfraItem> {
AxiomName name();
}


interface Item extends Component<Item> {
AxiomName name();
}

interface Value extends Component<Value> {
AxiomValueIdentifier identifier();
}
}
@@ -0,0 +1,37 @@
package com.evolveum.axiom.api;

import java.util.Collection;
import java.util.Objects;

import com.google.common.collect.ImmutableList;

class AxiomPathImpl implements AxiomPath {

private final Collection<Component<?>> components;

public AxiomPathImpl(Collection<Component<?>> components) {
this.components = ImmutableList.copyOf(components);
}

@Override
public Collection<Component<?>> components() {
return components;
}

@Override
public int hashCode() {
return components().hashCode();
}

@Override
public boolean equals(Object other) {
if(other == this) {
return true;
}
if(other instanceof AxiomPath) {
return Objects.equals(this.components(), ((AxiomPath) other).components());
}
return false;
}

}
Expand Up @@ -8,7 +8,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;

public class AxiomValueIdentifier {
public class AxiomValueIdentifier implements AxiomPath.Value {

private final Map<AxiomName, Object> components;

Expand Down Expand Up @@ -71,4 +71,8 @@ public static AxiomValueIdentifier from(AxiomIdentifierDefinition key, AxiomValu
return from(components.build());
}

@Override
public AxiomValueIdentifier identifier() {
return this;
}
}
@@ -0,0 +1,10 @@
package com.evolveum.axiom.api;

public class AxiomVariableName extends NamedPathComponent implements AxiomPath.Variable {

public AxiomVariableName(AxiomName name) {
super(name);
}


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

import java.util.Objects;

import org.jetbrains.annotations.NotNull;

abstract class NamedPathComponent {

private final @NotNull AxiomName name;

public NamedPathComponent(AxiomName name) {
super();
this.name = name;
}

public AxiomName name() {
return name;
}

@Override
public final int hashCode() {
return name.hashCode();
}

@Override
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NamedPathComponent other = (NamedPathComponent) obj;
return Objects.equals(name(), other.name());
}



}
13 changes: 13 additions & 0 deletions infra/axiom/src/main/java/com/evolveum/axiom/api/ValueBuilder.java
@@ -0,0 +1,13 @@
package com.evolveum.axiom.api;

import com.evolveum.axiom.concepts.Builder;

public interface ValueBuilder<P extends AxiomValue<?>> extends Builder<P> {




interface BuilderOrValue<P extends AxiomValue<?>> extends Builder.OrProduct<P, ValueBuilder<P>> {

}
}
28 changes: 28 additions & 0 deletions infra/axiom/src/main/java/com/evolveum/axiom/concepts/Builder.java
@@ -0,0 +1,28 @@
package com.evolveum.axiom.concepts;

import java.util.Optional;

import com.evolveum.axiom.concepts.Lazy.Supplier;

public interface Builder<P> {

P build();

interface OrProduct<P,B extends Builder<P>> extends Supplier<P> {

Optional<? extends B> builder();

Optional<? extends P> product();

@Override
default P get() {
if(product().isPresent()) {
return product().get();
}
if(builder().isPresent()) {
return builder().get().build();
}
throw new IllegalStateException("No product or builder is present");
}
}
}
@@ -0,0 +1,6 @@
package com.evolveum.axiom.concepts;

public interface CheckedFunction<I,O,E extends Exception> {

O apply(I input) throws E;
}
@@ -0,0 +1,6 @@
package com.evolveum.axiom.concepts;

public interface CheckedSupplier<O,E extends Exception> {

O get() throws E;
}
@@ -0,0 +1,9 @@
package com.evolveum.axiom.concepts;

import java.util.Optional;

public interface Navigable<K, N extends Navigable<K,N>> {

Optional<? extends N> resolve(K key);

}
@@ -0,0 +1,6 @@
package com.evolveum.axiom.concepts;

public interface Path<P> {

Iterable<? extends P> components();
}
@@ -0,0 +1,12 @@
package com.evolveum.axiom.concepts;

import java.util.Collection;
import java.util.Optional;

public interface PathNavigable<V,K,P extends Path<K>> {

Optional<? extends PathNavigable<V,K,P>> resolve(K key);

Collection<? extends PathNavigable<V, K, P>> resolve(P key);
}

0 comments on commit 34a645d

Please sign in to comment.