1 package org.simantics.db.procore.cluster;
\r
3 import gnu.trove.set.hash.TIntHashSet;
\r
5 import org.simantics.db.exception.DatabaseException;
\r
6 import org.simantics.db.impl.ClusterI;
\r
7 import org.simantics.db.impl.ClusterSupport;
\r
8 import org.simantics.db.impl.ClusterTraitsBase;
\r
9 import org.simantics.db.impl.Modifier;
\r
10 import org.simantics.db.impl.TableSizeListener;
\r
12 public class CompleteTableSmall extends CompleteTable {
\r
13 public CompleteTableSmall(TableSizeListener sizeListener, int[] header, int headerBase) {
\r
14 super(sizeListener, header, headerBase);
\r
16 public CompleteTableSmall(TableSizeListener sizeListener, int[] header, int headerBase, int[] ints) {
\r
17 super(sizeListener, header, headerBase, ints);
\r
21 public <Context> boolean foreachPredicate(int setIndex,
\r
22 ClusterI.PredicateProcedure<Context> procedure,
\r
23 Context context, ClusterSupport support, Modifier modifier)
\r
24 throws DatabaseException {
\r
25 ForeachPredicate<Context> t = new ForeachPredicate<Context>(procedure, support, modifier);
\r
26 return foreachComplete(setIndex, t, context, null, null);
\r
30 public <Context> boolean foreachObject(int setIndex,
\r
31 ClusterI.ObjectProcedure<Context> procedure,
\r
32 Context context, ClusterSupport support, Modifier modifier,
\r
33 ClusterI.CompleteTypeEnum completeType)
\r
34 throws DatabaseException {
\r
35 ForeachObject<Context> t = new ForeachObject<Context>
\r
36 (procedure, support, modifier, completeType);
\r
37 return foreachComplete(setIndex, t, context, null, null);
\r
40 private static final class ForeachPredicate<Context>
\r
41 implements ClusterI.ObjectProcedure<Context> {
\r
42 private TIntHashSet completeTypes = new TIntHashSet();
\r
43 private ClusterI.PredicateProcedure<Context> procedure;
\r
44 public ForeachPredicate(ClusterI.PredicateProcedure<Context>
\r
45 procedure, ClusterSupport support, Modifier modifier) {
\r
46 this.procedure = procedure;
\r
49 public boolean execute(Context context, int completeRef) {
\r
50 ClusterI.CompleteTypeEnum completeType = ClusterTraitsSmall.completeRefAndTypeGetType(completeRef);
\r
51 if (!completeTypes.contains(completeType.getValue())) {
\r
52 completeTypes.add(completeType.getValue());
\r
54 int pKey = ClusterTraitsBase.getCompleteTypeResourceKeyFromEnum(completeType);
\r
55 if (procedure.execute(context, pKey, 0))
\r
56 return true; // loop broken by procedure
\r
57 } catch (DatabaseException e) {
\r
58 e.printStackTrace();
\r
62 return false; // Continue looping.
\r
66 private static class ForeachObject<Context>
\r
67 implements ClusterI.ObjectProcedure<Context> {
\r
68 private ClusterI.ObjectProcedure<Context> procedure;
\r
69 private Modifier modifier;
\r
70 private ClusterI.CompleteTypeEnum completeType;
\r
71 public ForeachObject(ClusterI.ObjectProcedure<Context>
\r
72 procedure, ClusterSupport support, Modifier modifier, ClusterI.CompleteTypeEnum completeType) {
\r
73 this.procedure = procedure;
\r
74 this.modifier = modifier;
\r
75 this.completeType = completeType;
\r
78 public boolean execute(Context context, int completeRef) throws DatabaseException {
\r
79 ClusterI.CompleteTypeEnum completeType2 = ClusterTraitsSmall.completeRefAndTypeGetType(completeRef);
\r
80 if (completeType == completeType2) { // same predicate
\r
81 int objectRef = ClusterTraitsSmall.completeRefAndTypeGetRef(completeRef);
\r
83 if (null == modifier)
\r
84 externalRef = objectRef;
\r
86 externalRef = modifier.execute(objectRef);
\r
87 return procedure.execute(context, externalRef);
\r
89 return false; // Continue looping.
\r