--- /dev/null
+package org.simantics.db.procore.cluster;\r
+\r
+final class BitUtility {\r
+ static final long LongBits = 64;\r
+ static final int IntBits = 32;\r
+ static final short ShortBits = 16;\r
+ static final long ClearHighIntMask = (1L << IntBits) - 1;\r
+ static final long ClearLowIntMask = -1l ^ ClearHighIntMask;\r
+ static final long ClearHighShortMask = (1L << ShortBits) - 1;\r
+ static final long ClearLowShortMask = -1L ^ ClearHighShortMask;\r
+\r
+ static final int getHighInt(long longValue) {\r
+ return (int) (longValue >>> IntBits);\r
+ }\r
+\r
+ static final long setHighInt(long longValue, int highValue) {\r
+ longValue = (longValue & ClearHighIntMask) | (long) highValue << IntBits;\r
+ return longValue;\r
+ }\r
+\r
+ static final int getLowInt(long longValue) {\r
+ return (int) longValue;\r
+ }\r
+\r
+ static final long setLowInt(long longValue, int lowValue) {\r
+ longValue = (longValue & ClearLowIntMask) | lowValue;\r
+ return longValue;\r
+ }\r
+\r
+ static final long setLowAndHighInt(long longValue, int lowValue, int highValue) {\r
+ longValue = ((long) lowValue & ClearHighIntMask) | ((long) highValue << IntBits);\r
+ return longValue;\r
+ }\r
+\r
+ static final short getLowShort(long longValue) {\r
+ return (short)longValue;\r
+ }\r
+\r
+ static final long setLowShort(long longValue, short lowValue) {\r
+ longValue = (longValue & ClearLowShortMask) | (lowValue & ClearHighShortMask);\r
+ return longValue;\r
+ }\r
+\r
+ static final int getMiddle(final long longValue, final int skip, final int size) {\r
+ return (int)(longValue >>> skip) & (1<<size)-1;\r
+ }\r
+\r
+ static final long setMiddle(long longValue, final int skip, final int size, int value) {\r
+ long a1 = (1L<<size)-1;\r
+ long m1 = (a1 << skip);\r
+ long mask = -1L ^ m1;\r
+ long t1 = (value & a1) << skip;\r
+ long t2 = longValue & mask;\r
+ long t3 = t2 | t1;\r
+ return t3;\r
+ }\r
+\r
+}\r