01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.comp;
15:
16: import javax.swing.ListModel;
17:
18: /**
19: *
20: * @author jmarranz
21: */
22: public class ListDataModelUtil {
23:
24: /** Creates a new instance of ListDataModelUtil */
25: public ListDataModelUtil() {
26: }
27:
28: public static boolean contains(Object obj, ListModel model) {
29: return (indexOf(obj, model) >= 0);
30: }
31:
32: public static int indexOf(Object obj, ListModel model) {
33: return indexOf(obj, 0, model);
34: }
35:
36: public static int indexOf(Object obj, int index, ListModel model) {
37: if (obj == null)
38: return -1;
39:
40: int size = model.getSize();
41: for (int i = index; i < size; i++) {
42: Object currObj = model.getElementAt(i);
43: if (currObj.equals(obj))
44: return i;
45: }
46: return -1;
47: }
48:
49: public static int lastIndexOf(Object obj, ListModel model) {
50: return lastIndexOf(obj, model.getSize() - 1, model);
51: }
52:
53: public static int lastIndexOf(Object obj, int index, ListModel model) {
54: if (obj == null)
55: return -1;
56:
57: for (int i = index; i >= 0; i--) {
58: Object currObj = model.getElementAt(i);
59: if (currObj.equals(obj))
60: return i;
61: }
62: return -1;
63: }
64: }
|