import java.util.Iterator;
import java.util.Set;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.ResourceSet;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.ResourceImpl;
+import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.support.ResourceSupport;
protected static final int DEFAULT_CAPACITY = 3;
public static final int NO_DATA = -1;
+
+ private static final Object[] EMPTY_ARRAY = new Object[0];
- public IntSet() {
- support = null;
- data = null;
- sizeOrData = NO_DATA;
+ public static IntSet EMPTY = new IntSet();
+
+ private IntSet() {
+ support = null;
}
-
+
public IntSet(QuerySupport support) {
this.support = support.getSupport();
data = null;
@Override
public Object[] toArray() {
- throw new UnsupportedOperationException();
+ if(data != null) {
+ Object[] result = new Object[sizeOrData];
+ for(int i=0;i<sizeOrData;++i)
+ result[i] = new ResourceImpl(support, data[i]);
+ return result;
+ }
+ else if(sizeOrData == NO_DATA)
+ return EMPTY_ARRAY;
+ else
+ return new Object[] { new ResourceImpl(support, sizeOrData) };
}
@Override
}
}
}
+
+ public void forEach(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
+ if(data != null) {
+ for(int i=0;i<sizeOrData;++i)
+ procedure.execute(graph, data[i]);
+ }
+ else if(sizeOrData == NO_DATA) {
+ } else {
+ procedure.execute(graph, sizeOrData);
+ }
+ procedure.finished(graph);
+ }
}
\ No newline at end of file