KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > NilVector


1 /*
2  * NilVector.java
3  *
4  * Copyright (C) 2004 Peter Graves
5  * $Id: NilVector.java,v 1.12 2004/09/21 00:38:20 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.lisp;
23
24 public final class NilVector extends AbstractString
25 {
26     private int capacity;
27
28     public NilVector(int capacity) throws ConditionThrowable
29     {
30         this.capacity = capacity;
31     }
32
33     public char[] chars() throws ConditionThrowable
34     {
35         if (capacity != 0)
36             accessError();
37         return new char[0];
38     }
39
40     public char[] getStringChars() throws ConditionThrowable
41     {
42         if (capacity != 0)
43             accessError();
44         return new char[0];
45     }
46
47     public String JavaDoc getStringValue() throws ConditionThrowable
48     {
49         if (capacity != 0)
50             accessError();
51         return "";
52     }
53
54     public LispObject typeOf()
55     {
56         return Symbol.NIL_VECTOR;
57     }
58
59     public LispClass classOf()
60     {
61         return BuiltInClass.NIL_VECTOR;
62     }
63
64     public LispObject typep(LispObject type) throws ConditionThrowable
65     {
66         if (type == Symbol.NIL_VECTOR)
67             return T;
68         if (type == Symbol.SIMPLE_STRING)
69             return T;
70         if (type == Symbol.STRING)
71             return T;
72         if (type == Symbol.SIMPLE_ARRAY)
73             return T;
74         if (type == BuiltInClass.NIL_VECTOR)
75             return T;
76         if (type == BuiltInClass.STRING)
77             return T;
78         if (type == BuiltInClass.SIMPLE_ARRAY)
79             return T;
80         return super.typep(type);
81     }
82
83     public LispObject SIMPLE_STRING_P()
84     {
85         return T;
86     }
87
88     public boolean equal(LispObject obj) throws ConditionThrowable
89     {
90         if (obj instanceof NilVector) {
91             if (capacity != ((NilVector)obj).capacity)
92                 return false;
93             if (capacity != 0) {
94                 accessError();
95                 // Not reached.
96
return false;
97             }
98             return true;
99         }
100         if (obj instanceof AbstractString) {
101             if (capacity != obj.length())
102                 return false;
103             if (capacity != 0) {
104                 accessError();
105                 // Not reached.
106
return false;
107             }
108             return true;
109         }
110         return false;
111     }
112
113     public String JavaDoc getValue() throws ConditionThrowable
114     {
115         if (capacity == 0)
116             return "";
117         accessError();
118         // Not reached.
119
return null;
120     }
121
122     public int length()
123     {
124         return capacity;
125     }
126
127     public int capacity()
128     {
129         return capacity;
130     }
131
132     public LispObject getElementType()
133     {
134         return NIL;
135     }
136
137     public LispObject getRowMajor(int index) throws ConditionThrowable
138     {
139         return accessError();
140     }
141
142     public void setRowMajor(int index, LispObject newValue) throws ConditionThrowable
143     {
144         storeError(newValue);
145     }
146
147     public char getChar(int index) throws ConditionThrowable
148     {
149         accessError();
150         // Not reached.
151
return 0;
152     }
153
154     public void setChar(int index, char c) throws ConditionThrowable
155     {
156         storeError(LispCharacter.getInstance(c));
157     }
158
159     public LispObject subseq(int start, int end) throws ConditionThrowable
160     {
161         if (capacity == 0 && start == 0 && end == 0)
162             return this;
163         return accessError();
164     }
165
166     public void fill(LispObject obj) throws ConditionThrowable
167     {
168         storeError(obj);
169     }
170
171     public void fill(char c) throws ConditionThrowable
172     {
173         storeError(LispCharacter.getInstance(c));
174     }
175
176     public void shrink(int n) throws ConditionThrowable
177     {
178     }
179
180     public LispObject reverse() throws ConditionThrowable
181     {
182         return accessError();
183     }
184
185     public LispObject accessError() throws ConditionThrowable
186     {
187         return signal(new TypeError("Attempt to access an array of element type NIL."));
188     }
189
190     private void storeError(LispObject obj) throws ConditionThrowable
191     {
192         signal(new TypeError(String.valueOf(obj) + " is not of type NIL."));
193     }
194
195     public String JavaDoc toString()
196     {
197         return unreadableString("NIL-VECTOR");
198     }
199
200     public int sxhash() throws ConditionThrowable
201     {
202         if (capacity != 0)
203             accessError();
204         return 0;
205     }
206
207     public AbstractVector adjustVector(int newCapacity,
208                                        LispObject initialElement,
209                                        LispObject initialContents)
210         throws ConditionThrowable
211     {
212         accessError();
213         // Not reached.
214
return null;
215     }
216
217     public AbstractVector adjustVector(int size, AbstractArray displacedTo,
218                                        int displacement)
219         throws ConditionThrowable
220     {
221         accessError();
222         // Not reached.
223
return null;
224     }
225 }
226
Popular Tags