Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 58c32df1a44d |
children | c4156275c1e1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Fri Sep 28 12:13:53 2012 +0200 @@ -0,0 +1,127 @@ +package de.intevation.gnv.state; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; + +/** + * @author Tim Englich (tim.englich@intevation.de) + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + */ +public class DefaultInputData implements InputData { + + /** + * + */ + private static final long serialVersionUID = 4308041648698108066L; + + private static final Logger logger = Logger.getLogger(DefaultInputData.class); + + private final static String VALUE_SEPARATOR = " , "; + + protected String name; + protected String value; + protected Map description; + protected Object object; + + + /** + * Constructor + */ + public DefaultInputData(String name, String value) { + this.name = name; + this.value = value; + } + + public DefaultInputData(String name, Object object) { + this.name = name; + this.object = object; + } + + /** + * @see de.intevation.gnv.state.InputData#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.state.InputData#getValue() + */ + public String getValue() { + return this.value; + } + + public void setObject(Object object) { + this.object = object; + } + + public Object getObject() { + return object; + } + + public String getDescription(String key) { + if (description == null) + return null; + + return (String) description.get(key); + } + + public String[] getDescription() { + String[] values = splitValue(); + int length = values.length; + + String[] description = new String[length]; + for (int i = 0; i < length; i++) { + description[i] = (String) this.description.get(values[i]); + } + + return description; + } + + public void setDescription(String[] description) { + if (this.description == null) + this.description = new HashMap(); + + String[] values = splitValue(); + + int length = values.length; + int descLength = description.length; + + for (int i = 0; i < length; i++) { + if (i < descLength) { + this.description.put(values[i], description[i]); + } + else { + break; + } + } + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.name + "==> " + this.value; + } + + /** + * @see de.intevation.gnv.state.InputData#concartValue(java.lang.String) + */ + public void concartValue(String value) { + this.value = this.value + VALUE_SEPARATOR + value; + } + + /** + * @see de.intevation.gnv.state.InputData#splitValue() + */ + public String[] splitValue() { + if (this.value != null){ + return this.value.split(VALUE_SEPARATOR); + } + return null; + } + +}