Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/client/cadclientgui/data/CardfileList.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/data/CardfileList.java @ 555

Revision 555, 3.9 KB checked in by jdalbey, 6 years ago (diff)

Declaration and use of CardfileData? removed from CADClientGUI to fix #229. Add a length() function to CardfileList?.java.

RevLine 
1package tmcsim.client.cadclientgui.data;
2
3import java.awt.List;
4import java.io.Serializable;
5import java.util.LinkedList;
6
7/**
8 * This class extends a list and holds a list of CardfileDataObject alongside a
9 * list of CardfileDataObject's Name Field. The index of the CFDO and Name field
10 * should match at all times. Each instance of this class is meant to display
11 * any one list in the Cardfile's tabbed panel.
12 *
13 * @author Vincent
14 *
15 */
16
17public class CardfileList extends List implements Serializable {
18
19    LinkedList<CardfileDataObject> list;
20
21    public CardfileList() {
22        super();
23        list = new LinkedList<CardfileDataObject>();
24    }
25
26    /**
27     * Inserts the object so it remains in sorted order lexicographically.
28     *
29     * @param cfdo
30     *            the object to be inserted
31     * @return the inserted position
32     */
33    public int addDataObject(CardfileDataObject cfdo) {
34        int insertPosition = 0;
35        if (list.size() == 0) {
36            super.add(cfdo.getName());
37            list.add(cfdo);
38            return 0;
39        }
40        if (cfdo.getName().compareTo(list.get(insertPosition).getName()) < 0) {
41            super.add(cfdo.getName(), insertPosition);
42            list.add(insertPosition, cfdo);
43            return insertPosition;
44        }
45        while (insertPosition < list.size()
46                && cfdo.getName().compareTo(list.get(insertPosition).getName()) > 0) {
47            insertPosition++;
48        }
49        if (insertPosition < list.size()) {
50            super.add(cfdo.getName(), insertPosition);
51            list.add(insertPosition, cfdo);
52        } else {
53            super.add(cfdo.getName());
54            list.add(cfdo);
55        }
56        return insertPosition;
57    }
58
59    /**
60     * Removes the CFDO and name field from both lists at the specified index.
61     *
62     * @param index
63     */
64    public void removeDataObject(int index) {
65        if (index >= 0 && index < list.size()) {
66            super.remove(index);
67            list.remove(index);
68        }
69    }
70
71    /**
72     * returns the CFDO as the specified index, null if a bad index was sent.
73     *
74     * @param index
75     * @return the CFDO at the given index, or null if a bad index.
76     */
77    public CardfileDataObject getCFDO(int index) {
78        if (!(index < 0)) {
79            return list.get(index);
80        }
81        return null;
82    }
83
84    /**
85     * Removes the object at the specified index to be reinserted and sorted
86     * into the list.
87     */
88    public int resort(int index) {
89        CardfileDataObject cfdoToInsert = list.remove(index);
90        super.remove(index);
91        return addDataObject(cfdoToInsert);
92    }
93   
94    /**
95     * Returns a LinkedList of CFDO that contain the search string.
96     */
97    public LinkedList<CardfileDataObject> search(String search){
98        LinkedList<CardfileDataObject> returnList = new LinkedList<CardfileDataObject>();
99        for(int i = 0; i < list.size(); i++){
100            if(search.toLowerCase().equals(list.get(i).getCategory().toLowerCase()) ||
101               search.toLowerCase().equals(list.get(i).getName().toLowerCase()) ||
102               search.toLowerCase().equals(list.get(i).getAddress().toLowerCase()) ||
103               search.toLowerCase().equals(list.get(i).getCity().toLowerCase()) ||
104               search.toLowerCase().equals(list.get(i).getState().toLowerCase()) ||
105               search.toLowerCase().equals(list.get(i).getZip().toLowerCase()) ||
106               search.toLowerCase().equals(list.get(i).getPhone1().toLowerCase()) ||
107               search.toLowerCase().equals(list.get(i).getPhone2().toLowerCase()) ||
108               search.toLowerCase().equals(list.get(i).getFax().toLowerCase())){
109                returnList.add(list.get(i));
110               }
111        }
112        return returnList;
113    }
114    /**
115     * Used for debugging.
116     * @return the number of items in the list
117     */
118    public int length()
119    {
120       return list.size();
121    }
122}
Note: See TracBrowser for help on using the repository browser.