diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java new file mode 100644 index 000000000..f94da4137 --- /dev/null +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.parameter; + +import java.util.List; + +import li.strolch.model.Parameter; + +/** + * @author Robert von Burg + * + */ +public interface ListParameter extends Parameter> { + + /** + * Adds a single value to the {@link List} of values + * + * @param value + * the value to add + */ + public abstract void addValue(E value); + + /** + * Removes a single value from the {@link List} of values + * + * @param value + * the value to remove + * + * @return true if the value was removed, false if it did not exist + */ + public abstract boolean removeValue(E value); +} diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java new file mode 100644 index 000000000..51c9df022 --- /dev/null +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model.parameter; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import li.strolch.model.StrolchElement; + +/** + * @author Robert von Burg + */ +public class StringListParameter extends AbstractParameter> implements ListParameter { + + public static final String TYPE = "StringList"; + private static final long serialVersionUID = 1L; + + protected List value; + + @Override + public String getValueAsString() { + if (this.value.isEmpty()) + return ""; + + StringBuilder sb = new StringBuilder(); + Iterator iter = this.value.iterator(); + while (iter.hasNext()) { + + sb.append(iter.next()); + + if (iter.hasNext()) + sb.append(";"); + } + + return sb.toString(); + } + + @Override + public List getValue() { + return new ArrayList(this.value); + } + + @Override + public void setValue(List value) { + this.value.clear(); + this.value.addAll(value); + } + + @Override + public void addValue(String value) { + this.value.add(value); + } + + @Override + public boolean removeValue(String value) { + return this.value.remove(value); + } + + @Override + public String getType() { + return TYPE; + } + + @Override + public StrolchElement getClone() { + StringListParameter clone = new StringListParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +}