Skip to content

Commit 807db89

Browse files
committed
Rename toObjectArray() to toBoxedArray()
1 parent f19863d commit 807db89

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v0.5.0
44
* better resource handling for compression
55
* add nullSafe from() constructor
6+
* rename `toObjectArray()` to `toBoxedArray()` (will be removed in 1.0)
67

78
## v0.4.6
89

src/main/java/at/favre/lib/bytes/Bytes.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ public static Bytes from(Collection<Byte> bytesCollection) {
223223
/**
224224
* Creates a new instance from given object byte array. Will copy and unbox every element.
225225
*
226-
* @param objectArray to create from
226+
* @param boxedObjectArray to create from
227227
* @return new instance
228228
*/
229-
public static Bytes from(Byte[] objectArray) {
230-
return wrap(Util.toPrimitiveArray(objectArray));
229+
public static Bytes from(Byte[] boxedObjectArray) {
230+
return wrap(Util.toPrimitiveArray(boxedObjectArray));
231231
}
232232

233233
/**
@@ -1379,7 +1379,7 @@ public String encode(BinaryToTextEncoding.Encoder encoder) {
13791379
return encoder.encode(internalArray(), byteOrder);
13801380
}
13811381

1382-
/* CONSERVATORS WITHOUT REUSING THE INTERNAL ARRAY ****************************************************************/
1382+
/* CONVERTERS WITHOUT REUSING THE INTERNAL ARRAY ****************************************************************/
13831383

13841384
/**
13851385
* Returns a copy of the internal byte-array as {@link List} collection type
@@ -1391,14 +1391,22 @@ public List<Byte> toList() {
13911391
return Util.toList(internalArray());
13921392
}
13931393

1394+
/**
1395+
* @deprecated renamed API, use {@link #toBoxedArray()} instead - will be removed in v1.0+
1396+
*/
1397+
@Deprecated
1398+
public Byte[] toObjectArray() {
1399+
return toBoxedArray();
1400+
}
1401+
13941402
/**
13951403
* Returns a copy of the internal byte-array as boxed primitive array.
13961404
* This requires a time and space complexity of O(n).
13971405
*
13981406
* @return copy of internal array as object array
13991407
*/
1400-
public Byte[] toObjectArray() {
1401-
return Util.toObjectArray(internalArray());
1408+
public Byte[] toBoxedArray() {
1409+
return Util.toBoxedArray(internalArray());
14021410
}
14031411

14041412
/**

src/main/java/at/favre/lib/bytes/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static List<Byte> toList(byte[] array) {
168168
* @param array to convert
169169
* @return new array
170170
*/
171-
static Byte[] toObjectArray(byte[] array) {
171+
static Byte[] toBoxedArray(byte[] array) {
172172
Byte[] objectArray = new Byte[array.length];
173173
for (int i = 0; i < array.length; i++) {
174174
objectArray[i] = array[i];

src/test/java/at/favre/lib/bytes/BytesToConvertOtherTypesTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
public class BytesToConvertOtherTypesTest extends ABytesTest {
3131

3232
@Test
33-
public void toObjectArray() throws Exception {
33+
public void toObjectArray() {
3434
checkArray(example_bytes_empty);
3535
checkArray(example_bytes_one);
3636
checkArray(example_bytes_two);
@@ -40,15 +40,15 @@ public void toObjectArray() throws Exception {
4040
}
4141

4242
private void checkArray(byte[] array) {
43-
Byte[] byteArray = Bytes.from(array).toObjectArray();
43+
Byte[] byteArray = Bytes.from(array).toBoxedArray();
4444
assertEquals(array.length, byteArray.length);
4545
for (int i = 0; i < array.length; i++) {
4646
assertEquals(byteArray[i], Byte.valueOf(array[i]));
4747
}
4848
}
4949

5050
@Test
51-
public void toList() throws Exception {
51+
public void toList() {
5252
checkList(example_bytes_empty);
5353
checkList(example_bytes_one);
5454
checkList(example_bytes_two);
@@ -66,7 +66,7 @@ private void checkList(byte[] array) {
6666
}
6767

6868
@Test
69-
public void toBitSet() throws Exception {
69+
public void toBitSet() {
7070
assertArrayEquals(example_bytes_empty, Bytes.from(example_bytes_empty).toBitSet().toByteArray());
7171
assertArrayEquals(example_bytes_one, Bytes.from(example_bytes_one).toBitSet().toByteArray());
7272
assertArrayEquals(example_bytes_two, Bytes.from(example_bytes_two).toBitSet().toByteArray());
@@ -76,7 +76,7 @@ public void toBitSet() throws Exception {
7676
}
7777

7878
@Test
79-
public void toByte() throws Exception {
79+
public void toByte() {
8080
assertEquals(example_bytes_one[0], Bytes.from(example_bytes_one).toByte());
8181
assertEquals((byte) 0, Bytes.from(new byte[1]).toByte());
8282
assertEquals(-1, Bytes.from((byte) 0b1111_1111).toByte());
@@ -89,7 +89,7 @@ public void toByte() throws Exception {
8989
}
9090

9191
@Test
92-
public void toUnsignedByte() throws Exception {
92+
public void toUnsignedByte() {
9393
assertEquals(example_bytes_one[0], Bytes.from(example_bytes_one).toUnsignedByte());
9494
assertEquals((byte) 0, Bytes.from(new byte[1]).toUnsignedByte());
9595
assertEquals(255, Bytes.from((byte) 0b1111_1111).toUnsignedByte());
@@ -102,7 +102,7 @@ public void toUnsignedByte() throws Exception {
102102
}
103103

104104
@Test
105-
public void toChar() throws Exception {
105+
public void toChar() {
106106
assertEquals(6767, Bytes.from(example_bytes_two).toChar());
107107
assertEquals(Bytes.from(example_bytes_two).toShort(), Bytes.from(example_bytes_two).toChar());
108108
assertEquals((char) 0, Bytes.from(new byte[2]).toChar());
@@ -120,7 +120,7 @@ public void toChar() throws Exception {
120120
}
121121

122122
@Test
123-
public void toShort() throws Exception {
123+
public void toShort() {
124124
assertEquals(6767, Bytes.from(example_bytes_two).toShort());
125125
assertEquals(Bytes.from(example_bytes_one).toByte(), Bytes.from((byte) 0, example_bytes_one).toShort());
126126
assertEquals((short) 0, Bytes.from(new byte[2]).toShort());
@@ -138,7 +138,7 @@ public void toShort() throws Exception {
138138
}
139139

140140
@Test
141-
public void toInt() throws Exception {
141+
public void toInt() {
142142
assertEquals(591065872, Bytes.from(example_bytes_four).toInt());
143143
assertEquals(Bytes.from(new byte[]{0, 0, 0, 0}, example_bytes_four).toLong(), Bytes.from(example_bytes_four).toInt());
144144

@@ -161,7 +161,7 @@ public void toInt() throws Exception {
161161
}
162162

163163
@Test
164-
public void toLong() throws Exception {
164+
public void toLong() {
165165
assertEquals(-1237929515650418679L, Bytes.from(example_bytes_eight).toLong());
166166

167167
assertEquals(example_bytes_one[0], Bytes.from(new byte[]{0, 0, 0, 0, 0, 0, 0}, example_bytes_one).toLong());
@@ -181,7 +181,7 @@ public void toLong() throws Exception {
181181
}
182182

183183
@Test
184-
public void toFloat() throws Exception {
184+
public void toFloat() {
185185
assertEquals(1.0134550690550691E-17, Bytes.from(example_bytes_four).toFloat(), 0.001);
186186

187187
assertEquals(5.1E-322, Bytes.from(new byte[]{0, 0, 0}, example_bytes_one).toFloat(), 0.001);
@@ -201,7 +201,7 @@ public void toFloat() throws Exception {
201201
}
202202

203203
@Test
204-
public void toDouble() throws Exception {
204+
public void toDouble() {
205205
assertEquals(-6.659307728279082E225, Bytes.from(example_bytes_eight).toDouble(), 0.001);
206206

207207
assertEquals(5.1E-322, Bytes.from(new byte[]{0, 0, 0, 0, 0, 0, 0}, example_bytes_one).toDouble(), 0.001);

0 commit comments

Comments
 (0)