]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectStatementsImpl.java
Merge "Better emptying of trash bin"
[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
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;
24
25 final public class DirectStatementsImpl implements DirectStatements {
26
27     final ResourceSupport support;
28
29     final int             subject;
30
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)
72                 return true;
73         }
74         return false;
75     }
76
77     @Override
78     public boolean containsAll(Collection<?> arg0) {
79         throw new Error("Not supported");
80     }
81
82     @Override
83     public boolean isEmpty() {
84         throw new Error("Not supported");
85     }
86
87     @Override
88     public Iterator<Statement> iterator() {
89         return new Iterator<Statement>() {
90
91             int index = 0;
92
93             int max   = statements.size();
94
95             @Override
96             public boolean hasNext() {
97                 return index < max;
98             }
99
100             @Override
101             public Statement next() {
102                 return new DirectStatementImpl(support, subject, statements.getQuick(index++),
103                         statements.getQuick(index++));
104             }
105
106             @Override
107             public void remove() {
108                 throw new Error("Not supported");
109             }
110
111         };
112     }
113
114     @Override
115     public boolean remove(Object arg0) {
116         throw new Error("Not supported");
117     }
118
119     @Override
120     public boolean removeAll(Collection<?> arg0) {
121         throw new Error("Not supported");
122     }
123
124     @Override
125     public boolean retainAll(Collection<?> arg0) {
126         throw new Error("Not supported");
127     }
128
129     @Override
130     public int size() {
131         return statements.size() >> 1;
132     }
133
134     @Override
135     public Object[] toArray() {
136         throw new Error("Not supported");
137     }
138
139     @Override
140     public <T> T[] toArray(T[] arg0) {
141         throw new Error("Not supported");
142     }
143
144 }