126 lines
2.6 KiB
Java
126 lines
2.6 KiB
Java
import java.util.ArrayList;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @author Lublena
|
|
*
|
|
*/
|
|
public class EQDependency extends Dependency
|
|
{
|
|
//ArrayList<Term> left; // the terms on the left side of the dependency
|
|
//ArrayList<Term> right; // the terms on the right side of the dependency
|
|
|
|
ArrayList left; // the terms on the left side of the dependency
|
|
ArrayList right; // the terms on the right side of the dependency
|
|
|
|
public EQDependency()
|
|
{
|
|
type = 1;
|
|
//left = new ArrayList<Term>();
|
|
//right = new ArrayList<Term>();
|
|
|
|
left = new ArrayList();
|
|
right = new ArrayList();
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see Dependency#toString()
|
|
*/
|
|
public String toString()
|
|
{
|
|
if (left.isEmpty() || right.isEmpty())
|
|
{
|
|
return null;
|
|
}
|
|
|
|
StringBuffer sb = new StringBuffer(left.get(0).toString());
|
|
|
|
|
|
for (int i = 1; i < left.size(); ++i)
|
|
{
|
|
sb.append(" and " + left.get(i).toString());
|
|
}
|
|
|
|
// Append the right side of the functional dependency
|
|
sb.append(" => " + right.get(0).toString());
|
|
return sb.toString();
|
|
}
|
|
/*
|
|
* Returns an ArrayList of the column names appearing in the dependency.
|
|
*/
|
|
public ArrayList getColumns()
|
|
{
|
|
// ArrayList<String> result = new ArrayList<String>();
|
|
ArrayList result = new ArrayList();
|
|
for (int i = 0; i < left.size(); ++i)
|
|
{
|
|
String col = ((Term) left.get(i)).left;
|
|
result.add(col);
|
|
}
|
|
result.add(((Term) right.get(0)).left);
|
|
|
|
return result;
|
|
}
|
|
/*
|
|
* Returns an ArrayList of the terms in the dependency.
|
|
*/
|
|
public ArrayList getTerms()
|
|
{
|
|
//ArrayList<Term> result = new ArrayList<Term>();
|
|
ArrayList result = new ArrayList();
|
|
result.addAll(left);
|
|
result.addAll(right);
|
|
return result;
|
|
}
|
|
|
|
/*
|
|
* Returns an ArrayList of the terms in the dependency, where the operation in the
|
|
* term on the right-hand side is reversed.
|
|
*/
|
|
public ArrayList getRTerms()
|
|
{
|
|
ArrayList result = new ArrayList();
|
|
result.addAll(left);
|
|
Term t = (Term) right.get(0);
|
|
result.add(new Term(t.left, reverseOp(t.op), t.right));
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @param op The comparison operator to reverse.
|
|
* @return The reversed comparison operator for the input operator.
|
|
*/
|
|
private String reverseOp(String op)
|
|
{
|
|
String result = null;
|
|
if (op.equals("="))
|
|
{
|
|
result = "!=";
|
|
}
|
|
else if (op.equals("!=") || op.equals("<>"))
|
|
{
|
|
result = "=";
|
|
}
|
|
else if (op.equals("<"))
|
|
{
|
|
result = ">=";
|
|
}
|
|
else if (op.equals("<="))
|
|
{
|
|
result = ">";
|
|
}
|
|
else if (op.equals(">"))
|
|
{
|
|
result = "<=";
|
|
}
|
|
else if (op.equals(">="))
|
|
{
|
|
result = "<";
|
|
}
|
|
return result;
|
|
}
|
|
}
|