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

org.unix4j.codegen.optset.constraint.ExclusiveOptionConstraint Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.codegen.optset.constraint;

import java.util.Set;

/**
 * Constraint for a set of options that are excluded if a certain option is
 * active.
 */
public class ExclusiveOptionConstraint implements OptionConstraint {

	private final String option;
	private final Set excluded;

	/**
	 * Constructor with option and set of excluded options if {@code option} is
	 * active.
	 * 
	 * @param option
	 *            the option (long) name; if active the {@code excluded} options
	 *            are not allowed to be active
	 * @param excluded
	 *            the (long) names of options that cannot be active if
	 *            {@code option} is active
	 */
	public ExclusiveOptionConstraint(String option, Set excluded) {
		this.option = option;
		this.excluded = excluded;
	}

	@Override
	public boolean isValidActiveSet(Set activeSet) {
		if (activeSet.contains(option)) {
			for (final String dont : excluded) {
				if (activeSet.contains(dont)) {
					return false;
				}
			}
		}
		return true;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy