Exemplo n.º 1
0
 private boolean containedIn(ResultSet ors) {
   if (ors.getColumnCount() != getColumnCount()) {
     return false;
   }
   // look for a match for each row of this ResultSet
   for (int irow = 0; irow < getRowCount(); irow++) {
     // there is a match only if there is some row in the other ResultSet in which each column
     // matches
     boolean foundMatchingRow = false;
     for (int otherRow = 0; otherRow < ors.getRowCount(); otherRow++) {
       boolean rowMatches = true;
       for (int icol = 0; icol < getColumnCount(); icol++) {
         if (!valuesMatch(getResultAt(irow, icol), ors.getResultAt(otherRow, icol))) {
           // this row doesn't match
           rowMatches = false;
           break;
         }
       }
       if (rowMatches) {
         // we've found a match for this row
         foundMatchingRow = true;
         break;
       }
     }
     if (!foundMatchingRow) {
       return false;
     }
   }
   return false;
 }
Exemplo n.º 2
0
  /**
   * Compare this ResultSet to the argument ResultSet. Two ResultSets are equal if every row in one
   * is equal to some row in the other and there are no extra rows.
   */
  public boolean equals(Object otherObj) {
    if (!(otherObj instanceof ResultSet)) {
      return false;
    }
    ResultSet ors = (ResultSet) otherObj;
    if (ors.getColumnCount() != getColumnCount()) {
      return false;
    }
    if (ors.getRowCount() != getRowCount()) {
      return false;
    }

    // look for a match for each row of this ResultSet
    for (int irow = 0; irow < getRowCount(); irow++) {
      // there is a match only if there is some row in the other ResultSet in which each column
      // matches
      boolean foundMatchingRow = false;
      for (int otherRow = 0; otherRow < getRowCount(); otherRow++) {
        boolean rowMatches = true;
        for (int icol = 0; icol < getColumnCount(); icol++) {
          if (!valuesMatch(getResultAt(irow, icol), ors.getResultAt(otherRow, icol))) {
            // this row doesn't match
            rowMatches = false;
            break;
          }
        }
        if (rowMatches) {
          // we've found a match for this row
          foundMatchingRow = true;
          break;
        }
      }
      if (!foundMatchingRow) {
        return false;
      }
    }
    return true;
  }