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