/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*******************************************************************************/
package org.simantics.db.impl.query;
-import gnu.trove.procedure.TIntProcedure;
-
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
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;
+import gnu.trove.procedure.TIntProcedure;
+
final public class IntSet implements ResourceSet {
protected static final int DEFAULT_CAPACITY = 3;
public static final int NO_DATA = -1;
+
+ private static final Object[] EMPTY_ARRAY = new Object[0];
+
+ public static IntSet EMPTY = new IntSet();
- public IntSet() {
+ private IntSet() {
support = null;
- data = null;
- sizeOrData = NO_DATA;
}
public IntSet(QuerySupport support) {
@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