Last change
on this file since 175 was
175,
checked in by sherbold, 13 years ago
|
- code documentation and formatting
|
File size:
935 bytes
|
Line | |
---|
1 | package de.ugoe.cs.util;
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * <p>
|
---|
5 | * Helper class that provides methods to simplify working with arrays.
|
---|
6 | * </p>
|
---|
7 | *
|
---|
8 | * @author Steffen Herbold
|
---|
9 | * @version 1.0
|
---|
10 | */
|
---|
11 | final public class ArrayTools {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Finds the first occurrence of an object inside an array.
|
---|
16 | * </p>
|
---|
17 | * <p>
|
---|
18 | * In case {@code other==null}, the first occurrence of a {@code null} value
|
---|
19 | * in the array is returned.
|
---|
20 | * </p>
|
---|
21 | *
|
---|
22 | * @param array
|
---|
23 | * the array
|
---|
24 | * @param other
|
---|
25 | * the object
|
---|
26 | * @return index of the object if found, -1 otherwise
|
---|
27 | */
|
---|
28 | public static int findIndex(Object[] array, Object other) {
|
---|
29 | int retVal = -1;
|
---|
30 | for (int i = 0; i < array.length && retVal == -1; i++) {
|
---|
31 | if (other != null) {
|
---|
32 | if (array[i] != null && array[i].equals(other)) {
|
---|
33 | retVal = i;
|
---|
34 | }
|
---|
35 | } else {
|
---|
36 | if (array[i] == null) {
|
---|
37 | retVal = i;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 | return retVal;
|
---|
42 | }
|
---|
43 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.