@@ -101,10 +101,10 @@ private Util() {}
101101 * @return an int extracted from a Little-Endian byte array.
102102 */
103103 public static int bytesToInt (final byte [] arr ) {
104- return arr [3 ] << 24
105- | (arr [2 ] & 0xff ) << 16
106- | (arr [1 ] & 0xff ) << 8
107- | arr [0 ] & 0xff ;
104+ return ( arr [3 ] << 24 )
105+ | (( arr [2 ] & 0xff ) << 16 )
106+ | (( arr [1 ] & 0xff ) << 8 )
107+ | ( arr [0 ] & 0xff ) ;
108108 }
109109
110110 /**
@@ -113,14 +113,14 @@ public static int bytesToInt(final byte[] arr) {
113113 * @return a long extracted from a Little-Endian byte array.
114114 */
115115 public static long bytesToLong (final byte [] arr ) {
116- return (long )arr [7 ] << 56
117- | ((long )arr [6 ] & 0xff ) << 48
118- | ((long )arr [5 ] & 0xff ) << 40
119- | ((long )arr [4 ] & 0xff ) << 32
120- | ((long )arr [3 ] & 0xff ) << 24
121- | ((long )arr [2 ] & 0xff ) << 16
122- | ((long )arr [1 ] & 0xff ) << 8
123- | (long )arr [0 ] & 0xff ;
116+ return (( long )arr [7 ] << 56 )
117+ | ((( long )arr [6 ] & 0xff ) << 48 )
118+ | ((( long )arr [5 ] & 0xff ) << 40 )
119+ | ((( long )arr [4 ] & 0xff ) << 32 )
120+ | ((( long )arr [3 ] & 0xff ) << 24 )
121+ | ((( long )arr [2 ] & 0xff ) << 16 )
122+ | ((( long )arr [1 ] & 0xff ) << 8 )
123+ | (( long )arr [0 ] & 0xff ) ;
124124 }
125125
126126 /**
@@ -159,7 +159,7 @@ public static byte[] longToBytes(final long v, final byte[] arr) {
159159
160160 static long [] convertToLongArray (final byte [] byteArr , final boolean littleEndian ) {
161161 final int len = byteArr .length ;
162- final long [] longArr = new long [len / 8 + (len % 8 != 0 ? 1 : 0 )];
162+ final long [] longArr = new long [( len / 8 ) + (( len % 8 ) != 0 ? 1 : 0 )];
163163 int off = 0 ;
164164 int longArrIdx = 0 ;
165165 while (off < len ) {
@@ -191,7 +191,7 @@ public static String longToHexBytes(final long v) {
191191 final long mask = 0XFFL ;
192192 final StringBuilder sb = new StringBuilder ();
193193 for (int i = 8 ; i -- > 0 ; ) {
194- final String s = Long .toHexString (v >>> i * 8 & mask );
194+ final String s = Long .toHexString (( v >>> ( i * 8 )) & mask );
195195 sb .append (zeroPad (s , 2 )).append (" " );
196196 }
197197 return sb .toString ();
@@ -211,7 +211,7 @@ public static String bytesToString(
211211 final int mask = signed ? 0XFFFFFFFF : 0XFF ;
212212 final int arrLen = arr .length ;
213213 if (littleEndian ) {
214- for (int i = 0 ; i < arrLen - 1 ; i ++) {
214+ for (int i = 0 ; i < ( arrLen - 1 ) ; i ++) {
215215 sb .append (arr [i ] & mask ).append (sep );
216216 }
217217 sb .append (arr [arrLen - 1 ] & mask );
@@ -231,8 +231,8 @@ public static String bytesToString(
231231 */
232232 public static String nanoSecToString (final long nS ) {
233233 final long rem_nS = (long )(nS % 1000.0 );
234- final long rem_uS = (long )(nS / 1000.0 % 1000.0 );
235- final long rem_mS = (long )(nS / 1000000.0 % 1000.0 );
234+ final long rem_uS = (long )(( nS / 1000.0 ) % 1000.0 );
235+ final long rem_mS = (long )(( nS / 1000000.0 ) % 1000.0 );
236236 final long sec = (long )(nS / 1000000000.0 );
237237 final String nSstr = zeroPad (Long .toString (rem_nS ), 3 );
238238 final String uSstr = zeroPad (Long .toString (rem_uS ), 3 );
@@ -247,8 +247,8 @@ public static String nanoSecToString(final long nS) {
247247 */
248248 public static String milliSecToString (final long mS ) {
249249 final long rem_mS = (long )(mS % 1000.0 );
250- final long rem_sec = (long )(mS / 1000.0 % 60.0 );
251- final long rem_min = (long )(mS / 60000.0 % 60.0 );
250+ final long rem_sec = (long )(( mS / 1000.0 ) % 60.0 );
251+ final long rem_min = (long )(( mS / 60000.0 ) % 60.0 );
252252 final long hr = (long )(mS / 3600000.0 );
253253 final String mSstr = zeroPad (Long .toString (rem_mS ), 3 );
254254 final String secStr = zeroPad (Long .toString (rem_sec ), 2 );
@@ -296,7 +296,7 @@ public static String characterPad(final String s, final int fieldLength, final c
296296 * @param argName This name will be part of the error message if the check fails.
297297 */
298298 public static void checkIfMultipleOf8AndGT0 (final long v , final String argName ) {
299- if ((v & 0X7L ) == 0L && v > 0L ) {
299+ if ((( v & 0X7L ) == 0L ) && ( v > 0L ) ) {
300300 return ;
301301 }
302302 throw new SketchesArgumentException ("The value of the parameter \" " + argName
@@ -309,7 +309,7 @@ public static void checkIfMultipleOf8AndGT0(final long v, final String argName)
309309 * @return true if v is a multiple of 8 and greater than zero
310310 */
311311 public static boolean isMultipleOf8AndGT0 (final long v ) {
312- return (v & 0X7L ) == 0L && v > 0L ;
312+ return (( v & 0X7L ) == 0L ) && ( v > 0L ) ;
313313 }
314314
315315 //Powers of 2 or powers of base related
@@ -356,7 +356,7 @@ public static void checkIfPowerOf2(final long n, String argName) {
356356 public static int ceilingPowerOf2 (final int n ) {
357357 if (n <= 1 ) { return 1 ; }
358358 final int topIntPwrOf2 = 1 << 30 ;
359- return n >= topIntPwrOf2 ? topIntPwrOf2 : Integer .highestOneBit (n - 1 << 1 );
359+ return n >= topIntPwrOf2 ? topIntPwrOf2 : Integer .highestOneBit (( n - 1 ) << 1 );
360360 }
361361
362362 /**
@@ -377,7 +377,7 @@ public static int ceilingPowerOf2(final int n) {
377377 public static long ceilingPowerOf2 (final long n ) {
378378 if (n <= 1L ) { return 1L ; }
379379 final long topIntPwrOf2 = 1L << 62 ;
380- return n >= topIntPwrOf2 ? topIntPwrOf2 : Long .highestOneBit (n - 1L << 1 );
380+ return n >= topIntPwrOf2 ? topIntPwrOf2 : Long .highestOneBit (( n - 1L ) << 1 );
381381 }
382382
383383 /**
@@ -430,8 +430,8 @@ public static long floorPowerOf2(final long n) {
430430 * @return the inverse integer power of 2: 1/(2^e) = 2^(-e)
431431 */
432432 public static double invPow2 (final int e ) {
433- assert (e | 1024 - e - 1 ) >= 0 : "e cannot be negative or greater than 1023: " + e ;
434- return Double .longBitsToDouble (1023L - e << 52 );
433+ assert (e | ( 1024 - e - 1 ) ) >= 0 : "e cannot be negative or greater than 1023: " + e ;
434+ return Double .longBitsToDouble (( 1023L - e ) << 52 );
435435 }
436436
437437 /**
@@ -695,7 +695,7 @@ public static void checkBounds(final long reqOff, final long reqLen, final long
695695 * @param argName Used in the thrown exception.
696696 */
697697 public static void checkProbability (final double p , final String argName ) {
698- if (p >= 0.0 && p <= 1.0 ) {
698+ if (( p >= 0.0 ) && ( p <= 1.0 ) ) {
699699 return ;
700700 }
701701 throw new SketchesArgumentException ("The value of the parameter \" " + argName
@@ -711,7 +711,7 @@ public static void checkProbability(final double p, final String argName) {
711711 * @return true if n1 > n2.
712712 */
713713 public static boolean isLessThanUnsigned (final long n1 , final long n2 ) {
714- return n1 < n2 ^ n1 < 0 != n2 < 0 ;
714+ return ( n1 < n2 ) ^ (( n1 < 0 ) != ( n2 < 0 )) ;
715715 }
716716
717717 /**
@@ -741,7 +741,7 @@ public static boolean isOdd(final long n) {
741741 * bit is at position zero.
742742 * @return a one if the bit at bitPos is a one, otherwise zero.
743743 */
744- public static final int bitAt (final long number , final int bitPos ) {
744+ public static int bitAt (final long number , final int bitPos ) {
745745 return (number & (1L << bitPos )) > 0 ? 1 : 0 ;
746746 }
747747
@@ -751,7 +751,7 @@ public static final int bitAt(final long number, final int bitPos) {
751751 * @return the number of decimal digits of the number n
752752 */
753753 public static int numDigits (long n ) {
754- if (n % 10 == 0 ) { n ++; }
754+ if (( n % 10 ) == 0 ) { n ++; }
755755 return (int ) ceil (log (n ) / log (10 ));
756756 }
757757
@@ -898,39 +898,6 @@ public static void fill(final MemorySegment seg, final long offsetBytes, final l
898898 slice .fill (value );
899899 }
900900
901- /**
902- * Returns true if the two given MemorySegments refer to the same backing resource,
903- * which is either an off-heap memory location and size, or the same on-heap array object.
904- *
905- * <p>If both segment are off-heap, they both must have the same starting address and the same size.</p>
906- *
907- * <p>For on-heap segments, both segments must be based on or derived from the same array object and neither segment
908- * can be read-only.</p>
909- *
910- * <p>Returns false if either argument is null;</p>
911- *
912- * @param seg1 The first given MemorySegment
913- * @param seg2 The second given MemorySegment
914- * @return true if both MemorySegments are determined to be the same backing memory.
915- */
916- public static boolean isSameResource (final MemorySegment seg1 , final MemorySegment seg2 ) {
917- if ((seg1 == null ) || (seg2 == null )) { return false ; }
918- if (!seg1 .scope ().isAlive () || !seg2 .scope ().isAlive ()) {
919- throw new IllegalArgumentException ("Both arguments must be alive." );
920- }
921- final boolean seg1Native = seg1 .isNative ();
922- final boolean seg2Native = seg2 .isNative ();
923- if (seg1Native ^ seg2Native ) { return false ; }
924- if (seg1Native && seg2Native ) { //both off heap
925- return (seg1 .address () == seg2 .address ()) && (seg1 .byteSize () == seg2 .byteSize ());
926- }
927- //both on heap
928- if (seg1 .isReadOnly () || seg2 .isReadOnly ()) {
929- throw new IllegalArgumentException ("Cannot determine 'isSameBackingMemory(..)' on heap if either MemorySegment is Read-only." );
930- }
931- return (seg1 .heapBase ().orElse (null ) == seg2 .heapBase ().orElse (null ));
932- }
933-
934901 /**
935902 * Request a new heap MemorySegment with the given capacityBytes and either 8-byte aligned or one byte aligned.
936903 *
0 commit comments