Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Axiom: Added AxiomPath and related concepts
Signed-off-by: Tony Tkacik <tony.tkacik@evolveum.com>
- Loading branch information
1 parent
1b22585
commit 34a645d
Showing
16 changed files
with
260 additions
and
5 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomInfraName.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,9 @@ | ||
package com.evolveum.axiom.api; | ||
|
||
public class AxiomInfraName extends NamedPathComponent implements AxiomPath.InfraItem { | ||
|
||
AxiomInfraName(AxiomItemName name) { | ||
super(name); | ||
} | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomItemName.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,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)); | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomPath.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,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(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomPathImpl.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,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; | ||
} | ||
|
||
} |
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
10 changes: 10 additions & 0 deletions
10
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomVariableName.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,10 @@ | ||
package com.evolveum.axiom.api; | ||
|
||
public class AxiomVariableName extends NamedPathComponent implements AxiomPath.Variable { | ||
|
||
public AxiomVariableName(AxiomName name) { | ||
super(name); | ||
} | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
infra/axiom/src/main/java/com/evolveum/axiom/api/NamedPathComponent.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,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
13
infra/axiom/src/main/java/com/evolveum/axiom/api/ValueBuilder.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,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
28
infra/axiom/src/main/java/com/evolveum/axiom/concepts/Builder.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,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"); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
infra/axiom/src/main/java/com/evolveum/axiom/concepts/CheckedFunction.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,6 @@ | ||
package com.evolveum.axiom.concepts; | ||
|
||
public interface CheckedFunction<I,O,E extends Exception> { | ||
|
||
O apply(I input) throws E; | ||
} |
6 changes: 6 additions & 0 deletions
6
infra/axiom/src/main/java/com/evolveum/axiom/concepts/CheckedSupplier.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,6 @@ | ||
package com.evolveum.axiom.concepts; | ||
|
||
public interface CheckedSupplier<O,E extends Exception> { | ||
|
||
O get() throws E; | ||
} |
9 changes: 9 additions & 0 deletions
9
infra/axiom/src/main/java/com/evolveum/axiom/concepts/Navigable.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,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); | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
infra/axiom/src/main/java/com/evolveum/axiom/concepts/Path.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,6 @@ | ||
package com.evolveum.axiom.concepts; | ||
|
||
public interface Path<P> { | ||
|
||
Iterable<? extends P> components(); | ||
} |
12 changes: 12 additions & 0 deletions
12
infra/axiom/src/main/java/com/evolveum/axiom/concepts/PathNavigable.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,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); | ||
} | ||
|