KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > synth > Row


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.test.synth;
6
7 import java.sql.*;
8
9 class Row implements Comparable JavaDoc {
10     private Value[] data;
11
12     public Row(TestSynth config, ResultSet rs, int len) throws SQLException {
13         data = new Value[len];
14         for(int i = 0; i<len; i++) {
15             data[i] = Value.read(config, rs, i+1);
16         }
17     }
18     
19     public String JavaDoc toString() {
20         String JavaDoc s = "";
21         for(int i = 0; i<data.length; i++) {
22             Object JavaDoc o = data[i];
23             s += o==null ? "NULL" : o.toString();
24             s += "; ";
25         }
26         return s;
27     }
28     
29     public int compareTo(Object JavaDoc o) {
30         Row r2 = (Row)o;
31         int result = 0;
32         for(int i=0; i<data.length && result==0; i++) {
33             Object JavaDoc o1 = data[i];
34             Object JavaDoc o2 = r2.data[i];
35             if(o1==null) {
36                 result = (o2==null) ? 0 : -1;
37             } else if(o2==null) {
38                 result = 1;
39             } else {
40                 result = o1.toString().compareTo(o2.toString());
41             }
42         }
43         return result;
44     }
45     
46 }
47
Popular Tags