📄 nameobjectbase.java
字号:
/*
* MC2 -- j2me spreadsheet
*
* Copyright (c) 2004-2006 Michael Zemljanukha (mixaz@mail.ru)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* NameObject.java
*
* Created on December 15, 2003, 4:09 PM
*/
package com.wapindustrial.calc;
public abstract class NameObjectBase extends LispObject {
public abstract String getName();
/**
* Returns the object this name maps to
*
* @return The object this name maps to. NIL if the name is unmapped
*/
public abstract LispObject getMappedObject();
/**
* Maps the name to an object
* @param mapTo object to map to
* @throws EvaluateException if the name is immutable, and cannot be changed (for a system name)
*/
public LispObject setMappedObject(LispObject mapTo) throws EvaluateException {
throw new EvaluateException("name of this type cannot be set");
}
// evaluates as a function in functor
// performs delayed mapping of mapto
public LispObject evaluate( FunctorList functor ) throws EvaluateException {
try {
FunctionObject fo = (FunctionObject) getMappedObject();
try {
return fo.evaluate( functor );
}
catch (ArrayIndexOutOfBoundsException cce) {
cce.printStackTrace();
throw new EvaluateException("Wrong number of arguments", functor);
}
catch( IllegalArgumentException ee ) {
throw new EvaluateException("Wrong arguments for a MIDP functions", functor);
}
catch (ClassCastException cce) {
throw new EvaluateException("Type mismatch", functor);
}
}
catch (ClassCastException cce) {
throw new EvaluateException("Not a functor", functor);
}
}
public LispObject evaluateSExp() throws EvaluateException {
try {
return getMappedObject().evaluateSExp();
}
catch( NullPointerException ee ) {
throw new EvaluateException( "unmapped name?", this );
}
}
public void toBuffer( StringBuffer sb ) {
sb.append( getName() );
}
public void toFormulaBuffer( StringBuffer sb, FunctorList fl ) {
int size = fl.listSize();
sb.append( getName() );
sb.append( '(' );
for( int i=1; i<size; i++ ) {
if( i != 1 )
sb.append( ',' );
fl.getArgumentN(i).toFormulaBuffer( sb );
}
sb.append( ')' );
}
//#ifdef JAVA_COMPILER
public String getNameLabel() {
String constName = getName().toUpperCase();
constName = constName.replace('-','_');
constName = constName.replace('$','_');
constName = constName.replace('.','_');
return constName;
}
//#endif
//#ifndef MINIMAL_SET
/* (non-Javadoc)
* @see com.wapindustrial.calc.LispObject#preprocess(com.wapindustrial.calc.NameObjectBase)
*/
public LispObject preprocess(NameObjectBase functor) throws EvaluateException {
if(functor==this)
return evaluateSExp();
return this;
}
//#endif
/* (non-Javadoc)
* @see com.wapindustrial.calc.LispObject#typeNumber()
*/
public int typeNumber() {
// TODO Auto-generated method stub
return TYPE_REFERENCE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -