Skip to content

Commit 9a6e07e

Browse files
committed
Adds contains method
1 parent 52048d9 commit 9a6e07e

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Releases
22

3+
## v0.4.2
4+
5+
* add check method if transformer supports inplace
6+
* adds contains method
7+
38
## v0.4.1
49

510
* add bitAt() utility

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,16 @@ public boolean isReadOnly() {
856856
return false;
857857
}
858858

859+
/**
860+
* Checks if given byte value is contained in internal array
861+
*
862+
* @param target a primitive {@code byte} value
863+
* @return true if this Bytes instance contains the specified element
864+
*/
865+
public boolean contains(byte target) {
866+
return indexOf(target) != -1;
867+
}
868+
859869
/**
860870
* Returns the index of the first appearance of the value {@code target} in
861871
* {@code array}.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ public void testIsEmpty() throws Exception {
112112
assertFalse(Bytes.from(example_bytes_seven).isEmpty());
113113
}
114114

115+
@Test
116+
public void containsTest() throws Exception {
117+
assertEquals(false, Bytes.allocate(0).contains((byte) 0xFD));
118+
assertEquals(true, Bytes.allocate(128).contains((byte) 0x00));
119+
assertEquals(true, Bytes.from(example_bytes_seven).contains((byte) 0xFD));
120+
assertEquals(true, Bytes.from(example_bytes_seven).contains((byte) 0xAF));
121+
assertEquals(false, Bytes.from(example_bytes_seven).contains((byte) 0x00));
122+
}
123+
115124
@Test
116125
public void indexOfByte() throws Exception {
117126
assertEquals(-1, Bytes.allocate(0).indexOf((byte) 0xFD));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,6 @@ public int compare(Byte o1, Byte o2) {
367367
return 0;
368368
}
369369
}).supportInPlaceTransformation());
370-
assertFalse(new BytesTransformers.ShuffleTransformer(new SecureRandom()).supportInPlaceTransformation());
370+
assertTrue(new BytesTransformers.ShuffleTransformer(new SecureRandom()).supportInPlaceTransformation());
371371
}
372372
}

0 commit comments

Comments
 (0)