Use BitsLong, and retire Bits. Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/b2fb22c7 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/b2fb22c7 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/b2fb22c7
Branch: refs/heads/master Commit: b2fb22c711872fd1f8d3a8511e823f387c5a0d10 Parents: 17a4587 Author: Andy Seaborne <[email protected]> Authored: Sun Mar 13 17:04:21 2016 +0000 Committer: Andy Seaborne <[email protected]> Committed: Sun Mar 13 17:04:21 2016 +0000 ---------------------------------------------------------------------- .../java/org/apache/jena/shared/uuid/Bits.java | 259 ----------- .../org/apache/jena/shared/uuid/JenaUUID.java | 21 +- .../org/apache/jena/shared/uuid/UUID_V1.java | 12 +- .../apache/jena/shared/uuid/UUID_V1_Gen.java | 19 +- .../apache/jena/shared/uuid/UUID_V4_Gen.java | 18 +- .../org/apache/jena/shared/uuid/TestBits.java | 457 ------------------- .../apache/jena/shared/uuid/UUIDTestSuite.java | 1 - 7 files changed, 38 insertions(+), 749 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/main/java/org/apache/jena/shared/uuid/Bits.java ---------------------------------------------------------------------- diff --git a/jena-core/src/main/java/org/apache/jena/shared/uuid/Bits.java b/jena-core/src/main/java/org/apache/jena/shared/uuid/Bits.java deleted file mode 100644 index 2af89f6..0000000 --- a/jena-core/src/main/java/org/apache/jena/shared/uuid/Bits.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * 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.jena.shared.uuid; - -// NB shifting is "mod 64" -- <<64 is a no-op (not a clear). -// http://mindprod.com/jgloss/masking.html - -/** Utilities for manipulating a bit pattern which held in a 64 bit long - * (java.util.BitSet does not allow getting the pattern as a long) - */ -public final class Bits -{ - // When this is false, no calls to check() should be generated and the - // JIT can inline these class statics. - // Methods like XXX$ do no checking. - public static final boolean CHECK = false ; - private static int LongLen = 64 ; // Long.SIZE - java 5 and later - - /** Extract the value packed into bits start (inclusive) and finish (exclusive), - * the value is returned the low part of the returned long. - * The low bit is bit zero. - */ - - public static final - long unpack(long bits, int start, int finish) - { - if ( CHECK ) check(start, finish) ; - if ( finish == 0 ) return 0 ; - // Remove top bits by moving up. Clear bottom bits by them moving down. - return (bits<<(LongLen-finish)) >>> ((LongLen-finish)+start) ; - } - - /** Place the value into the bit pattern between start and finish; - * leaves other bits along. - */ - public static final - long pack(long bits, long value, int start, int finish) - { - if ( CHECK ) check(start, finish) ; - bits = clear$(bits, start, finish) ; - bits = bits | (value<<start) ; - return bits ; - } - - /** Get bits from a hex string. - * - * @param str - * @param startChar Index of first character (counted from the left, string style). - * @param finishChar Index after the last character (counted from the left, string style). - * @return long - */ - - public static final - long unpack(String str, int startChar, int finishChar) - { - String s = str.substring(startChar, finishChar) ; - return Long.parseLong(s, 16) ; - } - - /** Set the bits specificied. - * - * @param bits Pattern - * @param bitIndex - * @return Modified pattern - */ - public static final - long set(long bits, int bitIndex) - { - if ( CHECK ) check(bitIndex) ; - return set$(bits, bitIndex) ; - } - - /** Set the bits from string (inc) to finish (exc) to one - * - * @param bits Pattern - * @param start start (inclusive) - * @param finish finish (exclusive) - * @return Modified pattern - */ - public static final - long set(long bits, int start, int finish) - { - if ( CHECK ) check(start, finish) ; - return set$(bits, start, finish) ; - } - - public static final - boolean test(long bits, boolean isSet, int bitIndex) - { - if ( CHECK ) check(bitIndex) ; - return test$(bits, isSet, bitIndex) ; - } - - public static final - boolean test(long bits, long value, int start, int finish) - { - if ( CHECK ) check(start, finish) ; - return test$(bits, value, start, finish) ; - } - - /** Get the bits from start (inclusive) to finish (exclusive), - * leaving them aligned in the long. See alio unpack, returns - * the value found at that place. - */ - - public static final - long access(long bits, int start, int finish) - { - if ( CHECK ) check(start, finish) ; - return access$(bits, start, finish) ; - } - - public static final - long clear(long bits, int start, int finish) - { - if ( CHECK ) check(start, finish) ; - return clear$(bits, start, finish) ; - } - - /** - * Create a mask that has ones between bit positions start (inc) and finish (exc) - */ - public static final - long mask(int start, int finish) - { - if ( CHECK ) check(start, finish) ; - return mask$(start, finish) ; - } - - /** - * Create a mask that has zeros between bit positions start (inc) and finish (exc) - * and ones elsewhere - */ - public static final - long maskZero(int start, int finish) - { - if ( CHECK ) check(start, finish) ; - return maskZero$(start, finish) ; - } - - private static final - long clear$(long bits, int start, int finish) - { - long mask = maskZero$(start, finish) ; - bits = bits & mask ; - return bits ; - } - - private static final - long set$(long bits, int bitIndex) - { - long mask = mask$(bitIndex) ; - return bits | mask ; - } - - private static final - long set$(long bits, int start, int finish) - { - long mask = mask$(start, finish) ; - return bits | mask ; - } - - private static - boolean test$(long bits, boolean isSet, int bitIndex) - { - return isSet == access$(bits, bitIndex) ; - } - - private static - boolean test$(long bits, long value, int start, int finish) - { - long v = access$(bits, start, finish) ; - return v == value ; - } - - - - private static final - boolean access$(long bits, int bitIndex) - { - long mask = mask$(bitIndex) ; - return (bits & mask) != 0L ; - } - - private static final - long access$(long bits, int start, int finish) - { - // Two ways: -// long mask = mask$(start, finish) ; -// return bits & mask ; - - return ( (bits<<(LongLen-finish)) >>> (LongLen-finish+start) ) << start ; - } - - - private static final - long mask$(int bitIndex) - { - return 1L << bitIndex ; - } - - private static final - long mask$(int start, int finish) - { - // long mask = 0 ; - // if ( finish == Long.SIZE ) - // // <<Long.SIZE is a no-op - // mask = -1 ; - // else - // mask = (1L<<finish)-1 ; - if ( finish == 0 ) - // So start is zero and so the mask is zero. - return 0 ; - - - long mask = -1 ; -// mask = mask << (LongLen-finish) >>> (LongLen-finish) ; // Clear the top bits -// return mask >>> start << start ; // Clear the bottom bits - return mask << (LongLen-finish) >>> (LongLen-finish+start) << start ; - } - - private static final - long maskZero$(int start, int finish) - { - - return ~mask$(start, finish) ; - } - - private static final - void check(long bitIndex) - { - if ( bitIndex < 0 || bitIndex >= LongLen ) throw new IllegalArgumentException("Illegal bit index: "+bitIndex) ; - } - - private static final - void check(long start, long finish) - { - if ( start < 0 || start >= LongLen ) throw new IllegalArgumentException("Illegal start: "+start) ; - if ( finish < 0 || finish > LongLen ) throw new IllegalArgumentException("Illegal finish: "+finish) ; - if ( start > finish ) throw new IllegalArgumentException("Illegal range: ("+start+", "+finish+")") ; - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/main/java/org/apache/jena/shared/uuid/JenaUUID.java ---------------------------------------------------------------------- diff --git a/jena-core/src/main/java/org/apache/jena/shared/uuid/JenaUUID.java b/jena-core/src/main/java/org/apache/jena/shared/uuid/JenaUUID.java index f1d81f8..9bab863 100644 --- a/jena-core/src/main/java/org/apache/jena/shared/uuid/JenaUUID.java +++ b/jena-core/src/main/java/org/apache/jena/shared/uuid/JenaUUID.java @@ -25,6 +25,7 @@ package org.apache.jena.shared.uuid ; import java.util.Locale ; import java.util.UUID ; +import org.apache.jena.atlas.lib.BitsLong ; import org.slf4j.Logger ; import org.slf4j.LoggerFactory ; @@ -56,12 +57,12 @@ public abstract class JenaUUID protected int _getVersion(long mostSigBits, long leastSigBits) { // int variant = (int)((UUID_V1_Gen.maskVariant & leastSigBits)>>>62) ; // int version = (int)((UUID_V1_Gen.maskVersion & mostSigBits)>>>12) ; - int version = (int)Bits.unpack(mostSigBits, 12, 16) ; + int version = (int)BitsLong.unpack(mostSigBits, 12, 16) ; return version ; } protected int _getVariant(long mostSigBits, long leastSigBits) { - int variant = (int)Bits.unpack(leastSigBits, 62, 64) ; + int variant = (int)BitsLong.unpack(leastSigBits, 62, 64) ; return variant ; } @@ -94,7 +95,7 @@ public abstract class JenaUUID // Time low - which includes the incremental count. @Override - public int hashCode() { return (int) Bits.unpack(getMostSignificantBits(), 32, 64) ; } + public int hashCode() { return (int) BitsLong.unpack(getMostSignificantBits(), 32, 64) ; } @Override public boolean equals(Object other) @@ -170,9 +171,9 @@ public abstract class JenaUUID // ^ ^ ^ ^ ^ // Byte: 0 4 6 8 10 // Char: 0 9 14 19 24 including hyphens - int x = (int)Bits.unpack(s, 19, 23) ; + int x = (int)BitsLong.unpack(s, 19, 23) ; int variant = (x >>> 14) ; - int version = (int)Bits.unpack(s, 14, 15) ; + int version = (int)BitsLong.unpack(s, 14, 15) ; if ( variant == Var_Std ) { switch (version) { @@ -214,15 +215,15 @@ public abstract class JenaUUID /** Format using two longs - assumed valid for an UUID of some kind */ public static String toString(long mostSignificantBits, long leastSignificantBits) { StringBuffer sb = new StringBuffer(36) ; - JenaUUID.toHex(sb, Bits.unpack(mostSignificantBits, 32, 64), 4) ; + JenaUUID.toHex(sb, BitsLong.unpack(mostSignificantBits, 32, 64), 4) ; sb.append('-') ; - JenaUUID.toHex(sb, Bits.unpack(mostSignificantBits, 16, 32), 2) ; + JenaUUID.toHex(sb, BitsLong.unpack(mostSignificantBits, 16, 32), 2) ; sb.append('-') ; - JenaUUID.toHex(sb, Bits.unpack(mostSignificantBits, 0, 16), 2) ; + JenaUUID.toHex(sb, BitsLong.unpack(mostSignificantBits, 0, 16), 2) ; sb.append('-') ; - JenaUUID.toHex(sb, Bits.unpack(leastSignificantBits, 48, 64), 2) ; + JenaUUID.toHex(sb, BitsLong.unpack(leastSignificantBits, 48, 64), 2) ; sb.append('-') ; - JenaUUID.toHex(sb, Bits.unpack(leastSignificantBits, 0, 48), 6) ; + JenaUUID.toHex(sb, BitsLong.unpack(leastSignificantBits, 0, 48), 6) ; return sb.toString() ; } http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1.java ---------------------------------------------------------------------- diff --git a/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1.java b/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1.java index 147388a..e341314 100644 --- a/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1.java +++ b/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1.java @@ -18,6 +18,8 @@ package org.apache.jena.shared.uuid; +import org.apache.jena.atlas.lib.BitsLong ; + /* Version 1: 60 bits of time @@ -95,9 +97,9 @@ public class UUID_V1 extends JenaUUID // Accessors - long getTimeHigh() { return Bits.unpack(bitsMostSignificant, 0, 12) ; } // ( uuid.bitsUpper & UUID_V1_Gen.maskTimeHigh ) ; - long getTimeMid() { return Bits.unpack(bitsMostSignificant, 16, 32) ; } // ( uuid.bitsUpper & UUID_V1_Gen.maskTimeMid ) >>> 16 ; - long getTimeLow() { return Bits.unpack(bitsMostSignificant, 32, 64) ; } // ( uuid.bitsUpper & UUID_V1_Gen.maskTimeLow ) >>> 32; + long getTimeHigh() { return BitsLong.unpack(bitsMostSignificant, 0, 12) ; } // ( uuid.bitsUpper & UUID_V1_Gen.maskTimeHigh ) ; + long getTimeMid() { return BitsLong.unpack(bitsMostSignificant, 16, 32) ; } // ( uuid.bitsUpper & UUID_V1_Gen.maskTimeMid ) >>> 16 ; + long getTimeLow() { return BitsLong.unpack(bitsMostSignificant, 32, 64) ; } // ( uuid.bitsUpper & UUID_V1_Gen.maskTimeLow ) >>> 32; public long getTimestamp() { @@ -106,9 +108,9 @@ public class UUID_V1 extends JenaUUID public long getClockSequence() { - return Bits.unpack(bitsLeastSignificant, 48, 62) ; + return BitsLong.unpack(bitsLeastSignificant, 48, 62) ; } - public long getNode() { return Bits.unpack(bitsLeastSignificant, 0, 48) ; } + public long getNode() { return BitsLong.unpack(bitsLeastSignificant, 0, 48) ; } @Override public int getVersion() { return super._getVersion(bitsMostSignificant, bitsLeastSignificant) ; } http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1_Gen.java ---------------------------------------------------------------------- diff --git a/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1_Gen.java b/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1_Gen.java index f1067e4..03c526c 100644 --- a/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1_Gen.java +++ b/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V1_Gen.java @@ -22,6 +22,7 @@ import java.net.NetworkInterface ; import java.util.Enumeration ; import java.util.Locale ; +import org.apache.jena.atlas.lib.BitsLong ; import org.apache.jena.shared.uuid.JenaUUID.UUIDFormatException ; /* RFC 4122 "A Universally Unique IDentifier (UUID) URN Namespace" @@ -177,16 +178,16 @@ public class UUID_V1_Gen implements UUIDFactory // ^ ^ ^ ^ ^ // Byte: 0 4 6 8 10 // Char: 0 9 14 19 24 including hyphens - int x = (int)Bits.unpack(s, 19, 23) ; + int x = (int)BitsLong.unpack(s, 19, 23) ; int variant = (x >>> 14) ; int clockSeq = x & 0x3FFF ; - long timeHigh = Bits.unpack(s, 15, 18) ; - long timeMid = Bits.unpack(s, 9, 13) ; - long timeLow = Bits.unpack(s, 0, 8) ; + long timeHigh = BitsLong.unpack(s, 15, 18) ; + long timeMid = BitsLong.unpack(s, 9, 13) ; + long timeLow = BitsLong.unpack(s, 0, 8) ; - long node = Bits.unpack(s, 24, 36) ; - int version = (int)Bits.unpack(s, 14, 15) ; + long node = BitsLong.unpack(s, 24, 36) ; + int version = (int)BitsLong.unpack(s, 14, 15) ; return generate(version, variant, timeHigh, timeMid, timeLow, clockSeq, node) ; } @@ -275,7 +276,7 @@ public class UUID_V1_Gen implements UUIDFactory long random = LibUUID.makeRandom().nextLong() ; clockSeq = 0 ; if ( CLOCK_BITS != 0 ) - clockSeq = (int)Bits.unpack(random, 48, (48 + CLOCK_BITS)) ; + clockSeq = (int)BitsLong.unpack(random, 48, (48 + CLOCK_BITS)) ; // Get the MAC address of an interface. // The loopback I/F does not have a MAC address. @@ -302,8 +303,8 @@ public class UUID_V1_Gen implements UUIDFactory - node = Bits.unpack(random, 0, 47) ; // Low 48bits, except groups address bit - node = Bits.set(node, 47) ; // Set group address bit + node = BitsLong.unpack(random, 0, 47) ; // Low 48bits, except groups address bit + node = BitsLong.set(node, 47) ; // Set group address bit // Can also set the clock sequence number to increase the randomness. // Use up to 13 bits for the clock (actually, it's 14 bits as http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V4_Gen.java ---------------------------------------------------------------------- diff --git a/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V4_Gen.java b/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V4_Gen.java index e2721eb..5e7d8dc 100644 --- a/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V4_Gen.java +++ b/jena-core/src/main/java/org/apache/jena/shared/uuid/UUID_V4_Gen.java @@ -18,8 +18,10 @@ package org.apache.jena.shared.uuid; -import java.util.* ; +import java.util.Locale ; +import java.util.Random ; +import org.apache.jena.atlas.lib.BitsLong ; import org.apache.jena.shared.uuid.JenaUUID.UUIDFormatException ; @@ -45,8 +47,8 @@ public class UUID_V4_Gen implements UUIDFactory init() ; long mostSigBits = random.nextLong() ; long leastSigBits = random.nextLong() ; - mostSigBits = Bits.pack(mostSigBits, versionHere, 12, 16) ; - leastSigBits = Bits.pack(leastSigBits, variantHere, 62, 64) ; + mostSigBits = BitsLong.pack(mostSigBits, versionHere, 12, 16) ; + leastSigBits = BitsLong.pack(leastSigBits, variantHere, 62, 64) ; return new UUID_V4(mostSigBits, leastSigBits) ; } @@ -80,14 +82,14 @@ public class UUID_V4_Gen implements UUIDFactory // ^ ^ ^ ^ ^ // Byte: 0 4 6 8 10 // Char: 0 9 14 19 24 including hyphens - long mostSigBits = Bits.unpack(s, 0, 8) ; + long mostSigBits = BitsLong.unpack(s, 0, 8) ; // Skip - - mostSigBits = mostSigBits << 16 | Bits.unpack(s, 9, 13) ; + mostSigBits = mostSigBits << 16 | BitsLong.unpack(s, 9, 13) ; // Skip - - mostSigBits = mostSigBits << 16 | Bits.unpack(s, 14, 18) ; + mostSigBits = mostSigBits << 16 | BitsLong.unpack(s, 14, 18) ; - long leastSigBits = Bits.unpack(s, 19, 23) ; - leastSigBits = leastSigBits<<48 | Bits.unpack(s, 24, 36) ; + long leastSigBits = BitsLong.unpack(s, 19, 23) ; + leastSigBits = leastSigBits<<48 | BitsLong.unpack(s, 24, 36) ; return new UUID_V4(mostSigBits, leastSigBits) ; } http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/test/java/org/apache/jena/shared/uuid/TestBits.java ---------------------------------------------------------------------- diff --git a/jena-core/src/test/java/org/apache/jena/shared/uuid/TestBits.java b/jena-core/src/test/java/org/apache/jena/shared/uuid/TestBits.java deleted file mode 100644 index 2925669..0000000 --- a/jena-core/src/test/java/org/apache/jena/shared/uuid/TestBits.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * 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.jena.shared.uuid; - -import junit.framework.TestCase; -import org.apache.jena.shared.uuid.Bits ; - -public class TestBits extends TestCase -{ - public void testMask1() - { - long v = Bits.mask(0,1) ; - check(0x1L, v) ; - } - - public void testMask2() - { - long v = Bits.mask(0,2) ; - check(0x3L, v) ; - } - - public void testMask3() - { - long v = Bits.mask(1,2) ; - check(0x2L, v) ; - } - - public void testMask4() - { - long v = Bits.mask(0,64) ; - check(-1L, v) ; - } - - public void testMask5() - { - long v = Bits.mask(16,48) ; - check(0x0000FFFFFFFF0000L, v) ; - } - - public void testMask6() - { - long v = Bits.mask(16,64) ; - check(0xFFFFFFFFFFFF0000L, v) ; - } - - public void testMask7() - { - long v = Bits.mask(0, 0) ; - check(0L, v) ; - } - - public void testMaskZero1() - { - long v = Bits.maskZero(0,1) ; - check(~0x1L, v) ; - } - - public void testMaskZero2() - { - long v = Bits.maskZero(0,2) ; - check(~0x3L, v) ; - } - - public void testMaskZero3() - { - long v = Bits.maskZero(1,2) ; - check(0xFFFFFFFFFFFFFFFDL, v) ; - } - - public void testMaskZero4() - { - long v = Bits.maskZero(0,64) ; - check(0, v) ; - } - - public void testMaskZero5() - { - long v = Bits.maskZero(16,48) ; - check(0xFFFF00000000FFFFL, v) ; - } - - public void testMaskZero6() - { - long v = Bits.maskZero(16,64) ; - check(0xFFFFL, v) ; - } - - public void testMaskZero7() - { - long v = Bits.maskZero(0, 0) ; - check(-1L, v) ; - } - - public void testClear1() - { - long v = 0xF0F0 ; - v = Bits.clear(v, 4, 8) ; - String s = Long.toHexString(v) ; - check(0xF000L, v ) ; - } - - public void testClear2() - { - long v = 0x8000000000000000L; - v = Bits.clear(v, 63, 64) ; - String s = Long.toHexString(v) ; - check(0x0L, v ) ; - } - - public void testClear3() - { - long v = 0xC000000000000000L; - v = Bits.clear(v, 63, 64) ; - String s = Long.toHexString(v) ; - check(0x4000000000000000L, v ) ; - } - - public void testClear4() - { - long v = -1 ; - v = Bits.clear(v, 63, 64) ; - String s = Long.toHexString(v) ; - check(0x7FFFFFFFFFFFFFFFL, v ) ; - } - - public void testClear5() - { - long v = -1 ; - v = Bits.clear(v, 32, 64) ; - String s = Long.toHexString(v) ; - check(0x00000000FFFFFFFFL, v ) ; - } - - public void testClear6() - { - long v = -1 ; - v = Bits.clear(v, 0, 32) ; - String s = Long.toHexString(v) ; - check(0xFFFFFFFF00000000L, v ) ; - } - - public void testClear7() - { - long v = -1L ; - v = Bits.clear(v, 0, 0) ; - String s = Long.toHexString(v) ; - check(-1L, v ) ; - } - - public void testSet1() - { - long v = 0x0 ; - v = Bits.set(v, 0, 1) ; - check(1, v) ; - } - - public void testSet2() - { - long v = 0x1 ; - v = Bits.set(v, 0, 1) ; - check(1, v) ; - } - - public void testSet3() - { - long v = 0xF0 ; - v = Bits.set(v, 0, 1) ; - check(0xF1, v) ; - } - - public void testSet4() - { - long v = 0xF0F0F0F0F0F0F0F0L ; - v = Bits.set(v, 0, 8) ; - check(0xF0F0F0F0F0F0F0FFL, v) ; - } - - public void testSet5() - { - long v = 0 ; - v = Bits.set(v, 16, 48) ; - check(0x0000FFFFFFFF0000L, v) ; - } - - public void testSet6() - { - long v = 0 ; - v = Bits.set(v, 63, 64) ; - check(0x8000000000000000L, v) ; - } - - public void testSet7() - { - long v = 0 ; - v = Bits.set(v, 62, 64) ; - check(0xC000000000000000L, v) ; - } - - public void testSet8() - { - long v = 0 ; - v = Bits.set(v, 0, 64) ; - check(-1L, v) ; - } - - public void testSet9() - { - long v = 0 ; - v = Bits.set(v, 10, 10) ; - check(0, v) ; - } - - public void testSetBit1() - { - long v = 0 ; - v = Bits.set(v, 0) ; - check(1, v) ; - } - - public void testSetBit2() - { - long v = 0 ; - v = Bits.set(v, 1) ; - check(2, v) ; - } - - public void testSetBit3() - { - long v = 1 ; - v = Bits.set(v, 0) ; - check(1, v) ; - } - - public void testSetBit4() - { - long v = -1 ; - v = Bits.set(v, 0) ; - check(-1, v) ; - } - - public void testSetBit5() - { - long v = 0 ; - v = Bits.set(v, 62) ; - check(0x4000000000000000L, v) ; - } - - public void testSetBit6() - { - long v = 0 ; - v = Bits.set(v, 63) ; - check(0x8000000000000000L, v) ; - } - - public void testBitTest1() - { - long v = 0 ; - assertTrue(Bits.test(v, false, 0)) ; - } - - public void testBitTest2() - { - long v = 1 ; - assertTrue(Bits.test(v, true, 0)) ; - } - - public void testBitTest3() - { - long v = -1 ; - assertTrue(Bits.test(v, true, 63)) ; - } - - public void testBitTest4() - { - long v = 0x7FFFFFFFFFFFFFFFL ; - assertTrue(Bits.test(v, false, 63)) ; - } - - public void testBitsTest1() - { - long v = 0xFEDCBA9876543210L ; - assertTrue(Bits.test(v, 0x0, 0, 4)) ; - } - - public void testBitsTest2() - { - long v = 0xFEDCBA9876543210L ; - assertTrue(Bits.test(v, 0x10, 0, 8)) ; - } - - public void testBitsTest3() - { - long v = 0xFEDCBA9876543210L ; - assertTrue(Bits.test(v, v, 0, 64)) ; - } - - public void testBitsTest4() - { - long v = 0xFEDCBA9876543210L ; - assertFalse(Bits.test(v, 0, 0, 64)) ; - } - - public void testBitsTest5() - { - long v = 0xFEDCBA9876543210L ; - assertTrue(Bits.test(v, 0x0000BA9876540000L, 16, 48)) ; - } - - public void testAccess1() - { - long v = -1 ; - v = Bits.access(v, 4, 8) ; - check(0xF0L, v ) ; - } - - public void testAccess2() - { - long v = 0xFEDCBA9876543210L ; - v = Bits.access(v, 0, 8) ; - check(0x10L, v ) ; - } - - public void testAccess3() - { - long v = 0xFEDCBA9876543210L ; - v = Bits.access(v, 0, 64) ; - check(0xFEDCBA9876543210L, v ) ; - } - - public void testAccess4() - { - long v = 0xFEDCBA9876543210L ; - v = Bits.access(v, 62, 64) ; - check(0xC000000000000000L, v ) ; - } - - public void testAccess5() - { - long v = 0xFEDCBA9876543210L ; - v = Bits.access(v, 0, 2) ; - check(0L, v ) ; - } - - public void testPack1() - { - long v = 0 ; - v = Bits.pack(v, 0xFL, 0, 4) ; - check(0xFL, v ) ; - } - - public void testPack2() - { - long v = 0xF0 ; - v = Bits.pack(v, 0x2, 0, 4) ; - check(0xF2L, v ) ; - } - - public void testPack3() - { - long v = -1 ; - v = Bits.pack(v, 0x2, 0, 8) ; - check(0xFFFFFFFFFFFFFF02L, v ) ; - } - - public void testPack4() - { - long v = 0xFFFFFFFF00000000L ; - v = Bits.pack(v, 0x2, 16, 32) ; - check(0xFFFFFFFF00020000L, v ) ; - } - - public void testPack5() - { - long v = 0xFFFFFFFF00000000L ; - v = Bits.pack(v, 0xFFFF, 16, 32) ; - check(0xFFFFFFFFFFFF0000L, v ) ; - } - - public void testUnpack1() - { - long v = 0xABCDABCDABCDABCDL ; - v = Bits.unpack(v, 0, 4) ; - check(0xDL, v ) ; - } - - public void testUnpack2() - { - long v = 0xABCDABCDABCDABCDL ; - v = Bits.unpack(v, 63, 64) ; - check(1L, v ) ; - } - - public void testUnpack3() - { - long v = 0xABCDABCDABCDABCDL ; - v = Bits.unpack(v, 56, 64) ; - check(0xABL, v ) ; - } - - public void testUnpack4() - { - long v = 0xABCD12345678ABCDL ; - v = Bits.unpack(v, 32, 48) ; - check(0x1234L, v ) ; - } - - public void testUnpackStr1() - { - String s = "ABCD" ; - long v = Bits.unpack(s, 0, 4) ; - check(0xABCDL, v ) ; - } - - public void testUnpackStr2() - { - String s = "ABCD" ; - long v = Bits.unpack(s, 2, 4) ; - check(0xCDL, v ) ; - } - - public void testUnpackStr3() - { - String s = "ABCD" ; - long v = Bits.unpack(s, 0, 2) ; - check(0xABL, v ) ; - } - - private void check(long expected, long actual) - { - check(null, expected, actual) ; - } - - private void check(String msg, long expected, long actual) - { - if ( expected == actual ) return ; - String s = "Expected: "+Long.toHexString(expected)+" : Got: "+Long.toHexString(actual) ; - if ( msg != null ) - s = msg+": "+s ; - assertFalse(s, true) ; - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/b2fb22c7/jena-core/src/test/java/org/apache/jena/shared/uuid/UUIDTestSuite.java ---------------------------------------------------------------------- diff --git a/jena-core/src/test/java/org/apache/jena/shared/uuid/UUIDTestSuite.java b/jena-core/src/test/java/org/apache/jena/shared/uuid/UUIDTestSuite.java index a8c57fc..64817e1 100644 --- a/jena-core/src/test/java/org/apache/jena/shared/uuid/UUIDTestSuite.java +++ b/jena-core/src/test/java/org/apache/jena/shared/uuid/UUIDTestSuite.java @@ -35,7 +35,6 @@ public class UUIDTestSuite extends TestSuite { // The OS kernel can run out of entropy in which case these tests get very slow // These tests may not be in the test suite. - addTestSuite(TestBits.class) ; addTestSuite(TestUUID.class) ; addTestSuite(TestUUID_JRE.class) ; }
