package com.tandbergtv.watchpoint.pmm.web.formbeans.title;

import java.util.ArrayList;
import java.util.List;

import com.tandbergtv.watchpoint.pmm.web.util.CustomArrayList;

/**
 * Represents a Title in UI.
 * 
 * @author Raj Prakash
 */
public class TitleData {
	private int id;
	private String name;
	private List<Variable> variables = new CustomArrayList<Variable>(Variable.class);
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the variables
	 */
	public List<Variable> getVariables() {
		return variables;
	}
	/**
	 * @param variables the variables to set
	 */
	public void setVariables(List<Variable> variables) {
		this.variables = variables;
	}
	
	/**
	 * Checks if this titleData has any variables.
	 */
	public boolean hasVariables() {
		return variables != null && !variables.isEmpty();
	}
	
	/**
	 * Adds the given variable to the collection of variables.
	 */
	public void addVariable(Variable v) {
		if(variables == null)
			variables = new ArrayList<Variable>();
		variables.add(v);
	}
	
	/**
	 * Gets variable of the given name. If not found, null is returned.
	 */
	public Variable getVariableByName(String name) {
		if(variables != null)
			for(Variable v : variables)
				if(v.getName().equals(name))
					return v;
		return null;
	}
}
