net.sf.jcmdlineparser.options.AbstractMultiOption Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcmdlineparser Show documentation
Show all versions of jcmdlineparser Show documentation
A highly adaptive and easy to use
command line option parser for Java applications.
The newest version!
/**********************************************************************
Copyright (c) 2009-2010 Alexander Kerner. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***********************************************************************/
package net.sf.jcmdlineparser.options;
import java.util.ArrayList;
import java.util.Collection;
/**
*
* {@code AbstractMultiOption} is an abstract prototype of
* {@link AbstractOption}.
*
*
* This command line option can have more than one value.
*
*
*
* This class is fully thread save.
*
*
* @author Alexander Kerner
* @version 2010-11-24
*
*/
public abstract class AbstractMultiOption extends AbstractOption {
/**
*
* Delimiter between values.
*
*/
public final static String DELIM_PATTERN = ",";
private volatile Collection values = new ArrayList();
protected AbstractMultiOption(Class returnType, char identifierShort,
String identifierLong, String description, boolean required) {
super(returnType, identifierShort, identifierLong, description,
required);
}
protected AbstractMultiOption(Class returnType, char identifierShort,
String identifierLong, String description, boolean required, Collection extends T> values) {
super(returnType, identifierShort, identifierLong, description,
required);
setValues(values);
}
/**
*
* Get values.
*
* @throws OptionNotSetException
* if this {@link AbstractOption} was not provided on the
* command line
*/
public final synchronized Collection getValues() {
if (this.isSet())
return new ArrayList(values);
throw new OptionNotSetException("option \"" + this + "\" not set");
}
/**
* Set values.
*
* @param values values to set
*/
public final synchronized void setValues(Collection extends T> values) {
this.values.clear();
this.values.addAll(values);
this.setSet(true);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy