Permalink
Browse files

Generalized IdGraph to selectively enable custom vertex or edge IDs, …

…accommodating base graphs which do not support either edge or vertex indexing
  • Loading branch information...
1 parent 0c3a854 commit ca64cf8c68286e15f3c389a4c08485e5dccb35e6 @joshsh joshsh committed Mar 12, 2013
View
@@ -15,6 +15,7 @@ h3. Version 2.3.0 (NOT OFFICIALLY RELEASED YET)
</dependency>
```
+* Generalized @IdGraph@ to selectively enable custom vertex or edge IDs
* Stricter testing of property keys/value to ensure legal Blueprints values (no id, label, empty string, null)
* @Element.getProperty()@ API signature changed to support automatic typing to declared variable type
* Moved @PropertyGraphSail@, which provides a dynamic RDF view of any Blueprints graph, from Tinkubator into @blueprints-graph-sail@
@@ -11,7 +11,7 @@
public class IdEdge extends IdElement implements Edge {
protected IdEdge(final Edge base, final IdGraph idGraph) {
- super(base, idGraph);
+ super(base, idGraph, idGraph.getSupportEdgeIds());
}
public Edge getBaseEdge() {
@@ -16,45 +16,60 @@
protected final IdGraph idGraph;
- protected IdElement(final Element baseElement, final IdGraph idGraph) {
+ protected final boolean propertyBased;
+
+ protected IdElement(final Element baseElement,
+ final IdGraph idGraph,
+ final boolean propertyBased) {
this.baseElement = baseElement;
this.idGraph = idGraph;
+ this.propertyBased = propertyBased;
}
public <T> T getProperty(final String key) {
- if (key.equals(IdGraph.ID)) {
+ if (propertyBased && key.equals(IdGraph.ID)) {
return null;
}
return baseElement.getProperty(key);
}
public Set<String> getPropertyKeys() {
- final Set<String> keys = baseElement.getPropertyKeys();
- final Set<String> s = new HashSet<String>();
- s.addAll(keys);
- s.remove(IdGraph.ID);
- return s;
+ if (propertyBased) {
+ final Set<String> keys = baseElement.getPropertyKeys();
+ final Set<String> s = new HashSet<String>();
+ s.addAll(keys);
+ s.remove(IdGraph.ID);
+ return s;
+ } else {
+ return baseElement.getPropertyKeys();
+ }
}
public void setProperty(final String key, final Object value) {
- if (key.equals(IdGraph.ID)) {
- throw new IllegalArgumentException("Unable to set value for reserved property " + IdGraph.ID);
+ if (propertyBased) {
+ if (key.equals(IdGraph.ID)) {
+ throw new IllegalArgumentException("Unable to set value for reserved property " + IdGraph.ID);
+ }
}
baseElement.setProperty(key, value);
}
public <T> T removeProperty(final String key) {
- if (key.equals(IdGraph.ID)) {
- throw new IllegalArgumentException("Unable to remove value for reserved property " + IdGraph.ID);
+ if (propertyBased) {
+ if (key.equals(IdGraph.ID)) {
+ throw new IllegalArgumentException("Unable to remove value for reserved property " + IdGraph.ID);
+ }
}
return baseElement.removeProperty(key);
}
public Object getId() {
- return baseElement.getProperty(IdGraph.ID);
+ return propertyBased
+ ? baseElement.getProperty(IdGraph.ID)
+ : baseElement.getId();
}
public int hashCode() {
Oops, something went wrong.

0 comments on commit ca64cf8

Please sign in to comment.