net.sf.jcmdlineparser.options.VoidOption Maven / Gradle / Ivy
/**********************************************************************
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.Set;
import net.sf.jcmdlineparser.ParserException;
/**
*
* An {@code VoidOption} represents a command line option that has no values at
* all.
*
*
* Example:
*
* -
* {@code -v}
* -
* {@code --void}
*
*
*
* @author Alexander Kerner
* @version 2010-08-10
* @see AbstractOption
*
*/
public class VoidOption extends AbstractOption {
protected VoidOption(Class returnType, char identifierShort,
String identifierLong, String description, boolean required) {
super(returnType, identifierShort, identifierLong, description,
required);
}
protected VoidOption(Class returnType, char identifierShort,
String identifierLong, String description, boolean required,
Set> clashOptions) {
super(returnType, identifierShort, identifierLong, description,
required);
}
@Override
public synchronized void parse(String string) throws ParserException {
// this option has no value. any parsing meains a programming error.
if (string == null || string.length() == 0 || string.equals("")) {
// not good but OK
// this.setSet(true);
} else {
throw new ParserException();
}
}
@Override
public void setSet(boolean set) {
// Make this option public, since "AbstractOption#setSet(boolean)" is called in
// "AbstractOption#setValue(T)" , which is not available to VoidOption.
super.setSet(set);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy