X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fcluster%2FValueTable.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fcluster%2FValueTable.java;h=5ddcca89305e1d1f72f800e12e3fc12995a886ad;hp=2a3d11dbc100f2ac4d8a38d2ae45ce0924abb380;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ValueTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ValueTable.java index 2a3d11dbc..5ddcca893 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ValueTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ValueTable.java @@ -1,117 +1,117 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.procore.cluster; - -import java.util.Map; -import java.util.TreeMap; - -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.ValidationException; -import org.simantics.db.impl.ClusterI.ObjectProcedure; -import org.simantics.db.impl.ClusterI.Procedure; -import org.simantics.db.impl.ClusterSupport; -import org.simantics.db.impl.Modifier; -import org.simantics.db.impl.Table; -import org.simantics.db.impl.TableFactory; -import org.simantics.db.impl.TableSizeListener; - -public final class ValueTable extends Table { - public ValueTable(TableSizeListener sizeListener, int[] header, int headerBase) { - super(TableFactory.getByteFactory(), sizeListener, header, headerBase); - } - public ValueTable(TableSizeListener sizeListener, int[] header, int headerBase, byte[] bytes) { - super(TableFactory.getByteFactory(), sizeListener, header, headerBase, bytes); - } - void getValue(int valueIndex, byte[] to, int start, int size) { - getCopy(valueIndex, to, start, size); - } - void getString(int valueIndex, char[] to, int start, int size) { - byte[] bs = (byte[])table; - start += valueIndex+offset+1; - for(int i=0;i valueMap = - new TreeMap(); - - private int VALUE_SIZE = 0; - private int VALUE_OFFSET = 0; - public void checkValueInit() - throws DatabaseException { - valueMap.clear(); - final int s = getTableSize(); - final int c = getTableCapacity(); - if (s < 0 || s > c) - throw new ValidationException("Illegal value table size=" + s + " cap=" + c); - VALUE_SIZE = s; - VALUE_OFFSET = getTableBase() - ValueTable.ZERO_SHIFT; - } - public void checkValue(int capacity, int index) - throws DatabaseException { - if (0 == capacity && 0 == index) - return; - if (capacity < 1) - throw new ValidationException("Illegal resource value capacity=" + capacity); - if (index < 1) - throw new ValidationException("Illegal resource value index=" + index); - if (VALUE_SIZE < capacity + index + VALUE_OFFSET) - throw new ValidationException("Illegal resource value c=" + capacity + - " i=" + index + " ts=" + VALUE_SIZE + " off=" + VALUE_OFFSET); - // Duplicate index is allowed because new index is created only if new size is greater than old. - Integer valueCap = valueMap.get(index); - if (null == valueCap) - valueMap.put(index, capacity); - else if (capacity > valueCap) - valueMap.put(index, capacity); - else - valueMap.put(index, valueCap); - } - public void checkValueFini() - throws DatabaseException { - int last = 0; - for (Map.Entry e : valueMap.entrySet()) { - int i = e.getKey(); - int c = e.getValue(); - int cur = VALUE_OFFSET + i; - if (last > cur) - throw new ValidationException("Index error with resource value c=" + c + - " i=" + i + " ts=" + VALUE_SIZE + " off=" + VALUE_OFFSET); - last = cur + c; - } - } - - @Override - public boolean foreach(int setIndex, Procedure procedure, Context context, ClusterSupport support, Modifier modifier) throws DatabaseException { - throw new UnsupportedOperationException(); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.procore.cluster; + +import java.util.Map; +import java.util.TreeMap; + +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ValidationException; +import org.simantics.db.impl.ClusterI.ObjectProcedure; +import org.simantics.db.impl.ClusterI.Procedure; +import org.simantics.db.impl.ClusterSupport; +import org.simantics.db.impl.Modifier; +import org.simantics.db.impl.Table; +import org.simantics.db.impl.TableFactory; +import org.simantics.db.impl.TableSizeListener; + +public final class ValueTable extends Table { + public ValueTable(TableSizeListener sizeListener, int[] header, int headerBase) { + super(TableFactory.getByteFactory(), sizeListener, header, headerBase); + } + public ValueTable(TableSizeListener sizeListener, int[] header, int headerBase, byte[] bytes) { + super(TableFactory.getByteFactory(), sizeListener, header, headerBase, bytes); + } + void getValue(int valueIndex, byte[] to, int start, int size) { + getCopy(valueIndex, to, start, size); + } + void getString(int valueIndex, char[] to, int start, int size) { + byte[] bs = (byte[])table; + start += valueIndex+offset+1; + for(int i=0;i valueMap = + new TreeMap(); + + private int VALUE_SIZE = 0; + private int VALUE_OFFSET = 0; + public void checkValueInit() + throws DatabaseException { + valueMap.clear(); + final int s = getTableSize(); + final int c = getTableCapacity(); + if (s < 0 || s > c) + throw new ValidationException("Illegal value table size=" + s + " cap=" + c); + VALUE_SIZE = s; + VALUE_OFFSET = getTableBase() - ValueTable.ZERO_SHIFT; + } + public void checkValue(int capacity, int index) + throws DatabaseException { + if (0 == capacity && 0 == index) + return; + if (capacity < 1) + throw new ValidationException("Illegal resource value capacity=" + capacity); + if (index < 1) + throw new ValidationException("Illegal resource value index=" + index); + if (VALUE_SIZE < capacity + index + VALUE_OFFSET) + throw new ValidationException("Illegal resource value c=" + capacity + + " i=" + index + " ts=" + VALUE_SIZE + " off=" + VALUE_OFFSET); + // Duplicate index is allowed because new index is created only if new size is greater than old. + Integer valueCap = valueMap.get(index); + if (null == valueCap) + valueMap.put(index, capacity); + else if (capacity > valueCap) + valueMap.put(index, capacity); + else + valueMap.put(index, valueCap); + } + public void checkValueFini() + throws DatabaseException { + int last = 0; + for (Map.Entry e : valueMap.entrySet()) { + int i = e.getKey(); + int c = e.getValue(); + int cur = VALUE_OFFSET + i; + if (last > cur) + throw new ValidationException("Index error with resource value c=" + c + + " i=" + i + " ts=" + VALUE_SIZE + " off=" + VALUE_OFFSET); + last = cur + c; + } + } + + @Override + public boolean foreach(int setIndex, Procedure procedure, Context context, ClusterSupport support, Modifier modifier) throws DatabaseException { + throw new UnsupportedOperationException(); + } + +}