Skip to content

Commit

Permalink
Merge branch 'experiment/properties-in-elements' (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed May 10, 2016
2 parents f53992d + ba2f17d commit fa01d7c
Show file tree
Hide file tree
Showing 20 changed files with 713 additions and 723 deletions.
98 changes: 98 additions & 0 deletions src/main/java/com/bio4j/angulillos/AnyEdgeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.bio4j.angulillos;

/*
## Edges
A typed edge with explicit source and target.
- `S` the source TypedVertex, `ST` the source TypedVertex type
- `E` the edge, `ET` the edge type
- `T` the target TypedVertex, `TT` the target TypedVertex type
*/
public interface AnyEdgeType extends
AnyElementType,
HasFromArity,
HasToArity
{

AnyVertexType sourceType();
AnyVertexType targetType();
}

// TODO: make it public
interface TypedEdge <
// source vertex
S extends TypedVertex<S,ST, ?,RV,RE>,
ST extends TypedVertex.Type<S,ST, ?,RV,RE>,
// edge
E extends TypedEdge<S,ST, E,ET, T,TT, G,RV,RE>,
ET extends TypedEdge.Type<S,ST, E,ET, T,TT, G,RV,RE>,
// target vertex
T extends TypedVertex<T,TT, ?,RV,RE>,
TT extends TypedVertex.Type<T,TT, ?,RV,RE>,
// graph & raws
G extends TypedGraph<G,RV,RE>,
RV,RE
>
extends TypedElement<E,ET,G,RE>
{

interface Type <
// source vertex
S extends TypedVertex<S,ST, ?,RV,RE>,
ST extends TypedVertex.Type<S,ST, ?,RV,RE>,
// edge
E extends TypedEdge<S,ST, E,ET, T,TT, G,RV,RE>,
ET extends TypedEdge.Type<S,ST, E,ET, T,TT, G,RV,RE>,
// target vertex
T extends TypedVertex<T,TT, ?,RV,RE>,
TT extends TypedVertex.Type<T,TT, ?,RV,RE>,
// graph & raws
G extends TypedGraph<G,RV,RE>,
RV,RE
> extends
TypedElement.Type<E,ET,G,RE>,
AnyEdgeType
{
ST sourceType();
TT targetType();

/* adds an edge; note that this method does not set any properties. As it needs to be called by vertices in possibly different graphs, all the graph bounds are free with respect to G. */
default E addEdge(S from, T to) {

return this.fromRaw(
graph().raw().addEdge( from.raw(), this, to.raw() )
);
}

}


/* the source vertex of this edge */
default S source() {
return type().sourceType().fromRaw(
graph().raw().source( raw() )
);
}

/* the target vertex of this edge */
default T target() {
return type().targetType().fromRaw(
graph().raw().target( raw() )
);
}


@Override default
<X> X get(Property<ET,X> property) {
return graph().raw().<X>getPropertyE(raw(), property);
}

@Override default
<X> E set(Property<ET,X> property, X value) {

graph().raw().setPropertyE(raw(), property, value);
return self();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bio4j.angulillos;

import java.util.Set;

/*
## Elements
Expand All @@ -13,6 +15,12 @@
`E` refers to the element itself, and `ET` its type. You cannot define one without defining the other.
*/
public interface AnyElementType extends HasLabel {

AnyTypedGraph graph();
Set<AnyProperty> properties();
}

interface TypedElement <
F extends TypedElement<F,FT, G,RF>,
FT extends TypedElement.Type<F,FT, G,RF>,
Expand All @@ -31,12 +39,11 @@ interface Type <
FT extends TypedElement.Type<F,FT, G,RF>,
G extends TypedGraph<G,?,?>,
RF
> {
> extends AnyElementType {
public G graph();

/* Constructs a value of the typed element of this type */
F fromRaw(RF rawElem);

// NOTE: this should be final, but interface cannot have final methods
default String _label() { return getClass().getCanonicalName(); }
}


Expand All @@ -50,7 +57,7 @@ interface Type <
RF raw();

/* The graph in which this element lives. */
G graph();
default G graph() { return type().graph(); }

/* The `get` method lets you get the value of a `property` which this element has. For that, you pass as an argument the [property](Property.java.md). Note that the type bounds only allow properties of this element. */
<X> X get(Property<FT,X> property);
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/bio4j/angulillos/AnyProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bio4j.angulillos;

/*
## Properties
A property of the [Element](TypedElement.java.md) of type `FT`, with value type `X`.
*/
public interface AnyProperty extends
HasLabel,
HasFromArity {

AnyElementType elementType();
Class<?> valueClass();
}

// TODO: make it public
interface Property<
FT extends TypedElement.Type<?,FT,?,?>,
X
> extends AnyProperty {

FT elementType();
Class<X> valueClass();
}
Loading

0 comments on commit fa01d7c

Please sign in to comment.