KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Row


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 import java.util.List JavaDoc;
18 import java.util.LinkedList JavaDoc;
19
20 /**
21  * See Main.java.
22  */

23 public class Row {
24     
25   /**
26    * Alas, we can't just use a Map to store the (name, value) pairs
27    * because the output will look weird if we don't preserve the column
28    * order. This wouldn't be a problem if we were really inserting into
29    * a database; it only matters because we are displaying the SQL statements
30    * via stdout instead. The LinkedHashMap class would be nice to use, but
31    * that would require java 1.4, so we'll use a list instead, and may as
32    * well call the entries in the list 'Column' objects.
33    */

34   public static class Column {
35       private String JavaDoc name, value;
36       
37       public Column(String JavaDoc name, String JavaDoc value) {
38           this.name = name;
39           this.value = value;
40       }
41       
42       public String JavaDoc getName() {
43           return name;
44       }
45       
46       public String JavaDoc getValue() {
47           return value;
48       }
49   }
50     
51   private LinkedList JavaDoc columns = new LinkedList JavaDoc();
52
53   public Row() {
54   }
55   
56   public void addColumn(String JavaDoc name, String JavaDoc value) {
57       columns.add(new Column(name, value));
58   }
59
60   public List JavaDoc getColumns() {
61       return columns;
62   }
63 }
64
65
Popular Tags