]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectStatementsImpl.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / DirectStatementsImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package fi.vtt.simantics.procore.internal;
13
14 import gnu.trove.list.array.TIntArrayList;
15
16 import java.util.Collection;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.ListIterator;
20
21 import org.simantics.db.DirectStatements;
22 import org.simantics.db.Resource;
23 import org.simantics.db.Statement;
24 import org.simantics.db.impl.ResourceImpl;
25 import org.simantics.db.impl.support.ResourceSupport;
26
27 final public class DirectStatementsImpl implements DirectStatements {
28
29     final ResourceSupport support;
30     final int subject;
31     final TIntArrayList statements = new TIntArrayList();
32     
33     DirectStatementsImpl(ResourceSupport support, int subject) {
34         this.support = support;
35         this.subject = subject;
36     }
37     
38     void addStatement(int p, int o) {
39         statements.add(p);
40         statements.add(o);
41     }
42     
43     @Override
44     public Resource getSubject() {
45         return new ResourceImpl(support, subject);
46     }
47
48     @Override
49     public boolean add(Statement arg0) {
50         throw new Error("Not supported");
51     }
52
53     @Override
54     public boolean addAll(Collection<? extends Statement> arg0) {
55         throw new Error("Not supported");
56     }
57
58     @Override
59     public void clear() {
60         throw new Error("Not supported");
61     }
62
63     @Override
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) return true;
72         }
73         return false;
74     }
75
76     @Override
77     public boolean containsAll(Collection<?> arg0) {
78         throw new Error("Not supported");
79     }
80
81     @Override
82     public boolean isEmpty() {
83         throw new Error("Not supported");
84     }
85
86     @Override
87     public Iterator<Statement> iterator() {
88         return new Iterator<Statement>() {
89
90             int index = 0;
91             int max = statements.size();
92             
93             @Override
94             public boolean hasNext() {
95                 return index < max; 
96             }
97
98             @Override
99             public Statement next() {
100                 return new DirectStatementImpl(support, subject, statements.getQuick(index++), statements.getQuick(index++));
101             }
102
103             @Override
104             public void remove() {
105                 throw new Error("Not supported");
106             }
107             
108         };
109     }
110
111     @Override
112     public boolean remove(Object arg0) {
113         throw new Error("Not supported");
114     }
115
116     @Override
117     public boolean removeAll(Collection<?> arg0) {
118         throw new Error("Not supported");
119     }
120
121     @Override
122     public boolean retainAll(Collection<?> arg0) {
123         throw new Error("Not supported");
124     }
125
126     @Override
127     public int size() {
128         return statements.size() >> 1;
129     }
130
131     @Override
132     public Object[] toArray() {
133         throw new Error("Not supported");
134     }
135
136     @Override
137     public <T> T[] toArray(T[] arg0) {
138         throw new Error("Not supported");
139     }
140
141     @Override
142     public void add(int index, Statement element) {
143         throw new Error("Not supported");
144     }
145
146     @Override
147     public boolean addAll(int index, Collection<? extends Statement> c) {
148         throw new Error("Not supported");
149     }
150
151     @Override
152     public Statement get(int index_) {
153         int index = 2*index_;
154         return new DirectStatementImpl(support, subject, statements.getQuick(index), statements.getQuick(index+1));
155     }
156
157     @Override
158     public int indexOf(Object o) {
159         throw new Error("Not supported");
160     }
161
162     @Override
163     public int lastIndexOf(Object o) {
164         throw new Error("Not supported");
165     }
166
167     @Override
168     public ListIterator<Statement> listIterator() {
169         throw new Error("Not supported");
170     }
171
172     @Override
173     public ListIterator<Statement> listIterator(int index) {
174         throw new Error("Not supported");
175     }
176
177     @Override
178     public Statement remove(int index) {
179         throw new Error("Not supported");
180     }
181
182     @Override
183     public Statement set(int index, Statement element) {
184         throw new Error("Not supported");
185     }
186
187     @Override
188     public List<Statement> subList(int fromIndex, int toIndex) {
189         throw new Error("Not supported");
190     }
191     
192 }