All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.unicore.ucc.UCCOptions Maven / Gradle / Ivy

The newest version!
package eu.unicore.ucc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

/**
 * Collection of options for commandline, checking if option names (both long and short) are unique.
 * Adding an option with already taken name results in IllegalArgumentException.
* * This class also allows to handle multiple groups of options, to improve printing usage info
* * It is not thread-safe.
* * @author kstasiak * @author schuller */ public class UCCOptions extends Options { private static final long serialVersionUID = 1L; private final Set usedOptionNames=new HashSet(); public static final String GRP_DEFAULT="__DEFAULT__"; public static final String GRP_GENERAL="__GENERAL__"; public static final String GRP_SECURITY="__SECURITY__"; public static final String GRP_VO="__VO__"; private final Map> optionGroups=new HashMap>(); private void markAsUsed(String optionName) { if(usedOptionNames.contains(optionName)) { throw new IllegalArgumentException("The option \'"+optionName+ "\' has already been registered before."); } usedOptionNames.add(optionName); } @Override public Options addOption(Option option){ //add to default option group return addOption(option, GRP_DEFAULT); } public Options addOption(Option option, String optionGroup){ markAsUsed(option.getLongOpt()); markAsUsed(option.getOpt()); Options result = super.addOption(option); List




© 2015 - 2024 Weber Informatics LLC | Privacy Policy