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 fi.vtt.simantics.procore.internal;
14 import gnu.trove.list.array.TIntArrayList;
16 import java.util.Collection;
17 import java.util.Iterator;
19 import org.simantics.db.DirectStatements;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Statement;
22 import org.simantics.db.impl.ResourceImpl;
23 import org.simantics.db.impl.support.ResourceSupport;
25 final public class DirectStatementsImpl implements DirectStatements {
27 final ResourceSupport support;
29 final TIntArrayList statements = new TIntArrayList();
31 DirectStatementsImpl(ResourceSupport support, int subject) {
32 this.support = support;
33 this.subject = subject;
36 void addStatement(int p, int o) {
42 public Resource getSubject() {
43 return new ResourceImpl(support, subject);
47 public boolean add(Statement arg0) {
48 throw new Error("Not supported");
52 public boolean addAll(Collection<? extends Statement> arg0) {
53 throw new Error("Not supported");
58 throw new Error("Not supported");
62 public boolean contains(Object arg0) {
63 Statement stm = (Statement)arg0;
64 ResourceImpl p = (ResourceImpl)stm.getPredicate();
65 ResourceImpl o = (ResourceImpl)stm.getObject();
66 for(int i=0;i<statements.size();i+=2) {
67 int pi = statements.getQuick(i);
68 int oi = statements.getQuick(i+1);
69 if(p.id == pi && o.id == oi) return true;
75 public boolean containsAll(Collection<?> arg0) {
76 throw new Error("Not supported");
80 public boolean isEmpty() {
81 throw new Error("Not supported");
85 public Iterator<Statement> iterator() {
86 return new Iterator<Statement>() {
89 int max = statements.size();
92 public boolean hasNext() {
97 public Statement next() {
98 return new DirectStatementImpl(support, subject, statements.getQuick(index++), statements.getQuick(index++));
102 public void remove() {
103 throw new Error("Not supported");
110 public boolean remove(Object arg0) {
111 throw new Error("Not supported");
115 public boolean removeAll(Collection<?> arg0) {
116 throw new Error("Not supported");
120 public boolean retainAll(Collection<?> arg0) {
121 throw new Error("Not supported");
126 return statements.size() >> 1;
130 public Object[] toArray() {
131 throw new Error("Not supported");
135 public <T> T[] toArray(T[] arg0) {
136 throw new Error("Not supported");