1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.layer0.utils.binaryPredicates;
14 import java.util.Collection;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.utils.NameUtils;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.utils.datastructures.Pair;
23 public class Relation extends BinaryPredicate {
27 public Relation(Resource relation) {
28 this.relation = relation;
32 public Collection<Resource> getObjects(ReadGraph g, Resource subject) throws DatabaseException {
33 return g.getObjects(subject, relation);
37 public Collection<Pair<Resource, Resource>> getStatements(ReadGraph g) {
38 throw new UnsupportedOperationException();
42 public Collection<Resource> getSubjects(ReadGraph g, Resource object) throws DatabaseException {
43 return g.getObjects(object, g.getInverse(relation));
47 public boolean has(ReadGraph g, Resource subject, Resource object) throws DatabaseException {
48 return g.hasStatement(subject, relation, object);
52 public boolean supportsGetObjects() {
57 public boolean supportsGetStatements() {
62 public boolean supportsGetSubjects() {
67 public void add(WriteGraph g, Resource subject, Resource object) throws DatabaseException {
68 g.claim(subject, relation, object);
72 public void remove(WriteGraph g, Resource subject, Resource object) throws DatabaseException {
73 g.denyStatement(subject, relation, object);
77 public boolean supportsAdditions() {
82 public boolean supportsRemovals() {
87 public int hashCode() {
90 result = prime * result
91 + ((relation == null) ? 0 : relation.hashCode());
96 public boolean equals(Object obj) {
101 if (getClass() != obj.getClass())
103 Relation other = (Relation) obj;
104 if (relation == null) {
105 if (other.relation != null)
107 } else if (!relation.equals(other.relation))
113 public IBinaryPredicate inverse(ReadGraph g) throws DatabaseException {
114 return new Relation(g.getInverse(relation));
118 public String toString(ReadGraph g) throws DatabaseException {
119 return NameUtils.getSafeName(g, relation);