import java.util.*;

import yass.YassSong;
import yass.filter.YassFilter;

/**
 *  Description of the Class
 *
 * @author     Yass Along
 * @created    4. März 2008
 */
public class CustomEditionFilter extends YassFilter {

	/**
	 *  Gets the iD attribute of the CustomEditionFilter object
	 *
	 * @return    The iD value
	 */
	public String getID() {
		return "custom_edition";
	}


	/**
	 *  Gets the label attribute of the CustomEditionFilter object
	 *
	 * @return    The label value
	 */
	public String getLabel() {
		return "Custom Edition";
	}


	/**
	 *  Gets the genericRules attribute of the YassEditionFilter object
	 *
	 * @param  data  Description of the Parameter
	 * @return       The genericRules value
	 */
	public String[] getGenericRules(Vector data) {
		Vector editions = new Vector();
		for (Enumeration e = data.elements(); e.hasMoreElements(); ) {
			YassSong s = (YassSong) e.nextElement();
			String edition = s.getEdition();
			if (edition == null || edition.length() < 1) {
				continue;
			}
			if (!editions.contains(edition)) {
				editions.addElement(edition);
			}
		}
		Collections.sort(editions);

		return (String[]) editions.toArray(new String[]{});
	}


	/**
	 *  Description of the Method
	 *
	 * @param  rule  Description of the Parameter
	 * @return       Description of the Return Value
	 */
	public boolean allowDrop(String rule) {
		if (rule.equals("All")) {
			return false;
		}
		if (rule.equals("Unspecified")) {
			return false;
		}
		return true;
	}


	/**
	 *  Description of the Method
	 *
	 * @param  rule  Description of the Parameter
	 * @return       Description of the Return Value
	 */
	public boolean allowCoverDrop(String rule) {
		if (rule.equals("All")) {
			return false;
		}
		if (rule.equals("Unspecified")) {
			return false;
		}
		return true;
	}


	/**
	 *  Description of the Method
	 *
	 * @param  rule  Description of the Parameter
	 * @param  s     Description of the Parameter
	 */
	public void drop(String rule, YassSong s) {
		String old = s.getEdition();
		if (old == null || old.equals(rule)) {
			return;
		}

		s.setEdition(rule);
		s.setSaved(false);
	}


	/**
	 *  Description of the Method
	 *
	 * @param  s  Description of the Parameter
	 * @return    Description of the Return Value
	 */
	public boolean accept(YassSong s) {
		String t = s.getEdition();
		boolean hit = false;

		if (rule.equals("All")) {
			hit = true;
		} else if (rule.equals("Unspecified")) {
			if (t == null || t.length() < 1) {
				hit = true;
			}
		} else {
			hit = t.equals(rule);
		}

		return hit;
	}
}


