Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataList.java Thu Mar 17 16:44:51 2011 +0000 @@ -0,0 +1,133 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DataList implements Serializable { + + /** The list of Data objects managed by this list.*/ + protected List<Data> data; + + /** The name of the state that this list belongs to.*/ + protected String state; + + /** The name of a UIProvider that is recommended to render this DataList.*/ + protected String uiprovider; + + /** The label that should be used to label data objects.*/ + protected String label; + + + /** + * The default constructor that creates a new DataList without Data objects + * and no UIProvider. + */ + public DataList() { + data = new ArrayList<Data>(); + } + + + public DataList(String state, int size) { + this.state = state; + this.data = new ArrayList<Data>(size); + } + + + /** + * A constructor that creates a new DataList without Data objects and no + * UIProvider. Size defines the initial size of the list. + * + * @param size The initial size of the list. + */ + public DataList(String state, int size, String uiprovider) { + this(state, size); + this.uiprovider = uiprovider; + } + + + /** + * Adds a new Data object to the list. + * + * @param obj The Data object. + */ + public void add(Data obj) { + if (obj != null) { + data.add(obj); + } + } + + + /** + * Adds a new Data objects to the list. + * + * @param obj The Data object. + */ + public void add(Data[] obj) { + if (obj != null) { + for (Data o: obj) { + data.add(o); + } + } + } + + + /** + * Returns the Data element at position <i>idx</i>. + * + * @param idx The position of an element that should be returned. + * + * @return the Data element at position <i>idx</i>. + */ + public Data get(int idx) { + if (idx < size()) { + return data.get(idx); + } + + return null; + } + + + /** + * Returns the number of Data objects in the list. + * + * @param the number of Data objects in the list. + */ + public int size() { + return data.size(); + } + + + /** + * Returns the name of the state that this list belongs to. + * + * @return the name of the state that this list belongs to. + */ + public String getState() { + return state; + } + + + /** + * Returns the label for this list. + * + * @return the label of this list. + */ + public String getLabel() { + return label; + } + + + /** + * Retrieves the name of a UIProvider or null if no one is recommended. + * + * @return the name of a UIProvider or null if no one is recommended. + */ + public String getUIProvider() { + return uiprovider; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :