jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1133301 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem: Constants.java PropertyType.java Val.java
Date Wed, 08 Jun 2011 09:23:32 GMT
Author: thomasm
Date: Wed Jun  8 09:23:31 2011
New Revision: 1133301

URL: http://svn.apache.org/viewvc?rev=1133301&view=rev
Log:
Value implementation (from jackrabbit-j3)

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/PropertyType.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Val.java

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java?rev=1133301&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
Wed Jun  8 09:23:31 2011
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+/**
+ * Constants used in this project.
+ */
+public class Constants {
+    public static final int VERSION_MAJOR = 3;
+    public static final int VERSION_MINOR = 0;
+    public static final int BUILD = 1000;
+
+    public static final String FULL_VERSION = VERSION_MAJOR + "." + VERSION_MINOR + "." +
BUILD;
+
+    public static final String DEFAULT_URL = "mem:";
+
+    public static final int MAX_STORE_RETRY = 3;
+
+    public static final int MAX_CHILD_COUNT = 200;
+
+    public static final int MEM_CACHE_PER_REPOSITORY = 16 * 1024 * 1024;
+    public static final int MEM_CACHE_PER_SESSION = 1024 * 1024;
+    public static final int MEM_MAP_ENTRY = 32;
+    public static final int MEM_EVENT = 64;
+    public static final int MEM_NODE_DATA = 48;
+    public static final int MEM_VAL_LONG =  32;
+    public static final int MEM_VAL_BINARY = 32;
+    public static final int MEM_VAL_STRING = 64;
+    public static final int MEM_VAL_OBJ = 16;
+    public static final int SIZE_EVENT_BUNDLE = 20 * 1024;
+
+    public static final int BUNDLE_MIN_COMPRESS = 3;
+    public static final int JOURNAL_LOAD_SIZE = 16;
+
+    public static final String LOG_UNCLOSED_SESSIONS = "logUnclosedSessions";
+    public static final boolean LOG_UNCLOSED_SESSIONS_DEFAULT = true;
+
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/PropertyType.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/PropertyType.java?rev=1133301&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/PropertyType.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/PropertyType.java
Wed Jun  8 09:23:31 2011
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+/**
+ * The property types.
+ */
+public class PropertyType {
+
+    public static final int UNDEFINED = 0, STRING = 1, BINARY = 2, LONG = 3, DOUBLE = 4,
DATE = 5, BOOLEAN = 6,
+            NAME = 7, PATH = 8, REFERENCE = 9, WEAKREFERENCE = 10, URI = 11, DECIMAL = 12;
+
+    private static final String[] NAMES = { "undefined", "String", "Binary", "Long", "Double",
"Date", "Boolean",
+            "Name", "Path", "Reference", "WeakReference", "URI", "Decimal" };
+
+    public static String nameFromValue(int type) {
+        return NAMES[type];
+    }
+
+    public static int valueFromName(String name) {
+        switch (name.length()) {
+        case 3:
+            if ("URI".equals(name)) {
+                return URI;
+            }
+            break;
+        case 4:
+            if ("Long".equals(name)) {
+                return LONG;
+            } else if ("Date".equals(name)) {
+                return DATE;
+            } else if ("Name".equals(name)) {
+                return NAME;
+            } else if ("Path".equals(name)) {
+                return PATH;
+            }
+            break;
+        case 6:
+            if ("String".equals(name)) {
+                return STRING;
+            } else if ("Double".equals(name)) {
+                    return DOUBLE;
+            } else if ("Binary".equals(name)) {
+                return BINARY;
+            }
+            break;
+        case 7:
+            if ("Boolean".equals(name)) {
+                return BOOLEAN;
+            } else if ("Decimal".equals(name)) {
+                return DECIMAL;
+            }
+            break;
+        case 9:
+            if ("Reference".equals(name)) {
+                return REFERENCE;
+            } else if ("undefined".equals(name)) {
+                return UNDEFINED;
+            }
+            break;
+        case 13:
+            if ("WeakReference".equals(name)) {
+                return WEAKREFERENCE;
+            }
+            break;
+        }
+        throw new IllegalArgumentException("unknown type: " + name);
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Val.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Val.java?rev=1133301&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Val.java (added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Val.java Wed
Jun  8 09:23:31 2011
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+/**
+ * A value.
+ */
+public class Val implements Comparable<Val> {
+
+    public static final Val TRUE = new Val(PropertyType.BOOLEAN, 0, true);
+    public static final Val FALSE = new Val(PropertyType.BOOLEAN, 0, false);
+
+    public static final int TYPE_MULTI_VALUE = 43;
+    public static final int TYPE_BINARY_REFERENCE = 44;
+
+    private static final int CACHE_SIZE = 1024;
+    private static final Val[] CACHE = new Val[CACHE_SIZE];
+
+    private static final String EMPTY_STRING = "";
+    private static final Val STRING_0 = new Val(PropertyType.STRING, 0, EMPTY_STRING);
+
+    private static final HashMap<Val, Integer> INDEX_MAP = new HashMap<Val, Integer>();
+
+    private static final Val[] INDEXED = new Val[128];
+
+    static {
+        // index 0 is not used
+        Val[] indexed = new Val[] {
+            Val.get(-1),
+            Val.get(0),
+            Val.get(1),
+            Val.get(2),
+            Val.get(3),
+            Val.get(4),
+            Val.get(5),
+            Val.get(6),
+            Val.get(7),
+            Val.get(0.0d),
+            Val.get(1.0d),
+            Val.get("http://www.jcp.org/jcr/1.0"),
+            Val.get("http://www.jcp.org/jcr/mix/1.0"),
+            Val.get("http://www.jcp.org/jcr/nt/1.0"),
+            Val.get("http://www.jcp.org/jcr/sv/1.0"),
+            Val.get("activity"),
+            Val.get("address"),
+            Val.get("autocreated"),
+            Val.get("base"),
+            Val.get("childNodeDefinition"),
+            Val.get("childVersionHistory"),
+            Val.get("configuration"),
+            Val.get("content"),
+            Val.get("copiedFrom"),
+            Val.get("created"),
+            Val.get("createdBy"),
+            Val.get("data"),
+            Val.get("defaultPrimaryType"),
+            Val.get("defaultValues"),
+            Val.get("description"),
+            Val.get("encoding"),
+            Val.get("etag"),
+            Val.get("file"),
+            Val.get("folder"),
+            Val.get("frozenMixinTypes"),
+            Val.get("frozenNode"),
+            Val.get("frozenPrimaryType"),
+            Val.get("frozenUuid"),
+            Val.get("hasOrderableChildNodes"),
+            Val.get("hierarchyNode"),
+            Val.get("host"),
+            Val.get("id"),
+            Val.get("internal"),
+            Val.get("isCheckedOut"),
+            Val.get("jcr"),
+            Val.get("key"),
+            Val.get("language"),
+            Val.get("lastModified"),
+            Val.get("lastModifiedBy"),
+            Val.get("lifecycle"),
+            Val.get("linkedFile"),
+            Val.get("mandatory"),
+            Val.get("mergeFailed"),
+            Val.get("message"),
+            Val.get("mimeType"),
+            Val.get("mixin"),
+            Val.get("mixinTypes"),
+            Val.get("multiple"),
+            Val.get("name"),
+            Val.get("nodeTypeName"),
+            Val.get("nt"),
+            Val.get("onParentVersion"),
+            Val.get("orderable"),
+            Val.get("path"),
+            Val.get("port"),
+            Val.get("predecessors"),
+            Val.get("primaryItemName"),
+            Val.get("primaryType"),
+            Val.get("propertyDefinition"),
+            Val.get("protected"),
+            Val.get("protocol"),
+            Val.get("query"),
+            Val.get("referenceable"),
+            Val.get("repository"),
+            Val.get("requiredPrimaryTypes"),
+            Val.get("requiredType"),
+            Val.get("resource"),
+            Val.get("resourceType"),
+            Val.get("root"),
+            Val.get("rootVersion"),
+            Val.get("sameNameSiblings"),
+            Val.get("share"),
+            Val.get("shareable"),
+            Val.get("simpleVersionable"),
+            Val.get("sling"),
+            Val.get("successors"),
+            Val.get("supertypes"),
+            Val.get("system"),
+            Val.get("text"),
+            Val.get("title"),
+            Val.get("type"),
+            Val.get("unfiled"),
+            Val.get("unstructured"),
+            Val.get("uuid"),
+            Val.get("valueConstraints"),
+            Val.get("version"),
+            Val.get("versionable"),
+            Val.get("versionableUuid"),
+            Val.get("versionedChild"),
+            Val.get("versionHistory"),
+            Val.get("versionLabels"),
+            Val.get("versionStorage"),
+            Val.get("workspace"),
+            Val.get("http://sling.apache.org/jcr/event/1.0"),
+            Val.get("http://sling.apache.org/jcr/sling/1.0"),
+            Val.get("http://www.day.com/crx/1.0"),
+            Val.get("http://www.day.com/crx/replication/1.0"),
+            Val.get("http://www.day.com/dam/1.0"),
+            Val.get("http://www.day.com/jcr/cq/1.0"),
+            Val.get("http://www.day.com/jcr/crxde/1.0"),
+            Val.get("http://www.day.com/jcr/vault/1.0"),
+            Val.get("http://www.day.com/jcr/wiki/1.0"),
+            Val.get("http://www.w3.org/2001/XMLSchema"),
+            Val.get("http://www.w3.org/2004/10/xpath-functions"),
+            Val.get("http://www.w3.org/2005/xpath-functions"),
+            Val.get("http://www.w3.org/XML/1998/namespace"),
+        };
+        int i = 0;
+        for (Val v : indexed) {
+            v.index = (byte) i;
+            INDEXED[i] = v;
+            INDEX_MAP.put(v, i);
+            i++;
+        }
+    }
+
+    private final short type;
+    private short index;
+    private final Object value;
+
+    private Val(int type, int index, Object value) {
+        this.type = (short) type;
+        this.index = (short) index;
+        this.value = value;
+    }
+
+    public static Val getIndexed(int index) {
+        return INDEXED[index];
+    }
+
+    private static Val cache(int type, Object value) {
+        Val v = new Val(type, 0, value);
+        Integer index = INDEX_MAP.get(v);
+        if (index != null) {
+            return INDEXED[index];
+        }
+        int hash = v.hashCode();
+        int cacheIndex = hash & (CACHE_SIZE - 1);
+        Val cached = CACHE[cacheIndex];
+        if (cached != null && v.equals(cached)) {
+            return cached;
+        }
+        CACHE[cacheIndex] = v;
+        return v;
+    }
+
+    public static Val get(Val... array) {
+        if (array == null) {
+            throw ExceptionFactory.nullPointer();
+        }
+        return new Val(TYPE_MULTI_VALUE, 0, array);
+    }
+
+    public static Val get(boolean x) {
+        return x ? TRUE : FALSE;
+    }
+
+    public static Val get(long x) {
+        return cache(PropertyType.LONG, Long.valueOf(x));
+    }
+
+    public static Val get(double x) {
+        return cache(PropertyType.DOUBLE, Double.valueOf(x));
+    }
+
+    public static Val get(byte[] x) {
+        return new Val(PropertyType.BINARY, 0, x);
+    }
+
+    public static Val get(String x) {
+        if (x.length() == 0) {
+            return STRING_0;
+        }
+        return cache(PropertyType.STRING, x);
+    }
+
+    public static Val get(int type, String x) {
+        if (x.length() == 0) {
+            x = EMPTY_STRING;
+        }
+        switch (type) {
+        case PropertyType.BOOLEAN:
+            return get(Boolean.parseBoolean(x));
+        case PropertyType.LONG:
+            return get(Long.decode(x));
+        case PropertyType.DOUBLE:
+            return get(Double.parseDouble(x));
+        case PropertyType.DECIMAL:
+        case PropertyType.DATE:
+        case PropertyType.NAME:
+        case PropertyType.PATH:
+        case PropertyType.REFERENCE:
+        case PropertyType.STRING:
+        case PropertyType.URI:
+        case PropertyType.WEAKREFERENCE:
+            return cache(type, x);
+        case TYPE_BINARY_REFERENCE:
+            return cache(TYPE_BINARY_REFERENCE, x);
+        }
+        throw ExceptionFactory.illegalArgument("type: {0}, value: {0}", type, x);
+    }
+
+    public int hashCode() {
+        switch (type) {
+        case PropertyType.BINARY:
+            return getType() ^ Arrays.hashCode(getBytes());
+        case TYPE_MULTI_VALUE:
+            return getType() ^ Arrays.hashCode(getArray());
+        }
+        return getType() ^ value.hashCode();
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) {
+            return true;
+        }
+        if (other instanceof Val) {
+            Val v = (Val) other;
+            if (v.type != type) {
+                return false;
+            }
+            switch (type) {
+            case PropertyType.BINARY:
+                return Arrays.equals(getBytes(), v.getBytes());
+            case TYPE_MULTI_VALUE:
+                return Arrays.equals(getArray(), v.getArray());
+            }
+            return v.value.equals(value);
+        }
+        return false;
+    }
+
+    public String toString() {
+        switch (type) {
+        case TYPE_MULTI_VALUE: {
+            StringBuilder buff = new StringBuilder("[ ");
+            int i = 0;
+            for (Val v : (Val[]) value) {
+                if (i++ > 0) {
+                    buff.append(", ");
+                }
+                // should in theory never be null (unless there is a bug)
+                if (v != null) {
+                    buff.append(v.toString());
+                }
+            }
+            return buff.append(" ]").toString();
+        }
+        case TYPE_BINARY_REFERENCE: {
+            return "/* binaryRef */ \"" + value + "\"";
+        }
+        case PropertyType.BOOLEAN:
+        case PropertyType.LONG:
+            return value.toString();
+        case PropertyType.DECIMAL:
+            return "/* " + PropertyType.nameFromValue(type) + " */ " + value.toString();
+        case PropertyType.DOUBLE:
+            String s = value.toString();
+            if (s.equals("NaN") || s.endsWith("Infinity")) {
+                s = "\"" + s + "\"";
+            }
+            return "/* " + PropertyType.nameFromValue(type) + " */ " + s;
+        case PropertyType.STRING:
+            return JsopTokenizer.encode(value.toString());
+        default:
+            return "/* " + PropertyType.nameFromValue(type) + " */ " + JsopTokenizer.encode(value.toString());
+        }
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public String getString() {
+        return value.toString();
+    }
+
+    public double getDouble() {
+        return (Double) value;
+    }
+
+    public boolean getBoolean() {
+        return (Boolean) value;
+    }
+
+    public byte[] getBytes() {
+        return (byte[]) value;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public Val[] getArray() {
+        return (Val[]) value;
+    }
+
+    public long getLong() {
+        return (Long) value;
+    }
+
+    public int getMemoryUsed() {
+        if (index != 0) {
+            return 0;
+        }
+        switch (type) {
+        case PropertyType.BINARY:
+            return Constants.MEM_VAL_BINARY + getBytes().length;
+        case PropertyType.LONG:
+        case PropertyType.DOUBLE:
+            return Constants.MEM_VAL_LONG;
+        case TYPE_MULTI_VALUE: {
+            int mem = Constants.MEM_VAL_LONG;
+            for (Val v : getArray()) {
+                mem += v.getMemoryUsed() + Constants.MEM_VAL_OBJ;
+            }
+            return mem;
+        }
+        }
+        return Constants.MEM_VAL_STRING + getString().length() * 2;
+    }
+
+    public int compareTo(Val o) {
+        if (this == o) {
+            return 0;
+        }
+        int result = compareInt(type, o.type);
+        if (result != 0) {
+            return result;
+        }
+        switch (type) {
+        case PropertyType.BINARY:
+            result = compareNotNull(getBytes(), o.getBytes());
+            break;
+        case PropertyType.LONG:
+            result = compareLong(getLong(), o.getLong());
+            break;
+        case PropertyType.DOUBLE:
+            result = Double.compare(getDouble(), o.getDouble());
+            break;
+        default:
+            result = getString().compareTo(o.getString());
+        }
+        return result;
+    }
+
+    public static int compareInt(int a, int b) {
+        return a == b ? 0 : a < b ? -1 : 1;
+    }
+
+    public static int compareLong(long a, long b) {
+        return a == b ? 0 : a < b ? -1 : 1;
+    }
+
+    public static int compareNotNull(byte[] data1, byte[] data2) {
+        int len = Math.min(data1.length, data2.length);
+        for (int i = 0; i < len; i++) {
+            byte b = data1[i];
+            byte b2 = data2[i];
+            if (b != b2) {
+                return b > b2 ? 1 : -1;
+            }
+        }
+        return Integer.signum(data1.length - data2.length);
+    }
+
+    public Val addUnordered(Val x) {
+        Val[] oldArray = getArray();
+        Val[] newArray = new Val[oldArray.length + 1];
+        System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
+        newArray[oldArray.length] = x;
+        return Val.get(newArray);
+    }
+
+    public Val removeUnordered(Val x) {
+        Val[] oldArray = getArray();
+        int pos;
+        for (pos = 0; pos < oldArray.length; pos++) {
+            if (oldArray[pos].equals(x)) {
+                break;
+            }
+        }
+        if (pos >= oldArray.length) {
+            return this;
+        }
+        Val[] newArray = new Val[oldArray.length - 1];
+        System.arraycopy(oldArray, 0, newArray, 0, pos);
+        System.arraycopy(oldArray, pos + 1, newArray, pos, oldArray.length - pos - 1);
+        return Val.get(newArray);
+    }
+
+    public Val addOrdered(Val x) {
+        // if this is a performance problem,
+        // use java.util.TreeMap<Val, Integer> where the value is the count
+        // or java.util.ArrayList<Val>
+        Val[] oldArray = getArray();
+        int pos = Arrays.binarySearch(oldArray, x);
+        if (pos < 0) {
+            pos = -1 - pos;
+        }
+        Val[] newArray = new Val[oldArray.length + 1];
+        System.arraycopy(oldArray, 0, newArray, 0, pos);
+        System.arraycopy(oldArray, pos, newArray, pos + 1, oldArray.length - pos);
+        newArray[pos] = x;
+        return Val.get(newArray);
+    }
+
+    public Val removeOrdered(Val x) {
+        Val[] oldArray = getArray();
+        int pos = Arrays.binarySearch(oldArray, x);
+        if (pos < 0) {
+            return this;
+        }
+        Val[] newArray = new Val[oldArray.length - 1];
+        System.arraycopy(oldArray, 0, newArray, 0, pos);
+        System.arraycopy(oldArray, pos + 1, newArray, pos, oldArray.length - pos - 1);
+        return Val.get(newArray);
+    }
+
+    public static int getWorkspaceId(long nodeId) {
+        if ((nodeId & 1) == 0) {
+            return 0;
+        } else if ((nodeId & 3) == 1) {
+            return (int) ((nodeId >> 2) & ((1 << 4) - 1));
+        } else if ((nodeId & 7) == 3) {
+            return (int) ((nodeId >> 3) & ((1 << 11) - 1));
+        } else if ((nodeId & 15) == 7) {
+            return (int) ((nodeId >> 4) & ((1 << 28) - 1));
+        } else {
+            throw ExceptionFactory.illegalArgument("Node {0}", nodeId);
+        }
+    }
+
+    public static long getBaseNodeId(long nodeId) {
+        if ((nodeId & 1) == 0) {
+            return nodeId >> 1;
+        } else if ((nodeId & 3) == 1) {
+            return nodeId >> 6;
+        } else if ((nodeId & 7) == 3) {
+            return nodeId >> 14;
+        } else if ((nodeId & 15) == 7) {
+            return nodeId >> 32;
+        } else {
+            throw ExceptionFactory.illegalArgument("Node {0}", nodeId);
+        }
+    }
+
+    public static long getNodeId(int workspaceId, long baseNodeId) {
+        if (workspaceId == 0) {
+            // ... nnnnnnnn nnnnnnn0
+            return baseNodeId << 1;
+        } else if ((workspaceId & ~((1 << 4) - 1)) == 0) {
+            // up to workspace #15
+            // ... nnnnnnnn nnwwww01
+            return (baseNodeId << 6) + (workspaceId << 2) + 1;
+        } else if ((workspaceId & ~((1 << 11) - 1)) == 0) {
+            // up to workspace #2047
+            // ... nnwwwwww wwwww011
+            return (baseNodeId << 14) + (workspaceId << 3) + 3;
+        } else if ((workspaceId & ~((1 << 28) - 1)) == 0) {
+            // up to workspace #268'435'455
+            // ... nnnnnnnn wwwwww ... wwww0111
+            return (baseNodeId << 32) + ((long) workspaceId << 4) + 7;
+        } else {
+            throw ExceptionFactory.illegalArgument("Workspace {0}", workspaceId);
+        }
+    }
+
+}



Mime
View raw message