1 | /* ============================================================= |
2 | * SmallSQL : a free Java DBMS library for the Java(tm) platform |
3 | * ============================================================= |
4 | * |
5 | * (C) Copyright 2004-2006, by Volker Berlin. |
6 | * |
7 | * Project Info: http://www.smallsql.de/ |
8 | * |
9 | * This library is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU Lesser General Public License as published by |
11 | * the Free Software Foundation; either version 2.1 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, but |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 | * License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Lesser General Public |
20 | * License along with this library; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
22 | * USA. |
23 | * |
24 | * [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
25 | * in the United States and other countries.] |
26 | * |
27 | * --------------- |
28 | * Columns.java |
29 | * --------------- |
30 | * Author: Volker Berlin |
31 | * |
32 | */ |
33 | package smallsql.database; |
34 | |
35 | /** |
36 | * A typed implementation of Arraylist for Column. |
37 | * This list is used to descript the meta data of a ResultSet and to descript a Table. |
38 | * |
39 | * @author Volker Berlin |
40 | * |
41 | */ |
42 | final class Columns { |
43 | private int size; |
44 | private Column[] data; |
45 | |
46 | Columns(){ |
47 | data = new Column[16]; |
48 | } |
49 | |
50 | /*Columns(int initSize){ |
51 | data = new Column[initSize]; |
52 | }*/ |
53 | |
54 | final int size(){ |
55 | return size; |
56 | } |
57 | |
58 | final Column get(int idx){ |
59 | if (idx >= size) |
60 | throw new IndexOutOfBoundsException("Column index: "+idx+", Size: "+size); |
61 | return data[idx]; |
62 | } |
63 | |
64 | final void add(Column expr){ |
65 | if(size >= data.length ){ |
66 | resize(size << 1); |
67 | } |
68 | data[size++] = expr; |
69 | } |
70 | |
71 | /*final void add(int idx, Column expr){ |
72 | if(size >= data.length ){ |
73 | resize(size << 1); |
74 | } |
75 | System.arraycopy( data, idx, data, idx+1, (size++)-idx); |
76 | data[idx] = expr; |
77 | } |
78 | |
79 | final void addAll(Columns cols){ |
80 | int count = cols.size(); |
81 | if(size + count >= data.length ){ |
82 | resize(size + count); |
83 | } |
84 | System.arraycopy( cols.data, 0, data, size, count); |
85 | size += count; |
86 | } |
87 | |
88 | final void clear(){ |
89 | size = 0; |
90 | } |
91 | |
92 | final void remove(int idx){ |
93 | System.arraycopy( data, idx+1, data, idx, (--size)-idx); |
94 | }*/ |
95 | |
96 | /*final void set(int idx, Column expr){ |
97 | data[idx] = expr; |
98 | } |
99 | |
100 | final int indexOf(Column expr) { |
101 | if (expr == null) { |
102 | for (int i = 0; i < size; i++) |
103 | if (data[i]==null) |
104 | return i; |
105 | } else { |
106 | for (int i = 0; i < size; i++) |
107 | if (expr.equals(data[i])) |
108 | return i; |
109 | } |
110 | return -1; |
111 | }*/ |
112 | |
113 | private final void resize(int newSize){ |
114 | Column[] dataNew = new Column[newSize]; |
115 | System.arraycopy(data, 0, dataNew, 0, size); |
116 | data = dataNew; |
117 | } |
118 | } |