package com.k_int.discover.service;

import java.util.Arrays;

/**
 * Simple class to handle keeping together the Solr name, Xpath expression and whether or
 * not a value is required
 * 
 * @author rpb <rich@k-int.com>
 * 
 */
public class NameXPathMapping  implements java.io.Serializable {

	private static final long serialVersionUID = -4453726572805312843L;
	public String solrName = "";
	public String xpathExpression = "";
	public String[] values = null;
	public boolean required = false;
	public boolean collectAll = false;

	public NameXPathMapping(String solrName, String xpathExpression, String[] values, boolean required, boolean collectAll) {
		this.setSolrName(solrName);
		this.setXpathExpression(xpathExpression);
		this.setValues(values);
		this.setRequired(required);
		this.setCollectAll(collectAll);
	}

	public NameXPathMapping(String solrName, String xpathExpression, String[] values, boolean required) {
		this.setSolrName(solrName);
		this.setXpathExpression(xpathExpression);
		this.setValues(values);
		this.setRequired(required);
	}

	public NameXPathMapping(String solrName, String xpathExpression, boolean required, boolean collectAll) {
		this.setSolrName(solrName);
		this.setXpathExpression(xpathExpression);
		this.setRequired(required);
		this.setCollectAll(collectAll);
	}

	public NameXPathMapping(String solrName, String xpathExpression, boolean required) {
		this.setSolrName(solrName);
		this.setXpathExpression(xpathExpression);
		this.setRequired(required);
	}

	public String getSolrName() {
		return solrName;
	}

	public void setSolrName(String solrName) {
		if ( solrName != null ) {
			this.solrName = solrName;
		}
	}

	public String getXpathExpression() {
		return xpathExpression;
	}

	public void setXpathExpression(String xpathExpression) {
		if ( xpathExpression != null ) {
			this.xpathExpression = xpathExpression;
		}
	}

	public boolean isRequired() {
		return required;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}

	
	public String[] getValues() {
		return values;
	}

	public void setValues(String[] values) {
		if ( values != null ) {
			this.values = values;
		}
	}
	
	public boolean getCollectAll() {
		return collectAll;
	}
	
	public void setCollectAll(boolean collectAll) {
		this.collectAll = collectAll;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (collectAll ? 1231 : 1237);
		result = prime * result + (required ? 1231 : 1237);
		result = prime * result
				+ ((solrName == null) ? 0 : solrName.hashCode());
		result = prime * result + Arrays.hashCode(values);
		result = prime * result
				+ ((xpathExpression == null) ? 0 : xpathExpression.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NameXPathMapping other = (NameXPathMapping) obj;
		if (collectAll != other.collectAll)
			return false;
		if (required != other.required)
			return false;
		if (solrName == null) {
			if (other.solrName != null)
				return false;
		} else if (!solrName.equals(other.solrName))
			return false;
		if (!Arrays.equals(values, other.values))
			return false;
		if (xpathExpression == null) {
			if (other.xpathExpression != null)
				return false;
		} else if (!xpathExpression.equals(other.xpathExpression))
			return false;
		return true;
	}
	
	
}
