01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12: package com.eviware.soapui.model.util;
13:
14: import java.util.ArrayList;
15: import java.util.Arrays;
16: import java.util.List;
17:
18: import com.eviware.soapui.model.ModelItem;
19:
20: /**
21: * Utility for handling model item names.
22: *
23: * @author Lars Høidahl
24: */
25:
26: public class ModelItemNames<T extends ModelItem> {
27: private List<T> elements;
28:
29: public ModelItemNames(List<T> elements) {
30: this .elements = new ArrayList<T>(elements);
31: }
32:
33: public ModelItemNames(T[] elements) {
34: // Create an ArrayList to make sure that elements is modifyable.
35: this .elements = new ArrayList<T>(Arrays.asList(elements));
36: }
37:
38: public String[] getNames() {
39: ArrayList<String> list = getElementNameList();
40: return list.toArray(new String[list.size()]);
41: }
42:
43: private ArrayList<String> getElementNameList() {
44: ArrayList<String> elementNames = new ArrayList<String>();
45: for (T element : elements) {
46: elementNames.add(element.getName());
47: }
48: return elementNames;
49: }
50:
51: public T getElement(String name) {
52: int index = getElementNameList().indexOf(name);
53: return elements.get(index);
54: }
55:
56: public void addElement(T element) {
57: elements.add(element);
58: }
59:
60: public int getSize() {
61: return elements.size();
62: }
63:
64: public String getNameAt(int i) {
65: return elements.get(i).getName();
66: }
67: }
|