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