-
Notifications
You must be signed in to change notification settings - Fork 4
/
JavaUtils.java
64 lines (59 loc) · 1.66 KB
/
JavaUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.bytesizebit.androidutils;
import java.util.ArrayList;
import java.util.List;
/***********
* Android Utils
* Created by Shahar Barsheshet on 17/10/2015.
* bytesizebit@gmail.com
* www.bytesizebit.com
***********/
public class JavaUtils {
private JavaUtils() {
}
/**
* Get the index of an object
*
* @param array the items
* @param objectToFind the object
* @return the index of the object or -1 if not found
*/
public static int indexOf(Object[] array, Object objectToFind) {
if (array == null || array.length == 0 || objectToFind == null) {
return -1;
}
for (int i = 0; i < array.length; i++) {
Object obj = array[i];
if (obj.equals(objectToFind)) {
return i;
}
}
return -1;
}
/**
* Create a Integer arrayList from String arrayList
*
* @param arrayList source array
* @return Integer arrayList
*/
public static ArrayList<Integer> convertStringArrayToIntegerArray(List<String> arrayList) {
ArrayList<Integer> integers = new ArrayList<>();
for (String str : arrayList) {
integers.add(Integer.valueOf(str));
}
return integers;
}
/**
* Check if object is null and throw
*
* @param object the object to check
* @param message the message to throw
* @param <T> the object type
* @return the object if not null
*/
public static <T> T checkNotNull(T object, String message) {
if (object == null) {
throw new NullPointerException(message);
}
return object;
}
}