01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.util;
20:
21: public class ArrayUtils {
22: public static int indexOf(int[] array, int value) {
23: for (int i = 0; i < array.length; i++) {
24: if (array[i] == value) {
25: return i;
26: }
27: }
28: return -1;
29: }
30:
31: public static int indexOf(Object[] array, Object value) {
32: for (int i = 0; i < array.length; i++) {
33: if (array[i] == value) {
34: return i;
35: }
36: if (value != null && array[i] != null
37: && value.equals(array[i])) {
38: return i;
39: }
40: }
41: return -1;
42: }
43:
44: public static int identityIndexOf(Object[] array, Object value) {
45: for (int i = 0; i < array.length; i++) {
46: if (array[i] == value) {
47: return i;
48: }
49: }
50: return -1;
51: }
52:
53: public static void clear(Object[] array) {
54: for (int i = 0; i < array.length; i++) {
55: array[i] = null;
56: }
57: }
58:
59: public static String toString(int[] array) {
60: StringBuffer result = new StringBuffer();
61: result.append('{');
62: for (int i = 0; i < array.length; i++) {
63: result.append("" + array[i] + ",");
64: }
65: result.append('}');
66: return result.toString();
67: }
68:
69: }
|