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

org.unix4j.codegen.optset.Constraints Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.unix4j.codegen.command.def.CommandDef;
import org.unix4j.codegen.command.def.OptionDef;
import org.unix4j.codegen.optset.constraint.EnabledOptionConstraint;
import org.unix4j.codegen.optset.constraint.ExclusiveOptionConstraint;
import org.unix4j.codegen.optset.constraint.OptionConstraint;

public class Constraints {
	
	public static Collection getOptionConstraints(CommandDef commandDef) {
		final List constraints = new ArrayList();
		addExclusiveOptionConstraints(commandDef, constraints);
		addEnabledOptionConstraints(commandDef, constraints);
		return constraints;
	}

	private static void addExclusiveOptionConstraints(CommandDef commandDef, List constraints) {
		for (final OptionDef opt : commandDef.options.values()) {
			if (!opt.excludes.isEmpty()) {
				constraints.add(new ExclusiveOptionConstraint(opt.name, opt.excludes));
			}
		}
	}
	private static void addEnabledOptionConstraints(CommandDef commandDef, List constraints) {
		for (final OptionDef opt : commandDef.options.values()) {
			if (!opt.enabledBy.isEmpty()) {
				constraints.add(new EnabledOptionConstraint(opt.name, opt.enabledBy));
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy