source: other-projects/GlamED/trunk/src/org/honours/collection/Collection.java@ 26607

Last change on this file since 26607 was 26607, checked in by davidb, 11 years ago

Added in getCollectionSpace method.

File size: 2.5 KB
Line 
1package org.honours.collection;
2
3import java.util.List;
4import java.util.concurrent.CopyOnWriteArrayList;
5
6import org.expeditee.gui.Frame;
7import org.honours.Main;
8import org.honours.CollectionSpace.*;
9
10public class Collection {
11
12 private String _name;
13 private CopyOnWriteArrayList<CollectionItem> _items;
14 private CollectionInformation _collectionInfo;
15
16 private CollectionSpace _collectionSpace;
17
18 public Collection() {}
19
20 public Collection(String name){
21 _name = name;
22 _items = new CopyOnWriteArrayList<CollectionItem>();
23 }
24
25 public void setName(String s){
26 _name = s;
27 }
28
29 public String getName(){
30 return _name;
31 }
32
33 public void setCollectionInformation(CollectionInformation ci){
34 _collectionInfo = ci;
35 }
36
37 public CollectionInformation getCollectionInformation(){
38 return _collectionInfo;
39 }
40
41 public void addItem(CollectionItem item){
42 _items.add(item);
43 }
44
45 public List<CollectionItem> getItems()
46 {
47 return _items;
48 }
49
50 public void resetItems(){
51 //_items = new ArrayList<CollectionItem>();
52 _items = new CopyOnWriteArrayList<CollectionItem>();
53 }
54
55 public void setCollectionSpace(CollectionSpace cs){
56 _collectionSpace = cs;
57 }
58
59 public CollectionSpace getCollectionSpace(){
60 return _collectionSpace;
61 }
62
63public static Collection findCollection(Frame frame){
64
65 if(frame == null)
66 return null;
67
68 String framesetName = frame.getFramesetName();
69 for(Collection c : Main._collections){
70 if(c.getName().equals(framesetName))
71 return c;
72 }
73 return null;
74 }
75
76 /**
77 * Find a collection with the matching
78 * passed (frameset) name.
79 * @param name
80 * @return
81 */
82 public static Collection findCollection(String name){
83
84 if(name == null)
85 return null;
86 else if(name.equals(""))
87 return null;
88
89 for(Collection c : Main._collections){
90 if(c.getName().equals(name))
91 return c;
92 }
93
94 return null;
95 }
96
97 public static int getCollectionPosition(Collection c){
98
99 if(c == null)
100 return -1;
101
102 for(int i = 0; i < Main._collections.size(); i++){
103 Collection currCol = Main._collections.get(i);
104 if(currCol == c)
105 return i;
106 }
107
108 return -1;
109 }
110
111 public static int getCollectionPosition(Frame frame){
112 Collection find = findCollection(frame);
113 if(find == null)
114 return -1;
115
116 for(int i = 0; i < Main._collections.size(); i++){
117
118 Collection currCol = Main._collections.get(i);
119 if(currCol == find)
120 return i;
121
122 }
123
124 return -1;
125 }
126
127}
Note: See TracBrowser for help on using the repository browser.