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%2FClusterTraits.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fcluster%2FClusterTraits.java;h=d787ef89bc95b9b80802f67c620be242fb7eec63;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterTraits.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterTraits.java new file mode 100644 index 000000000..d787ef89b --- /dev/null +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterTraits.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * 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 org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.ClusterI; +import org.simantics.db.impl.ClusterTraitsBase; + + +public final class ClusterTraits extends ClusterTraitsBase { + private static final int FOREIGN_INDEX_BITS = 16; + private static final int FOREIGN_INDEX_MAX = (1< FOREIGN_INDEX_MAX) + throw new DatabaseException("Illegal foreign index " + foreignIndex); + if (isIllegalResourceIndex(resourceIndex)) + throw new DatabaseException("Illegal resource index " + resourceIndex); + return (resourceIndex<>> NOTYPE_BITS; + } + public static final boolean isFlat(int reference) { + return reference < 0 && (reference & 0x40000000) != 0; + } + public static final boolean isLocal(int reference) { + return (reference & 0xC0000000) == 0; + } + public static final int getForeignIndexFromReference(int reference) + throws DatabaseException { + int foreignIndex = reference & 0x0000FFFF; + if (0 == foreignIndex) + throw new DatabaseException("Illegal foreign index " + foreignIndex); + return foreignIndex; + } + public static final int getResourceIndexFromForeignReference(int reference) + throws DatabaseException { + int resourceIndex = (reference & 0x7FFFFFFF) >> FOREIGN_INDEX_BITS; + if (isIllegalResourceIndex(resourceIndex)) + throw new DatabaseException("Illegal foreign reference " + reference); + return resourceIndex; + } + public static final boolean statementIndexIsDirect(int index) { + return (index & 0xC0000000) != 0x40000000; + } + public static final int statementIndexMake(int index) + throws DatabaseException { + assert(index > 0); + if ((index & 0xC0000000) != 0) + throw new DatabaseException("Illegal statement index " + index); + return index | 0x40000000; + } + public static final int statementIndexGet(int index) + throws DatabaseException { + if ((index & 0xC0000000) == 0x40000000) + return index & 0x3FFFFFFF; + else + return index; + } + public static boolean completeReferenceIsLocal(int completeRef) { + boolean complete = (completeRef & 0xC0000000) != 0; + return complete && ((completeRef & 0x0000FFFF) == 0); + } + public static boolean completeReferenceIsMultiple(int completeRef) { + boolean complete = (completeRef & 0xC0000000) != 0; + return !complete && (completeRef != 0); + } + public static int completeReferenceGetResourceIndex(int completeRef) { + int low = (completeRef & 0x3FFFFFFF) >>> CLUSTER_INDEX_BITS; + return low & 0x00003FFFF; + } + public static int completeReferenceGetForeignIndex(int completeRef) { + return completeRef & 0x0000FFFF; + } + public static ClusterI.CompleteTypeEnum completeReferenceGetType(int completeRef) { + return ClusterI.CompleteTypeEnum.make(completeRef >>> NOTYPE_BITS); + } + public static int completeReferenceMake(int type, int resourceIndex, int clusterIndex) { + assert(type < (1<