]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/BitUtility.java
Fail safe import fixes made by Antti
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / BitUtility.java
1 package org.simantics.db.procore.cluster;
2
3 final class BitUtility {
4         static final long LongBits = 64;
5         static final int IntBits = 32;
6     static final short ShortBits = 16;
7     static final long ClearHighIntMask = (1L << IntBits) - 1;
8     static final long ClearLowIntMask = -1l ^ ClearHighIntMask;
9     static final long ClearHighShortMask = (1L << ShortBits) - 1;
10     static final long ClearLowShortMask  = -1L ^ ClearHighShortMask;
11
12     static final int getHighInt(long longValue) {
13         return (int) (longValue >>> IntBits);
14     }
15
16     static final long setHighInt(long longValue, int highValue) {
17         longValue = (longValue & ClearHighIntMask) | (long) highValue << IntBits;
18         return longValue;
19     }
20
21     static final int getLowInt(long longValue) {
22         return (int) longValue;
23     }
24
25     static final long setLowInt(long longValue, int lowValue) {
26         longValue = (longValue & ClearLowIntMask) | lowValue;
27         return longValue;
28     }
29
30     static final long setLowAndHighInt(long longValue, int lowValue, int highValue) {
31         longValue = ((long) lowValue & ClearHighIntMask) | ((long) highValue << IntBits);
32         return longValue;
33     }
34
35     static final short getLowShort(long longValue) {
36         return (short)longValue;
37     }
38
39     static final long setLowShort(long longValue, short lowValue) {
40         longValue = (longValue & ClearLowShortMask) | (lowValue & ClearHighShortMask);
41         return longValue;
42     }
43
44     static final int getMiddle(final long longValue, final int skip, final int size) {
45         return (int)(longValue >>> skip) & (1<<size)-1;
46     }
47
48     static final long setMiddle(long longValue, final int skip, final int size, int value) {
49         long a1 = (1L<<size)-1;
50         long m1 = (a1 << skip);
51         long mask = -1L ^ m1;
52         long t1 = (value & a1) << skip;
53         long t2 = longValue & mask;
54         long t3 = t2 | t1;
55         return t3;
56     }
57
58 }