01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.synth.sql;
07:
08: import java.sql.ResultSet;
09: import java.sql.SQLException;
10:
11: /**
12: * Represents a row.
13: */
14: class Row implements Comparable {
15: private Value[] data;
16:
17: public Row(TestSynth config, ResultSet rs, int len)
18: throws SQLException {
19: data = new Value[len];
20: for (int i = 0; i < len; i++) {
21: data[i] = Value.read(config, rs, i + 1);
22: }
23: }
24:
25: public String toString() {
26: String s = "";
27: for (int i = 0; i < data.length; i++) {
28: Object o = data[i];
29: s += o == null ? "NULL" : o.toString();
30: s += "; ";
31: }
32: return s;
33: }
34:
35: public int compareTo(Object o) {
36: Row r2 = (Row) o;
37: int result = 0;
38: for (int i = 0; i < data.length && result == 0; i++) {
39: Object o1 = data[i];
40: Object o2 = r2.data[i];
41: if (o1 == null) {
42: result = (o2 == null) ? 0 : -1;
43: } else if (o2 == null) {
44: result = 1;
45: } else {
46: result = o1.toString().compareTo(o2.toString());
47: }
48: }
49: return result;
50: }
51:
52: }
|