1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.ontotext.ordi.tripleset.impl;
19
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.Set;
24
25 import org.openrdf.model.Resource;
26 import org.openrdf.model.Statement;
27 import org.openrdf.model.URI;
28 import org.openrdf.model.Value;
29 import org.openrdf.model.impl.ContextStatementImpl;
30 import org.openrdf.model.impl.URIImpl;
31
32 import com.ontotext.ordi.tripleset.ORDIConst;
33 import com.ontotext.ordi.tripleset.TStatement;
34
35 public class TStatementImpl extends ContextStatementImpl implements TStatement {
36
37 static final long serialVersionUID = 0;
38 static final URI IMPLICIT_STATEMENT = new URIImpl(ORDIConst.IMPLICIT_STATEMENT);
39
40 protected final Set<URI> tripleSets;
41
42 public TStatementImpl(Resource subject, URI predicate, Value object,
43 Resource context, URI... ts) {
44 super(subject, predicate, object, context);
45 if (ts == null) {
46 throw new IllegalArgumentException();
47 }
48 tripleSets = new HashSet<URI>();
49 Collections.addAll(tripleSets, ts);
50 }
51
52 public TStatementImpl(Resource subject, URI predicate, Value object,
53 Resource context, Set<URI> ts) {
54 super(subject, predicate, object, context);
55 if (ts == null) {
56 throw new IllegalArgumentException();
57 }
58 this.tripleSets = ts;
59 }
60
61 public TStatementImpl(Statement statement, Resource context, URI... ts) {
62 this(statement.getSubject(), statement.getPredicate(), statement
63 .getObject(), statement.getContext(), ts);
64 }
65
66 public TStatementImpl(Statement statement, Resource context, Set<URI> ts) {
67 this(statement.getSubject(), statement.getPredicate(), statement
68 .getObject(), statement.getContext(), ts);
69 }
70
71 public Iterator<URI> getTriplesetIterator() {
72 return tripleSets.iterator();
73 }
74
75 public boolean isMemberOf(URI uri) {
76 if (uri.stringValue().equals(ORDIConst.EXPLICIT_STATEMENT))
77 return tripleSets.contains(IMPLICIT_STATEMENT) == false;
78 return tripleSets.contains(uri);
79 }
80
81
82 public boolean equals(Object other) {
83 if (this == other) {
84 return true;
85 }
86 if (other instanceof Statement) {
87 Statement otherSt = (Statement) other;
88 return getObject().equals(otherSt.getObject())
89 && getSubject().equals(otherSt.getSubject())
90 && getContext().equals(otherSt.getContext());
91 }
92
93 return false;
94 }
95
96 public int hashCode() {
97 return 923521 * getContext().hashCode() + 961 * getSubject().hashCode()
98 + 31 * getPredicate().hashCode() + getObject().hashCode();
99 }
100 }