//package edu.gsu.cs.dbengine; import java.util.*; public class Tuple { public Vector attributes; public Vector domains; public Comparable [] tuple; Tuple (Comparable [] tup, Vector attr, Vector dom) { attributes = new Vector(); for (int i=0; i")) return (!lopValue.equals(ropValue)); else if (comparison.equals("<")) return (lopValue.compareTo(ropValue) < 0); else if (comparison.equals(">")) return (lopValue.compareTo(ropValue) > 0); else if (comparison.equals("<=")) return (lopValue.compareTo(ropValue) <= 0); else if (comparison.equals(">=")) return (lopValue.compareTo(ropValue) >= 0); } else if (lopType.equals("num") && ropType.equals("num")) { double lval = Double.parseDouble(lopValue); double rval = Double.parseDouble(ropValue); if (comparison.equals("=")) return (lval == rval); else if (comparison.equals("<>")) return (lval != rval); else if (comparison.equals("<")) return (lval < rval); else if (comparison.equals(">")) return (lval > rval); else if (comparison.equals("<=")) return (lval <= rval); else if (comparison.equals(">=")) return (lval >= rval); } else if (lopType.equals("col") && ropType.equals("num")) { int index = attributes.indexOf(lopValue); String lcolType = (String) domains.elementAt(index); if (lcolType.equals("INTEGER")) { Integer lvall = (Integer) tuple[index]; double lval = lvall.doubleValue(); double rval = Double.parseDouble(ropValue); if (comparison.equals("=")) return (lval == rval); else if (comparison.equals("<>")) return (lval != rval); else if (comparison.equals("<")) return (lval < rval); else if (comparison.equals(">")) return (lval > rval); else if (comparison.equals("<=")) return (lval <= rval); else if (comparison.equals(">=")) return (lval >= rval); } else { Double lvall = (Double) tuple[index]; double lval = lvall.doubleValue(); double rval = Double.parseDouble(ropValue); if (comparison.equals("=")) return (lval == rval); else if (comparison.equals("<>")) return (lval != rval); else if (comparison.equals("<")) return (lval < rval); else if (comparison.equals(">")) return (lval > rval); else if (comparison.equals("<=")) return (lval <= rval); else if (comparison.equals(">=")) return (lval >= rval); } } else if (lopType.equals("col") && ropType.equals("str")) { int index = attributes.indexOf(lopValue); String lcolType = (String) domains.elementAt(index); if (lcolType.equals("VARCHAR")) { String lval = (String) tuple[index]; if (comparison.equals("=")) return lval.equals(ropValue); else if (comparison.equals("<>")) return (!lval.equals(ropValue)); else if (comparison.equals("<")) return (lval.compareTo(ropValue) < 0); else if (comparison.equals(">")) return (lval.compareTo(ropValue) > 0); else if (comparison.equals("<=")) return (lval.compareTo(ropValue) <= 0); else if (comparison.equals(">=")) return (lval.compareTo(ropValue) >= 0); } } else if (lopType.equals("num") && ropType.equals("col")) { int index = attributes.indexOf(ropValue); String rcolType = (String) domains.elementAt(index); if (rcolType.equals("INTEGER")) { Integer rvall = (Integer) tuple[index]; double rval = rvall.doubleValue(); double lval = Double.parseDouble(lopValue); if (comparison.equals("=")) return (lval == rval); else if (comparison.equals("<>")) return (lval != rval); else if (comparison.equals("<")) return (lval < rval); else if (comparison.equals(">")) return (lval > rval); else if (comparison.equals("<=")) return (lval <= rval); else if (comparison.equals(">=")) return (lval >= rval); } else { Double rvall = (Double) tuple[index]; double rval = rvall.doubleValue(); double lval = Double.parseDouble(lopValue); if (comparison.equals("=")) return (lval == rval); else if (comparison.equals("<>")) return (lval != rval); else if (comparison.equals("<")) return (lval < rval); else if (comparison.equals(">")) return (lval > rval); else if (comparison.equals("<=")) return (lval <= rval); else if (comparison.equals(">=")) return (lval >= rval); } } else if (lopType.equals("str") && ropType.equals("col")) { int index = attributes.indexOf(ropValue); String rcolType = (String) domains.elementAt(index); if (rcolType.equals("VARCHAR")) { String rval = (String) tuple[index]; if (comparison.equals("=")) return lopValue.equals(rval); else if (comparison.equals("<>")) return (!lopValue.equals(rval)); else if (comparison.equals("<")) return (lopValue.compareTo(rval) < 0); else if (comparison.equals(">")) return (lopValue.compareTo(rval) > 0); else if (comparison.equals("<=")) return (lopValue.compareTo(rval) <= 0); else if (comparison.equals(">=")) return (lopValue.compareTo(rval) >= 0); } } else if (lopType.equals("col") && ropType.equals("col")) { int lIndex = attributes.indexOf(lopValue); int rIndex = attributes.indexOf(ropValue); String lcolType = (String) domains.elementAt(lIndex); String rcolType = (String) domains.elementAt(rIndex); if (lcolType.equals("VARCHAR") && rcolType.equals("VARCHAR")) { String lval = (String) tuple[lIndex]; String rval = (String) tuple[rIndex]; if (comparison.equals("=")) return lval.equals(rval); else if (comparison.equals("<>")) return (!lval.equals(rval)); else if (comparison.equals("<")) return (lval.compareTo(rval) < 0); else if (comparison.equals(">")) return (lval.compareTo(rval) > 0); else if (comparison.equals("<=")) return (lval.compareTo(rval) <= 0); else if (comparison.equals(">=")) return (lval.compareTo(rval) >= 0); } else { // both columns are numeric (INTEGER or DECIMAL) double lval = 0.0; if (lcolType.equals("INTEGER")) { Integer lvall = (Integer) tuple[lIndex]; lval = lvall.doubleValue(); } else { Double lvall = (Double) tuple[lIndex]; lval = lvall.doubleValue(); } double rval = 0.0; if (rcolType.equals("INTEGER")) { Integer rvall = (Integer) tuple[rIndex]; rval = rvall.doubleValue(); } else { Double rvall = (Double) tuple[rIndex]; rval = rvall.doubleValue(); } if (comparison.equals("=")) return (lval == rval); else if (comparison.equals("<>")) return (lval != rval); else if (comparison.equals("<")) return (lval < rval); else if (comparison.equals(">")) return (lval > rval); else if (comparison.equals("<=")) return (lval <= rval); else if (comparison.equals(">=")) return (lval >= rval); } } return false; } String extractColumnValueAsString(String colName) { int index = attributes.indexOf(colName); String colType = (String) domains.elementAt(index); String cval = null; if (colType.equals("VARCHAR")) cval = (String) tuple[index]; else if (colType.equals("INTEGER")) { Integer ival = (Integer) tuple[index]; cval = "" + ival.intValue(); } else { Double dval = (Double) tuple[index]; cval = "" + dval.doubleValue(); } return cval; } void printTuple() { for (int i=0; i