1919
2020package org .apache .datasketches .memory .internal ;
2121
22- import java .lang .foreign .Arena ;
23- import static org .apache .datasketches .memory .internal .UtilForTest .CB ;
24- import static org .apache .datasketches .memory .internal .UtilForTest .DB ;
25- import static org .apache .datasketches .memory .internal .UtilForTest .FB ;
26- import static org .apache .datasketches .memory .internal .UtilForTest .IB ;
27- import static org .apache .datasketches .memory .internal .UtilForTest .LB ;
28- import static org .apache .datasketches .memory .internal .UtilForTest .NBO ;
29- import static org .apache .datasketches .memory .internal .UtilForTest .NNBO ;
30- import static org .apache .datasketches .memory .internal .UtilForTest .SB ;
22+ import static org .apache .datasketches .memory .internal .ResourceImpl .NATIVE_BYTE_ORDER ;
23+ import static org .apache .datasketches .memory .internal .ResourceImpl .NON_NATIVE_BYTE_ORDER ;
3124import static org .testng .Assert .assertEquals ;
3225import static org .testng .Assert .assertFalse ;
33- import static org .testng .Assert .assertNotNull ;
3426import static org .testng .Assert .assertTrue ;
3527
28+ import java .lang .foreign .Arena ;
3629import java .nio .ByteBuffer ;
3730import java .nio .ByteOrder ;
3831
@@ -72,7 +65,7 @@ public void checkPutGetBooleans() {
7265 boolean [] srcArray = {true , false , true , false , false , true , false , true };
7366 final int len = srcArray .length ;
7467 final int half = len / 2 ;
75- WritableBuffer wbuf = WritableMemory .allocate (len , NBO ).asWritableBuffer ();
68+ WritableBuffer wbuf = WritableMemory .allocate (len , NATIVE_BYTE_ORDER ).asWritableBuffer ();
7669 //put
7770 for (int i = 0 ; i < half ; i ++) { wbuf .putBoolean (srcArray [i ]); } //put*(value)
7871 for (int i = half ; i < len ; i ++) { wbuf .putBoolean (i , srcArray [i ]); } //put*(add, value)
@@ -89,7 +82,7 @@ public void checkPutGetBytes() {
8982 byte [] srcArray = { 1 , -2 , 3 , -4 , 5 , -6 , 7 , -8 };
9083 final int len = srcArray .length ;
9184 final int half = len / 2 ;
92- WritableBuffer wbuf = WritableMemory .allocate (len , NBO ).asWritableBuffer ();
85+ WritableBuffer wbuf = WritableMemory .allocate (len , NATIVE_BYTE_ORDER ).asWritableBuffer ();
9386 //put
9487 wbuf .putByte (srcArray [0 ]); //put*(value)
9588 wbuf .putByteArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
@@ -110,19 +103,19 @@ public void checkPutGetNativeCharacters() {
110103 char [] srcArray = { 'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' };
111104 final int len = srcArray .length ;
112105 final int half = len / 2 ;
113- WritableBuffer wbuf = WritableMemory .allocate (len * CB , NBO ).asWritableBuffer ();
106+ WritableBuffer wbuf = WritableMemory .allocate (len * Character . BYTES , NATIVE_BYTE_ORDER ).asWritableBuffer ();
114107 //put
115108 wbuf .putChar (srcArray [0 ]); //put*(value)
116109 wbuf .putCharArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
117110 wbuf .putChar (srcArray [3 ]); //put*(value)
118- for (int i = half ; i < len ; i ++) { wbuf .putChar (i * CB , srcArray [i ]); } //put*(add, value)
111+ for (int i = half ; i < len ; i ++) { wbuf .putChar (i * Character . BYTES , srcArray [i ]); } //put*(add, value)
119112 wbuf .resetPosition ();
120113 //get
121114 char [] dstArray = new char [len ];
122115 dstArray [0 ] = wbuf .getChar (); //get*()
123116 wbuf .getCharArray (dstArray , 1 , 2 ); //get*Array(dst[], dstOff, len)
124117 dstArray [3 ] = wbuf .getChar (); //get*()
125- for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getChar (i * CB ); } //get*(add)
118+ for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getChar (i * Character . BYTES ); } //get*(add)
126119 assertEquals (srcArray , dstArray );
127120 }
128121
@@ -131,19 +124,19 @@ public void checkPutGetNativeDoubles() {
131124 double [] srcArray = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
132125 final int len = srcArray .length ;
133126 final int half = len / 2 ;
134- WritableBuffer wbuf = WritableMemory .allocate (len * DB , NBO ).asWritableBuffer ();
127+ WritableBuffer wbuf = WritableMemory .allocate (len * Double . BYTES , NATIVE_BYTE_ORDER ).asWritableBuffer ();
135128 //put
136129 wbuf .putDouble (srcArray [0 ]); //put*(value)
137130 wbuf .putDoubleArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
138131 wbuf .putDouble (srcArray [3 ]); //put*(value)
139- for (int i = half ; i < len ; i ++) { wbuf .putDouble (i * DB , srcArray [i ]); } //put*(add, value)
132+ for (int i = half ; i < len ; i ++) { wbuf .putDouble (i * Double . BYTES , srcArray [i ]); } //put*(add, value)
140133 wbuf .resetPosition ();
141134 //get
142135 double [] dstArray = new double [len ];
143136 dstArray [0 ] = wbuf .getDouble (); //get*()
144137 wbuf .getDoubleArray (dstArray , 1 , 2 ); //get*Array(dst[], dstOff, len)
145138 dstArray [3 ] = wbuf .getDouble (); //get*()
146- for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getDouble (i * DB ); } //get*(add)
139+ for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getDouble (i * Double . BYTES ); } //get*(add)
147140 assertEquals (srcArray , dstArray );
148141 }
149142
@@ -152,19 +145,19 @@ public void checkPutGetNativeFloats() {
152145 float [] srcArray = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
153146 final int len = srcArray .length ;
154147 final int half = len / 2 ;
155- WritableBuffer wbuf = WritableMemory .allocate (len * FB , NBO ).asWritableBuffer ();
148+ WritableBuffer wbuf = WritableMemory .allocate (len * Float . BYTES , NATIVE_BYTE_ORDER ).asWritableBuffer ();
156149 //put
157150 wbuf .putFloat (srcArray [0 ]); //put*(value)
158151 wbuf .putFloatArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
159152 wbuf .putFloat (srcArray [3 ]); //put*(value)
160- for (int i = half ; i < len ; i ++) { wbuf .putFloat (i * FB , srcArray [i ]); } //put*(add, value)
153+ for (int i = half ; i < len ; i ++) { wbuf .putFloat (i * Float . BYTES , srcArray [i ]); } //put*(add, value)
161154 wbuf .resetPosition ();
162155 //get
163156 float [] dstArray = new float [len ];
164157 dstArray [0 ] = wbuf .getFloat (); //get*()
165158 wbuf .getFloatArray (dstArray , 1 , 2 ); //get*Array(dst[], dstOff, len)
166159 dstArray [3 ] = wbuf .getFloat (); //get*()
167- for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getFloat (i * FB ); } //get*(add)
160+ for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getFloat (i * Float . BYTES ); } //get*(add)
168161 assertEquals (srcArray , dstArray );
169162 }
170163
@@ -173,19 +166,19 @@ public void checkPutGetNativeInts() {
173166 int [] srcArray = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
174167 final int len = srcArray .length ;
175168 final int half = len / 2 ;
176- WritableBuffer wbuf = WritableMemory .allocate (len * IB , NBO ).asWritableBuffer ();
169+ WritableBuffer wbuf = WritableMemory .allocate (len * Integer . BYTES , NATIVE_BYTE_ORDER ).asWritableBuffer ();
177170 //put
178171 wbuf .putInt (srcArray [0 ]); //put*(value)
179172 wbuf .putIntArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
180173 wbuf .putInt (srcArray [3 ]); //put*(value)
181- for (int i = half ; i < len ; i ++) { wbuf .putInt (i * IB , srcArray [i ]); } //put*(add, value)
174+ for (int i = half ; i < len ; i ++) { wbuf .putInt (i * Integer . BYTES , srcArray [i ]); } //put*(add, value)
182175 wbuf .resetPosition ();
183176 //get
184177 int [] dstArray = new int [len ];
185178 dstArray [0 ] = wbuf .getInt (); //get*()
186179 wbuf .getIntArray (dstArray , 1 , 2 ); //get*Array(dst[], dstOff, len)
187180 dstArray [3 ] = wbuf .getInt (); //get*()
188- for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getInt (i * IB ); } //get*(add)
181+ for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getInt (i * Integer . BYTES ); } //get*(add)
189182 assertEquals (srcArray , dstArray );
190183 }
191184
@@ -194,19 +187,19 @@ public void checkPutGetNativeLongs() {
194187 long [] srcArray = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
195188 final int len = srcArray .length ;
196189 final int half = len / 2 ;
197- WritableBuffer wbuf = WritableMemory .allocate (len * LB , NNBO ).asWritableBuffer ();
190+ WritableBuffer wbuf = WritableMemory .allocate (len * Long . BYTES , NATIVE_BYTE_ORDER ).asWritableBuffer ();
198191 //put
199192 wbuf .putLong (srcArray [0 ]); //put*(value)
200193 wbuf .putLongArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
201194 wbuf .putLong (srcArray [3 ]); //put*(value)
202- for (int i = half ; i < len ; i ++) { wbuf .putLong (i * LB , srcArray [i ]); } //put*(add, value)
195+ for (int i = half ; i < len ; i ++) { wbuf .putLong (i * Long . BYTES , srcArray [i ]); } //put*(add, value)
203196 wbuf .resetPosition ();
204197 //get
205198 long [] dstArray = new long [len ];
206199 dstArray [0 ] = wbuf .getLong (); //get*()
207200 wbuf .getLongArray (dstArray , 1 , 2 ); //get*Array(dst[], dstOff, len)
208201 dstArray [3 ] = wbuf .getLong (); //get*()
209- for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getLong (i * LB ); } //get*(add)
202+ for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getLong (i * Long . BYTES ); } //get*(add)
210203 assertEquals (srcArray , dstArray );
211204 }
212205
@@ -215,19 +208,19 @@ public void checkPutGetNativeShorts() {
215208 short [] srcArray = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
216209 final int len = srcArray .length ;
217210 final int half = len / 2 ;
218- WritableBuffer wbuf = WritableMemory .allocate (len * SB , NBO ).asWritableBuffer ();
211+ WritableBuffer wbuf = WritableMemory .allocate (len * Short . BYTES , NATIVE_BYTE_ORDER ).asWritableBuffer ();
219212 //put
220213 wbuf .putShort (srcArray [0 ]); //put*(value)
221214 wbuf .putShortArray (srcArray , 1 , 2 ); //put*Array(src[], srcOff, len)
222215 wbuf .putShort (srcArray [3 ]); //put*(value)
223- for (int i = half ; i < len ; i ++) { wbuf .putShort (i * SB , srcArray [i ]); } //put*(add, value)
216+ for (int i = half ; i < len ; i ++) { wbuf .putShort (i * Short . BYTES , srcArray [i ]); } //put*(add, value)
224217 wbuf .resetPosition ();
225218 //get
226219 short [] dstArray = new short [len ];
227220 dstArray [0 ] = wbuf .getShort (); //get*()
228221 wbuf .getShortArray (dstArray , 1 , 2 ); //get*Array(dst[], dstOff, len)
229222 dstArray [3 ] = wbuf .getShort (); //get*()
230- for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getShort (i * SB ); } //get*(add)
223+ for (int i = half ; i < len ; i ++) { dstArray [i ] = wbuf .getShort (i * Short . BYTES ); } //get*(add)
231224 assertEquals (srcArray , dstArray );
232225 }
233226
@@ -512,7 +505,7 @@ public void checkZeroBuffer() {
512505 public void checkDuplicateNonNative () {
513506 WritableMemory wmem = WritableMemory .allocate (64 );
514507 wmem .putShort (0 , (short ) 1 );
515- Buffer buf = wmem .asWritableBuffer ().duplicate (NNBO );
508+ Buffer buf = wmem .asWritableBuffer ().duplicate (NON_NATIVE_BYTE_ORDER );
516509 assertEquals (buf .getShort (0 ), 256 );
517510 }
518511
0 commit comments