]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterTraitsSmall.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / ClusterTraitsSmall.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.procore.cluster;\r
13 \r
14 import org.simantics.db.exception.DatabaseException;\r
15 import org.simantics.db.impl.ClusterI;\r
16 import org.simantics.db.impl.ClusterTraitsBase;\r
17 \r
18 \r
19 public final class ClusterTraitsSmall extends ClusterTraitsBase {\r
20     static final short FOREIGN_INDEX_BITS = 15;\r
21     static final short FOREIGN_INDEX_MAX = (1<<FOREIGN_INDEX_BITS)-1;\r
22     static final int VALUE_INDEX_BITS = 22;\r
23     static final int VALUE_INDEX_MAX = (1<<VALUE_INDEX_BITS)-1;\r
24     static final int VALUE_INDEX_EX = VALUE_INDEX_MAX; \r
25     static final int VALUE_SIZE_BITS = 15;\r
26     public static final int VALUE_SIZE_MAX = (1<<VALUE_SIZE_BITS)-1;\r
27     public static final short makeForeignRef(short foreignIndex) {\r
28         assert(foreignIndex <= FOREIGN_INDEX_MAX);\r
29         return (short)(foreignIndex | 1<<FOREIGN_INDEX_BITS);\r
30     }\r
31     public static short resourceRefGetForeignIndex(short resourceRef)\r
32     throws DatabaseException {\r
33         if (resourceRef >>> FOREIGN_INDEX_BITS == 0)\r
34             throw new DatabaseException("Local resource refence doesn't have foreing index. reference=" + resourceRef);\r
35         return (short)(resourceRef & FOREIGN_INDEX_MAX);\r
36     }\r
37     public static boolean resourceRefIsLocal(short resourceRef) {\r
38         return resourceRef > 0; \r
39     }\r
40     public static ClusterI.CompleteTypeEnum completeRefAndTypeGetType(int completeRefAndType) {\r
41         return ClusterI.CompleteTypeEnum.make((completeRefAndType >>> 16) & 0x3);\r
42     }\r
43     public static short completeRefAndTypeGetRef(int completeRefAndType) {\r
44         return (short)(completeRefAndType & (1<<16)-1);\r
45     }\r
46 }\r
47 \r