Skip to content

Commit ae9af05

Browse files
committed
JBytes.len
1 parent 1354f59 commit ae9af05

File tree

2 files changed

+8
-0
lines changed
  • src
    • main/java/com/trivago/fastutilconcurrentwrapper/util
    • test/java/com/trivago/fastutilconcurrentwrapper/util

2 files changed

+8
-0
lines changed

src/main/java/com/trivago/fastutilconcurrentwrapper/util/JBytes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public static boolean nonEmpty (byte @Nullable [] b) {
4141
return b != null && b.length > 0;
4242
}
4343

44+
public static int len (byte @Nullable [] b){
45+
return b != null ? b.length : 0;
46+
}
47+
4448
/**
4549
A common case of copying arrays from start to [start .. min(len1,len2))
4650
Used when increasing or decreasing the array length.

src/test/java/com/trivago/fastutilconcurrentwrapper/util/JBytesTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ void testIsEmptyAndNonEmpty() {
3232
assertFalse(JBytes.nonEmpty(null));
3333
assertFalse(JBytes.nonEmpty(new byte[0]));
3434
assertTrue(JBytes.nonEmpty(new byte[]{1}));
35+
36+
assertEquals(0, JBytes.len(null));
37+
assertEquals(0, JBytes.len(new byte[0]));
38+
assertEquals(1, JBytes.len(new byte[]{0}));
3539
}
3640

3741
@Test

0 commit comments

Comments
 (0)