s4553711
7/1/2015 - 6:34 AM

Compare two list with type ColInfo

Compare two list with type ColInfo

public void test() {
	RemoteTool cmd = new RemoteTool();
	Map<ColInfo, Integer> tmp = new HashMap<>();
	DatabaseSchemaInfo result = parserSchema(cmd.exec("psql -U rd hipipe -c '\\d "+target+"'").split("\n"));
	DatabaseSchemaInfo result2 = parserSchema(getSqlFromDisk(target+".sql"));
			
	System.out.println("--1-start---");
	for(ColInfo col : result.getCols()) {
		tmp.put(col, 1);
	}
	System.out.println("--1-end---");
			
	System.out.println("--2-start---");
	for(ColInfo col : result2.getCols()) {
		if (tmp.containsKey(col)) {
			tmp.put(col, 2);
		}  else {
			tmp.put(col, 3);
		}
	}
	System.out.println("--2-end---");
			
	System.out.println("--3-start---");
	Map<String, String> errorCol = new HashMap<>();
	for(ColInfo info : tmp.keySet()) {
		if (tmp.get(info) == 1 || tmp.get(info) == 3) {
			System.out.println("> "+target+" 1/3 : "+info.getName());
			if (errorCol.containsKey(info.getName())) {
				String old = errorCol.get(info.getName());
				errorCol.put(info.getName(), old+" <-> "+info.getType()+", "+info.getModifier());
			} else {
				errorCol.put(info.getName(), info.getType()+", "+info.getModifier());
			}
			verdict = false;
		} else if (tmp.get(info) == 2) {
			System.out.println("> "+target+" 2 : "+info.getName());
		}
	}
	for(String i : errorCol.keySet()){
		System.out.println(i+" >>> "+errorCol.get(i));
	}
	System.out.println("--3-end---");
}
package ibms.gp.bioinfo.monitor.util;

import org.apache.commons.lang.builder.HashCodeBuilder;

public class ColInfo {
	private String name;
	private String type;
	private String modifier;

	public ColInfo (String name, String type, String modifier) {
		this.name = name;
		this.type = type;
		this.modifier = modifier;
	}

	public boolean equals(Object obj) {
		//System.out.println("Compare equals ...");
		ColInfo tar = (ColInfo)obj;
		if (this.name.equals(tar.getName()) && this.type.equals(tar.getType()) && this.modifier.equals(tar.getModifier())) {
			return true;
		} else {
			return false;
		}
	}
	
	public int hashCode() {
		//System.out.println("Compare hashcode ...");
		return new HashCodeBuilder(1, 1).append(name).append(type).append(modifier).toHashCode();
	}
	
	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public String getModifier() {
		return modifier;
	}
}