source: branches/0.17.x/abcl/src/org/armedbear/lisp/NilVector.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1/*
2 * NilVector.java
3 *
4 * Copyright (C) 2004-2005 Peter Graves
5 * $Id: NilVector.java 12254 2009-11-06 20:07:54Z ehuelsmann $
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 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public final class NilVector extends AbstractString
37{
38    private int capacity;
39
40    public NilVector(int capacity)
41    {
42        this.capacity = capacity;
43    }
44
45    @Override
46    public char[] chars()
47    {
48        if (capacity != 0)
49            accessError();
50        return new char[0];
51    }
52
53    @Override
54    public char[] getStringChars()
55    {
56        if (capacity != 0)
57            accessError();
58        return new char[0];
59    }
60
61    @Override
62    public String getStringValue()
63    {
64        if (capacity != 0)
65            accessError();
66        return "";
67    }
68
69    @Override
70    public LispObject typeOf()
71    {
72        return list(Symbol.NIL_VECTOR, Fixnum.getInstance(capacity));
73    }
74
75    @Override
76    public LispObject classOf()
77    {
78        return BuiltInClass.NIL_VECTOR;
79    }
80
81    @Override
82    public LispObject typep(LispObject type)
83    {
84        if (type == Symbol.NIL_VECTOR)
85            return T;
86        if (type == Symbol.SIMPLE_STRING)
87            return T;
88        if (type == Symbol.SIMPLE_ARRAY)
89            return T;
90        if (type == BuiltInClass.NIL_VECTOR)
91            return T;
92        if (type == BuiltInClass.SIMPLE_STRING)
93            return T;
94        if (type == BuiltInClass.SIMPLE_ARRAY)
95            return T;
96        return super.typep(type);
97    }
98
99    @Override
100    public LispObject SIMPLE_STRING_P()
101    {
102        return T;
103    }
104
105    @Override
106    public boolean equal(LispObject obj)
107    {
108        if (obj instanceof NilVector) {
109            if (capacity != ((NilVector)obj).capacity)
110                return false;
111            if (capacity != 0) {
112                accessError();
113                // Not reached.
114                return false;
115            }
116            return true;
117        }
118        if (obj instanceof AbstractString) {
119            if (capacity != obj.length())
120                return false;
121            if (capacity != 0) {
122                accessError();
123                // Not reached.
124                return false;
125            }
126            return true;
127        }
128        return false;
129    }
130
131    public String getValue()
132    {
133        if (capacity == 0)
134            return "";
135        accessError();
136        // Not reached.
137        return null;
138    }
139
140    @Override
141    public int length()
142    {
143        return capacity;
144    }
145
146    @Override
147    public int capacity()
148    {
149        return capacity;
150    }
151
152    @Override
153    public LispObject getElementType()
154    {
155        return NIL;
156    }
157
158    @Override
159    public LispObject CHAR(int index)
160    {
161        return accessError();
162    }
163
164    @Override
165    public LispObject SCHAR(int index)
166    {
167        return accessError();
168    }
169
170    @Override
171    public LispObject AREF(int index)
172    {
173        return accessError();
174    }
175
176    @Override
177    public void aset(int index, LispObject newValue)
178    {
179        storeError(newValue);
180    }
181
182    @Override
183    public char charAt(int index)
184    {
185        accessError();
186        // Not reached.
187        return 0;
188    }
189
190    @Override
191    public void setCharAt(int index, char c)
192    {
193        storeError(LispCharacter.getInstance(c));
194    }
195
196    @Override
197    public LispObject subseq(int start, int end)
198    {
199        if (capacity == 0 && start == 0 && end == 0)
200            return this;
201        return accessError();
202    }
203
204    @Override
205    public void fill(LispObject obj)
206    {
207        storeError(obj);
208    }
209
210    @Override
211    public void fill(char c)
212    {
213        storeError(LispCharacter.getInstance(c));
214    }
215
216    @Override
217    public void shrink(int n)
218    {
219    }
220
221    @Override
222    public LispObject reverse()
223    {
224        return accessError();
225    }
226
227    public LispObject accessError()
228    {
229        return error(new TypeError("Attempt to access an array of element type NIL."));
230    }
231
232    private void storeError(LispObject obj)
233    {
234        error(new TypeError(String.valueOf(obj) + " is not of type NIL."));
235    }
236
237    @Override
238    public String toString()
239    {
240        return unreadableString("NIL-VECTOR");
241    }
242
243    @Override
244    public int sxhash()
245    {
246        return 0;
247    }
248
249    @Override
250    public AbstractVector adjustArray(int newCapacity,
251                                       LispObject initialElement,
252                                       LispObject initialContents)
253
254    {
255        accessError();
256        // Not reached.
257        return null;
258    }
259
260    @Override
261    public AbstractVector adjustArray(int size, AbstractArray displacedTo,
262                                       int displacement)
263
264    {
265        accessError();
266        // Not reached.
267        return null;
268    }
269}
Note: See TracBrowser for help on using the repository browser.