001: /*
002: * NilVector.java
003: *
004: * Copyright (C) 2004 Peter Graves
005: * $Id: NilVector.java,v 1.12 2004/09/21 00:38:20 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.lisp;
023:
024: public final class NilVector extends AbstractString {
025: private int capacity;
026:
027: public NilVector(int capacity) throws ConditionThrowable {
028: this .capacity = capacity;
029: }
030:
031: public char[] chars() throws ConditionThrowable {
032: if (capacity != 0)
033: accessError();
034: return new char[0];
035: }
036:
037: public char[] getStringChars() throws ConditionThrowable {
038: if (capacity != 0)
039: accessError();
040: return new char[0];
041: }
042:
043: public String getStringValue() throws ConditionThrowable {
044: if (capacity != 0)
045: accessError();
046: return "";
047: }
048:
049: public LispObject typeOf() {
050: return Symbol.NIL_VECTOR;
051: }
052:
053: public LispClass classOf() {
054: return BuiltInClass.NIL_VECTOR;
055: }
056:
057: public LispObject typep(LispObject type) throws ConditionThrowable {
058: if (type == Symbol.NIL_VECTOR)
059: return T;
060: if (type == Symbol.SIMPLE_STRING)
061: return T;
062: if (type == Symbol.STRING)
063: return T;
064: if (type == Symbol.SIMPLE_ARRAY)
065: return T;
066: if (type == BuiltInClass.NIL_VECTOR)
067: return T;
068: if (type == BuiltInClass.STRING)
069: return T;
070: if (type == BuiltInClass.SIMPLE_ARRAY)
071: return T;
072: return super .typep(type);
073: }
074:
075: public LispObject SIMPLE_STRING_P() {
076: return T;
077: }
078:
079: public boolean equal(LispObject obj) throws ConditionThrowable {
080: if (obj instanceof NilVector) {
081: if (capacity != ((NilVector) obj).capacity)
082: return false;
083: if (capacity != 0) {
084: accessError();
085: // Not reached.
086: return false;
087: }
088: return true;
089: }
090: if (obj instanceof AbstractString) {
091: if (capacity != obj.length())
092: return false;
093: if (capacity != 0) {
094: accessError();
095: // Not reached.
096: return false;
097: }
098: return true;
099: }
100: return false;
101: }
102:
103: public String getValue() throws ConditionThrowable {
104: if (capacity == 0)
105: return "";
106: accessError();
107: // Not reached.
108: return null;
109: }
110:
111: public int length() {
112: return capacity;
113: }
114:
115: public int capacity() {
116: return capacity;
117: }
118:
119: public LispObject getElementType() {
120: return NIL;
121: }
122:
123: public LispObject getRowMajor(int index) throws ConditionThrowable {
124: return accessError();
125: }
126:
127: public void setRowMajor(int index, LispObject newValue)
128: throws ConditionThrowable {
129: storeError(newValue);
130: }
131:
132: public char getChar(int index) throws ConditionThrowable {
133: accessError();
134: // Not reached.
135: return 0;
136: }
137:
138: public void setChar(int index, char c) throws ConditionThrowable {
139: storeError(LispCharacter.getInstance(c));
140: }
141:
142: public LispObject subseq(int start, int end)
143: throws ConditionThrowable {
144: if (capacity == 0 && start == 0 && end == 0)
145: return this ;
146: return accessError();
147: }
148:
149: public void fill(LispObject obj) throws ConditionThrowable {
150: storeError(obj);
151: }
152:
153: public void fill(char c) throws ConditionThrowable {
154: storeError(LispCharacter.getInstance(c));
155: }
156:
157: public void shrink(int n) throws ConditionThrowable {
158: }
159:
160: public LispObject reverse() throws ConditionThrowable {
161: return accessError();
162: }
163:
164: public LispObject accessError() throws ConditionThrowable {
165: return signal(new TypeError(
166: "Attempt to access an array of element type NIL."));
167: }
168:
169: private void storeError(LispObject obj) throws ConditionThrowable {
170: signal(new TypeError(String.valueOf(obj)
171: + " is not of type NIL."));
172: }
173:
174: public String toString() {
175: return unreadableString("NIL-VECTOR");
176: }
177:
178: public int sxhash() throws ConditionThrowable {
179: if (capacity != 0)
180: accessError();
181: return 0;
182: }
183:
184: public AbstractVector adjustVector(int newCapacity,
185: LispObject initialElement, LispObject initialContents)
186: throws ConditionThrowable {
187: accessError();
188: // Not reached.
189: return null;
190: }
191:
192: public AbstractVector adjustVector(int size,
193: AbstractArray displacedTo, int displacement)
194: throws ConditionThrowable {
195: accessError();
196: // Not reached.
197: return null;
198: }
199: }
|