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;
31 final TIntArrayList statements = new TIntArrayList();
33 DirectStatementsImpl(ResourceSupport support, int subject) {
34 this.support = support;
35 this.subject = subject;
38 void addStatement(int p, int o) {
44 public Resource getSubject() {
45 return new ResourceImpl(support, subject);
49 public boolean add(Statement arg0) {
50 throw new Error("Not supported");
54 public boolean addAll(Collection<? extends Statement> arg0) {
55 throw new Error("Not supported");
60 throw new Error("Not supported");
64 public boolean contains(Object arg0) {
65 Statement stm = (Statement) arg0;
66 ResourceImpl p = (ResourceImpl) stm.getPredicate();
67 ResourceImpl o = (ResourceImpl) stm.getObject();
68 for (int i = 0; i < statements.size(); i += 2) {
69 int pi = statements.getQuick(i);
70 int oi = statements.getQuick(i + 1);
71 if (p.id == pi && o.id == oi)
78 public boolean containsAll(Collection<?> arg0) {
79 throw new Error("Not supported");
83 public boolean isEmpty() {
84 throw new Error("Not supported");
88 public Iterator<Statement> iterator() {
89 return new Iterator<Statement>() {
93 int max = statements.size();
96 public boolean hasNext() {
101 public Statement next() {
102 return new DirectStatementImpl(support, subject, statements.getQuick(index++),
103 statements.getQuick(index++));
107 public void remove() {
108 throw new Error("Not supported");
115 public boolean remove(Object arg0) {
116 throw new Error("Not supported");
120 public boolean removeAll(Collection<?> arg0) {
121 throw new Error("Not supported");
125 public boolean retainAll(Collection<?> arg0) {
126 throw new Error("Not supported");
131 return statements.size() >> 1;
135 public Object[] toArray() {
136 throw new Error("Not supported");
140 public <T> T[] toArray(T[] arg0) {
141 throw new Error("Not supported");