-package org.simantics.db.service;\r
-\r
-import java.nio.ByteBuffer;\r
-import java.nio.ByteOrder;\r
-\r
-public final class ClusterUID {\r
- public static final ClusterUID Null = new ClusterUID(0, 0);\r
- public static final ClusterUID Reserved = new ClusterUID(0, 1);\r
- public static final ClusterUID Builtin = new ClusterUID(0, 2);\r
- public static boolean isLegal(ClusterUID clusterUID) {\r
- return !clusterUID.equals(Null) && !clusterUID.equals(Reserved);\r
- }\r
-// public final long first;\r
- public final long second;\r
-// public transient int arrayOffset = -1;\r
-\r
-// transient private static long firstCache1 = 0;\r
-// transient private static long firstCache2 = 0;\r
- transient private static long secondCache1 = 0;\r
- transient private static long secondCache2 = 0;\r
- transient private static ClusterUID clusterCache1 = null;\r
- transient private static ClusterUID clusterCache2 = null;\r
-\r
- public ClusterUID() {\r
-// first = 0;\r
- second = 0;\r
- }\r
-\r
- public ClusterUID(long first, long second) {\r
- assert(first == 0);\r
-// this.first = first;\r
- this.second = second;\r
- }\r
-\r
- public synchronized static ClusterUID make(long first, long second) {\r
-\r
- assert(first == 0);\r
-\r
- if(second == secondCache1) return clusterCache1;\r
- else if(second == secondCache2) return clusterCache2;\r
- else {\r
- ClusterUID result = new ClusterUID(first, second);\r
- secondCache2 = secondCache1; clusterCache2 = clusterCache1;\r
- secondCache1 = second; clusterCache1 = result;\r
- return result;\r
- }\r
-\r
- }\r
-\r
- public static ClusterUID make(byte[] bytes, int offset) {\r
- if (bytes.length < offset + 16)\r
- throw new IllegalArgumentException("Too few bytes for ClusteUID. length=" + bytes.length + " offset=" + offset);\r
- ByteBuffer bf = ByteBuffer.wrap(bytes, offset, 16);\r
- bf.order(ByteOrder.LITTLE_ENDIAN);\r
- return make(bf.getLong(),bf.getLong());\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return String.format("%x.%x", 0, second);\r
- }\r
- public static int getLongLength() {\r
- return 2;\r
- }\r
- public int toByte(byte[] bytes, int offset) {\r
- Bytes.writeLE(bytes, offset+0, 0);\r
- Bytes.writeLE(bytes, offset+8, second);\r
- return offset + 16;\r
- }\r
- public int toLong(long[] longs, int offset) {\r
- longs[offset++] = 0;\r
- longs[offset++] = second;\r
- return offset;\r
- }\r
- public byte[] asBytes() {\r
- byte[] bytes = new byte[16];\r
- toByte(bytes, 0);\r
- return bytes;\r
- }\r
- public ResourceUID toRID(int resourceIndex) {\r
- return new ResourceUID(0, second, resourceIndex);\r
- }\r
- @Override\r
- public boolean equals(Object o) {\r
- if (this == o)\r
- return true;\r
- else if (!(o instanceof ClusterUID))\r
- return false;\r
- ClusterUID x = (ClusterUID)o;\r
- return /*first == x.first &&*/ second == x.second;\r
- }\r
- @Override\r
- public int hashCode() {\r
- int result = 17;\r
-// int f = (int)(0 ^ (0 >>> 32));\r
-// result = 31 * result + f;\r
- int s = (int)(second ^ (second >>> 32));\r
- result = 31 * result + s;\r
- return result;\r
- }\r
-}\r
+package org.simantics.db.service;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public final class ClusterUID {
+ public static final ClusterUID Null = new ClusterUID(0, 0);
+ public static final ClusterUID Reserved = new ClusterUID(0, 1);
+ public static final ClusterUID Builtin = new ClusterUID(0, 2);
+ public static boolean isLegal(ClusterUID clusterUID) {
+ return !clusterUID.equals(Null) && !clusterUID.equals(Reserved);
+ }
+// public final long first;
+ public final long second;
+// public transient int arrayOffset = -1;
+
+// transient private static long firstCache1 = 0;
+// transient private static long firstCache2 = 0;
+ transient private static long secondCache1 = 0;
+ transient private static long secondCache2 = 0;
+ transient private static ClusterUID clusterCache1 = null;
+ transient private static ClusterUID clusterCache2 = null;
+
+ public ClusterUID() {
+// first = 0;
+ second = 0;
+ }
+
+ public ClusterUID(long first, long second) {
+ assert(first == 0);
+// this.first = first;
+ this.second = second;
+ }
+
+ public synchronized static ClusterUID make(long first, long second) {
+
+ assert(first == 0);
+
+ if(second == secondCache1) return clusterCache1;
+ else if(second == secondCache2) return clusterCache2;
+ else {
+ ClusterUID result = new ClusterUID(first, second);
+ secondCache2 = secondCache1; clusterCache2 = clusterCache1;
+ secondCache1 = second; clusterCache1 = result;
+ return result;
+ }
+
+ }
+
+ public static ClusterUID make(byte[] bytes, int offset) {
+ if (bytes.length < offset + 16)
+ throw new IllegalArgumentException("Too few bytes for ClusteUID. length=" + bytes.length + " offset=" + offset);
+ ByteBuffer bf = ByteBuffer.wrap(bytes, offset, 16);
+ bf.order(ByteOrder.LITTLE_ENDIAN);
+ return make(bf.getLong(),bf.getLong());
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%x.%x", 0, second);
+ }
+ public static int getLongLength() {
+ return 2;
+ }
+ public int toByte(byte[] bytes, int offset) {
+ Bytes.writeLE(bytes, offset+0, 0);
+ Bytes.writeLE(bytes, offset+8, second);
+ return offset + 16;
+ }
+ public int toLong(long[] longs, int offset) {
+ longs[offset++] = 0;
+ longs[offset++] = second;
+ return offset;
+ }
+ public byte[] asBytes() {
+ byte[] bytes = new byte[16];
+ toByte(bytes, 0);
+ return bytes;
+ }
+ public ResourceUID toRID(int resourceIndex) {
+ return new ResourceUID(0, second, resourceIndex);
+ }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ else if (!(o instanceof ClusterUID))
+ return false;
+ ClusterUID x = (ClusterUID)o;
+ return /*first == x.first &&*/ second == x.second;
+ }
+ @Override
+ public int hashCode() {
+ int result = 17;
+// int f = (int)(0 ^ (0 >>> 32));
+// result = 31 * result + f;
+ int s = (int)(second ^ (second >>> 32));
+ result = 31 * result + s;
+ return result;
+ }
+}