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

com.textrecruit.ustackserverapi.params.OrParam Maven / Gradle / Ivy

There is a newer version: 1.0.31
Show newest version
package com.textrecruit.ustackserverapi.params;

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

import com.textrecruit.ustackserverapi.params.exceptions.ParamGroupException;
import com.textrecruit.ustackserverapi.APIException;
import com.textrecruit.ustackserverapi.CallParameters;

/**
 * Provide validation against one set of parameters OR another
 * 
 * @author jdanner
 *
 */
public class OrParam implements Validated {

	private String name;
	private List params;

	public OrParam(String name) {
		params = new ArrayList();
		this.name = name;
	}
	
	public OrParam add(AndParam param) {
		params.add(param);
		return this;
	}
	
	public OrParam add(OrParam param) {
		params.add(param);
		return this;
	}
	
	public OrParam add(APICallParam param)
	{
		params.add(param);
		return this;
	}

	@Override
	public void validate(CallParameters data) throws APIException {

		ParamGroupException preExcep = new ParamGroupException(name);
		
		for (Validated val : params)
		{
			try {
				val.validate(data);
			} catch (APIException e) {
				preExcep.addException(e);
			}
		}

		if (preExcep.getChildExceptions().size() == params.size())
			throw preExcep;
		
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy