Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/shared/model/DataList.java @ 51:a2923d63f530
Introduced a data structure DataList to manage to list of Data objects of a single state.
flys-client/trunk@1505 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 17 Mar 2011 16:44:51 +0000 |
parents | |
children | 1d0be51ab93b |
comparison
equal
deleted
inserted
replaced
50:827eb4e06ebf | 51:a2923d63f530 |
---|---|
1 package de.intevation.flys.client.shared.model; | |
2 | |
3 import java.io.Serializable; | |
4 import java.util.ArrayList; | |
5 import java.util.List; | |
6 | |
7 /** | |
8 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
9 */ | |
10 public class DataList implements Serializable { | |
11 | |
12 /** The list of Data objects managed by this list.*/ | |
13 protected List<Data> data; | |
14 | |
15 /** The name of the state that this list belongs to.*/ | |
16 protected String state; | |
17 | |
18 /** The name of a UIProvider that is recommended to render this DataList.*/ | |
19 protected String uiprovider; | |
20 | |
21 /** The label that should be used to label data objects.*/ | |
22 protected String label; | |
23 | |
24 | |
25 /** | |
26 * The default constructor that creates a new DataList without Data objects | |
27 * and no UIProvider. | |
28 */ | |
29 public DataList() { | |
30 data = new ArrayList<Data>(); | |
31 } | |
32 | |
33 | |
34 public DataList(String state, int size) { | |
35 this.state = state; | |
36 this.data = new ArrayList<Data>(size); | |
37 } | |
38 | |
39 | |
40 /** | |
41 * A constructor that creates a new DataList without Data objects and no | |
42 * UIProvider. Size defines the initial size of the list. | |
43 * | |
44 * @param size The initial size of the list. | |
45 */ | |
46 public DataList(String state, int size, String uiprovider) { | |
47 this(state, size); | |
48 this.uiprovider = uiprovider; | |
49 } | |
50 | |
51 | |
52 /** | |
53 * Adds a new Data object to the list. | |
54 * | |
55 * @param obj The Data object. | |
56 */ | |
57 public void add(Data obj) { | |
58 if (obj != null) { | |
59 data.add(obj); | |
60 } | |
61 } | |
62 | |
63 | |
64 /** | |
65 * Adds a new Data objects to the list. | |
66 * | |
67 * @param obj The Data object. | |
68 */ | |
69 public void add(Data[] obj) { | |
70 if (obj != null) { | |
71 for (Data o: obj) { | |
72 data.add(o); | |
73 } | |
74 } | |
75 } | |
76 | |
77 | |
78 /** | |
79 * Returns the Data element at position <i>idx</i>. | |
80 * | |
81 * @param idx The position of an element that should be returned. | |
82 * | |
83 * @return the Data element at position <i>idx</i>. | |
84 */ | |
85 public Data get(int idx) { | |
86 if (idx < size()) { | |
87 return data.get(idx); | |
88 } | |
89 | |
90 return null; | |
91 } | |
92 | |
93 | |
94 /** | |
95 * Returns the number of Data objects in the list. | |
96 * | |
97 * @param the number of Data objects in the list. | |
98 */ | |
99 public int size() { | |
100 return data.size(); | |
101 } | |
102 | |
103 | |
104 /** | |
105 * Returns the name of the state that this list belongs to. | |
106 * | |
107 * @return the name of the state that this list belongs to. | |
108 */ | |
109 public String getState() { | |
110 return state; | |
111 } | |
112 | |
113 | |
114 /** | |
115 * Returns the label for this list. | |
116 * | |
117 * @return the label of this list. | |
118 */ | |
119 public String getLabel() { | |
120 return label; | |
121 } | |
122 | |
123 | |
124 /** | |
125 * Retrieves the name of a UIProvider or null if no one is recommended. | |
126 * | |
127 * @return the name of a UIProvider or null if no one is recommended. | |
128 */ | |
129 public String getUIProvider() { | |
130 return uiprovider; | |
131 } | |
132 } | |
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |