package model;

import java.util.Comparator;

/**
 * Immutable class indicating the SQL component for a Node.
 * @author keping
 *
 */
public class NodeInfo {
	// TODO: all fields should be private in final version.
	private String type; 
	private String value;
	/**
	 * Similarity score of the Node to the column/table name in schema.
	 */
	private double score = 1.0;
	
	public NodeInfo(String type, String value) {
		this.type = type;
		this.value = value;
	}
	public NodeInfo(String type, String value, double score) {
		this(type, value);
		this.score = score;
	}
	public NodeInfo(NodeInfo ni){
		this.type = ni.type;
		this.value = ni.value;
		this.score = ni.score;
	}
	@Override
	public String toString() {
		return type+": "+value;
	}
	public String getType() { return type; }
	public String getValue() {
		return value;
	}
	
	public double getScore(){
		return score;
	}
	
	public static class ReverseScoreComparator implements Comparator<NodeInfo> {
		@Override
		public int compare(NodeInfo a, NodeInfo b) {
			if (a.score < b.score) { return 1; }
			else if (a.score > b.score) { return -1; }
			else { return 0; }
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		result = prime * result + ((value == null) ? 0 : value.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;
		NodeInfo other = (NodeInfo) obj;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}

	
}

@@ -1841,12 +1841,268 @@
 ue;%0A%09%7D%0A%0A
+%09public boolean sameSchema (NodeInfo other) %7B%0A%0A%09%09if (type == null %7C%7C other.type == null %7C%7C value == null %7C%7C other.value == null) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%0A%09%09if (type.equals(other.type) && value.equals(other.value)) %7B%0A%0A%09%09%09return true;%0A%09%09%7D%0A%0A%09%09return false;%0A%09%7D%0A
 %09%0A%7D%0A

check schema function added