WriteGraph g, Layer0 L0, Resource list,
Resource before, Resource after,
Iterable<Resource> elements) throws DatabaseException {
+ Resource elementPredicate = getElementPredicate(g, list);
for(Resource item : elements) {
Resource cur = g.newResource();
g.claim(cur, L0.InstanceOf, null, L0.List_Entry);
g.claim(cur, L0.IsOwnedBy, L0.IsComposedOf, list);
g.claim(before, L0.List_Next, L0.List_Previous, cur);
- g.claim(cur, L0.List_Element, item);
+ g.claim(cur, elementPredicate, item);
before = cur;
}
g.claim(before, L0.List_Next, L0.List_Previous, after);
WriteGraph g, Layer0 L0, Resource list,
Resource before, Resource after,
Resource[] elements) throws DatabaseException {
+ Resource elementPredicate = getElementPredicate(g, list);
for(Resource item : elements) {
Resource cur = g.newResource();
g.claim(cur, L0.InstanceOf, null, L0.List_Entry);
g.claim(cur, L0.IsOwnedBy, L0.IsComposedOf, list);
g.claim(before, L0.List_Next, L0.List_Previous, cur);
- g.claim(cur, L0.List_Element, item);
+ g.claim(cur, elementPredicate, item);
before = cur;
}
g.claim(before, L0.List_Next, L0.List_Previous, after);
}
public static void createExisting(WriteOnlyGraph g, Resource list, Iterable<Resource> elements) throws DatabaseException {
+ createExisting(g, list, false, elements);
+ }
+
+ public static void createExisting(WriteOnlyGraph g, Resource list, boolean withInverses, Iterable<Resource> elements) throws DatabaseException {
Layer0 L0 = g.getService(Layer0.class);
Resource before = list;
+ Resource elementPredicate = withInverses ? L0.List_ElementWithInverse : L0.List_Element;
for(Resource item : elements) {
Resource cur = g.newResource();
g.claim(cur, L0.InstanceOf, null, L0.List_Entry);
g.claim(cur, L0.IsOwnedBy, L0.IsComposedOf, list);
g.claim(before, L0.List_Next, L0.List_Previous, cur);
- g.claim(cur, L0.List_Element, null, item);
+ g.claim(cur, elementPredicate, null, item);
before = cur;
}
g.claim(before, L0.List_Next, L0.List_Previous, list);
Resource node = getNode(g, list, element);
if(node != null) {
+ Resource elementPredicate = getElementPredicate(g, list);
g.deny(node, L0.List_Element);
- g.claim(node, L0.List_Element, replacement);
+ g.claim(node, elementPredicate, replacement);
return true;
} else {
return false;
while(!cur.equals(list)) {
Resource el = g.getPossibleObject(cur, L0.List_Element);
Resource next = g.getSingleObject(cur, L0.List_Next);
- if(element.equals(el)) {
+ if(element.equals(el)) {
g.deny(cur);
g.claim(prev, L0.List_Next, next);
return true;
while(!cur.equals(list)) {
Resource el = g.getPossibleObject(cur, L0.List_Element);
Resource next = g.getSingleObject(cur, L0.List_Next);
- if(elements.contains(el)) {
+ if(elements.contains(el)) {
g.deny(cur);
g.claim(prev, L0.List_Next, next);
removed = true;
Resource prev = g.getSingleObject(node, L0.List_Previous);
if(list.equals(prev))
return false;
- swap(g, node, prev);
+ swap(g, list, node, prev);
return true;
}
Resource next = g.getSingleObject(node, L0.List_Next);
if(list.equals(next))
return false;
- swap(g, node, next);
+ swap(g, list, node, next);
return true;
}
- private static void swap(WriteGraph g, Resource a, Resource b) throws DatabaseException {
+ private static void swap(WriteGraph g, Resource list, Resource a, Resource b) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(g);
Resource ea = g.getPossibleObject(a, L0.List_Element);
Resource eb = g.getPossibleObject(b, L0.List_Element);
g.deny(a, L0.List_Element);
g.deny(b, L0.List_Element);
+ Resource elementPredicate = getElementPredicate(g, list);
+
if(eb != null)
- g.claim(a, L0.List_Element, eb);
+ g.claim(a, elementPredicate, eb);
if(ea != null)
- g.claim(b, L0.List_Element, ea);
+ g.claim(b, elementPredicate, ea);
}
+ public static Resource getElementPredicate(ReadGraph g, Resource list) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(g);
+ Resource predicate = g.getPossibleObject(list, L0.List_ElementPredicate);
+ if(predicate != null) return predicate;
+ return g.isInstanceOf(list, L0.ListWithInverses) ?
+ L0.List_ElementWithInverse : L0.List_Element;
+ }
+
+ public static Resource getListElementList(ReadGraph g, Resource element) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(g);
+ return g.getSingleObject(element, L0.IsOwnedBy);
+ }
+
}