add a useful operation to ArrayHelper

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-11-09 21:06:58 +01:00
parent c86f151b7f
commit cdaee09fba
1 changed files with 10 additions and 1 deletions

View File

@ -22,10 +22,19 @@ import org.hibernate.type.Type;
public final class ArrayHelper { public final class ArrayHelper {
public static boolean contains(Object[] array, Object object) { public static <T> boolean contains(T[] array, T object) {
return indexOf( array, object ) > -1; return indexOf( array, object ) > -1;
} }
public static <T> boolean containsAll(T[] array, T[] elements) {
for ( T element : elements ) {
if ( !contains( array, element ) ) {
return false;
}
}
return true;
}
public static boolean contains(int[] array, int value) { public static boolean contains(int[] array, int value) {
for ( int i = 0; i < array.length; i++ ) { for ( int i = 0; i < array.length; i++ ) {
if ( array[i] == value ) { if ( array[i] == value ) {