tbrugz.sqldiff.util.SimilarityCalculator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqldump Show documentation
Show all versions of sqldump Show documentation
Utility to dump schema and data from a RDBMS
package tbrugz.sqldiff.util;
import tbrugz.sqldump.dbmodel.Column;
import tbrugz.sqldump.dbmodel.Table;
public class SimilarityCalculator {
private SimilarityCalculator() {}
static SimilarityCalculator instance = new SimilarityCalculator();
public static SimilarityCalculator instance() {
return instance;
}
public double similarity(Table t1, Table t2) {
final double NAME_WEIGTH = 0.1;
final double SCHEMANAME_WEIGTH = 0.05;
final double COLUMNS_WEIGTH = 0.7;
final double ALL_WEIGTH = NAME_WEIGTH+SCHEMANAME_WEIGTH+COLUMNS_WEIGTH;
double ret = 0;
//name similarity
if(t1.getSchemaName()==null && t2.getSchemaName()==null) {
ret += SCHEMANAME_WEIGTH;
}
else if(t1.getSchemaName()!=null && t1.getSchemaName().equals(t2.getSchemaName())) {
ret += SCHEMANAME_WEIGTH;
}
if(t1.getName().equals(t2.getName())) {
ret += NAME_WEIGTH;
}
//columns similarity
int t1cols = t1.getColumns().size();
int t2cols = t2.getColumns().size();
int sumSize = t1cols+t2cols;
for(int i=0;i