001package org.unix4j.codegen.optset.constraint;
002
003import java.util.Set;
004
005/**
006 * Constraint for a set of options that are excluded if a certain option is
007 * active.
008 */
009public class ExclusiveOptionConstraint implements OptionConstraint {
010
011        private final String option;
012        private final Set<String> excluded;
013
014        /**
015         * Constructor with option and set of excluded options if {@code option} is
016         * active.
017         * 
018         * @param option
019         *            the option (long) name; if active the {@code excluded} options
020         *            are not allowed to be active
021         * @param excluded
022         *            the (long) names of options that cannot be active if
023         *            {@code option} is active
024         */
025        public ExclusiveOptionConstraint(String option, Set<String> excluded) {
026                this.option = option;
027                this.excluded = excluded;
028        }
029
030        @Override
031        public boolean isValidActiveSet(Set<String> activeSet) {
032                if (activeSet.contains(option)) {
033                        for (final String dont : excluded) {
034                                if (activeSet.contains(dont)) {
035                                        return false;
036                                }
037                        }
038                }
039                return true;
040        }
041
042}