⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functorlist.java

📁 类似于Windows上的Excel
💻 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
 */

package com.wapindustrial.calc;

public abstract class FunctorList extends LispObject {
	
	public final NameObjectBase functor;
	
	public LispObject[] toArray() {
	    int size = listSize();
	    final LispObject args[] = new LispObject[size];
	    args[0] = functor;
	    for(int i=1; i<size; i++)
	        args[i] = getArgumentN(i);
	    return args;
	}
	
	public QuotedList toQuotedList() {
	    return new QuotedList(toArray());
	}
	
    /* (non-Javadoc)
     * @see com.wapindustrial.calc.LispObject#toList()
     */
    FunctorList toList() {
        return this;
    }
    
	/**
	 * Returns functor for n=0, for EMPTY_LIST it's null. 
	 * @param n
	 * @return element of list
	 * @throws IllegalArgumentException if n >= listSize()
	 * @see LispObject#listSize() LispObject#toList()
	 */
	public abstract LispObject getArgumentN(int n);
	
	// these may be overriden by implementation to increase speed
	public LispObject getArgument1() { return getArgumentN(1); }
	public LispObject getArgument2() { return getArgumentN(2); }
	public LispObject getArgument3() { return getArgumentN(3); }
	
	public LispObject evaluateArgN(int narg)  throws EvaluateException  { return getArgumentN(narg).evaluateSExp(); }
	
	// these may be overriden by implementation to increase speed
	public LispObject evaluateArg1() throws EvaluateException { return evaluateArgN(1); }
	public LispObject evaluateArg2() throws EvaluateException { return evaluateArgN(2); }
	public LispObject evaluateArg3() throws EvaluateException { return evaluateArgN(3); }
	
    public LispObject interpretArgN(int narg)  throws EvaluateException  { return getArgumentN(narg).interpret(); }
    
    // these may be overriden by implementation to increase speed
    public LispObject interpretArg1() throws EvaluateException { return interpretArgN(1); }
    public LispObject interpretArg2() throws EvaluateException { return interpretArgN(2); }
    public LispObject interpretArg3() throws EvaluateException { return interpretArgN(3); }
    
	public FunctorList( NameObjectBase functor ) {
		this.functor = functor; 
	}
	
    public void toBuffer( StringBuffer sb ) {
        sb.append( '(' );
        sb.append( functor.getName() );
        LispObject[] args = toArray();
        for( int i=1; i<args.length; i++ ) {
            sb.append( ' ' );
            args[i].toBuffer( sb );
        }
        sb.append( ')' );
    }

    public void toFormulaBuffer( StringBuffer sb ) {
        functor.toFormulaBuffer( sb, this );
    }
    
    public LispObject evaluateSExp() throws EvaluateException {
        return functor.evaluate( this);
    }

    public LispObject shiftReferences(int I1, int J1, int dI, int dJ) {
        boolean rr = false;
        final int size = listSize();
        final LispObject args[] = new LispObject[size];
        args[0] = functor;
        for( int i=1; i<size; i++ ) {
            LispObject lo = getArgumentN(i);
            LispObject newlo = args[i] = lo.shiftReferences( I1, J1, dI, dJ );
            if(lo!=newlo)
                rr = true;
        }
        if(rr)
            return createFunctorList(args);
        return this;
    }

    public LispObject moveReferences(int dI, int dJ) {
        boolean rr = false;
        final int size = listSize();
        final LispObject args[] = new LispObject[size];
        args[0] = functor;
        for( int i=1; i<size; i++ ) {
            LispObject lo = getArgumentN(i);
            LispObject newlo = args[i] = lo.moveReferences(dI, dJ );
            if(lo!=newlo)
                rr = true;
        }
        if(rr)
            return createFunctorList(args);
        return this;
    }

    public final short getShort( int index ) throws EvaluateException {
        LispObject lo = evaluateArgN(index);
        if( lo == NIL )
            return 0;
        return ((ShortAtom)lo).value;
    }
    
    public final short getShort1() throws EvaluateException {
        LispObject lo = evaluateArg1();
        if( lo == NIL )
            return 0;
        return ((ShortAtom)lo).value;
    }

    public final short getShort2() throws EvaluateException {
        LispObject lo = evaluateArg2();
        if( lo == NIL )
            return 0;
        return ((ShortAtom)lo).value;
    }

    public final short getShort3() throws EvaluateException {
        LispObject lo = evaluateArg3();
        if( lo == NIL )
            return 0;
        return ((ShortAtom)lo).value;
    }

    public final Cell getCell( int index ) throws EvaluateException {
        return (Cell)evaluateArgN(index);
    }

    public final Cell getCell1() throws EvaluateException {
        return (Cell)evaluateArg1();
    }
    
    public final Sheet getSheet( int index ) throws EvaluateException {
        return (Sheet)evaluateArgN(index);
    }
    
    public final Sheet getSheet1() throws EvaluateException {
        return (Sheet)evaluateArg1();
    }

    public final boolean getBoolean( int index ) throws EvaluateException {
        LispObject lo = evaluateArgN(index);
        if( lo == NIL )
            return false;
        return ((BooleanAtom)lo).value;
    }

    public final int getInt( int index ) throws EvaluateException {
        LispObject lo = evaluateArgN(index);
        if( lo == NIL )
            return 0;
        return (int)((LongAtom)lo).value;
    }

    public final FloatAtom getFloat( int index ) throws EvaluateException {
        LispObject lo = evaluateArgN(index);
        if( lo == NIL )
            return null;
        return (FloatAtom)lo;
    }
    
    public final String getString( int index ) throws EvaluateException {
        LispObject lo = evaluateArgN(index);
        if( lo == NIL )
            return null;
        if( lo.typeNumber() == TYPE_STRING )
            return ((StringAtomBase)lo).getValue();
        else
            return lo.toString();
    }

    public final String getString1() throws EvaluateException {
        return getString(1);
    }
    public final String getString2() throws EvaluateException {
        return getString(2);
    }
    public final String getString3() throws EvaluateException {
        return getString(3);
    }
    
    public final QuotedList getQuotedList( int index ) throws EvaluateException {
        LispObject lo = evaluateArgN(index);
        if( lo == NIL )
            return null;
        return (QuotedList)lo;
    }
    
    /* (non-Javadoc)
     * @see com.wapindustrial.calc.LispObject#typeNumber()
     */
    public int typeNumber() {
        return TYPE_FUNCTORLIST;
    }
    
//#ifndef MINIMAL_SET                
    public LispObject preprocess(NameObjectBase functor) throws EvaluateException {
		boolean replace = false;
		int len = listSize();
		LispObject newlist[] = new LispObject[len];
		newlist[0] = this.functor;
        for( int i=1; i<len; i++ ) {
        	newlist[i] = getArgumentN(i).preprocess(functor);
        	if(newlist[i] != getArgumentN(i))
        		replace = true;
        }
        FunctorList fl = this;
        if(replace)
        	fl = createFunctorList(newlist);
		if(functor==fl.functor) {
			return fl.evaluateSExp();
		}
		return fl;
	}
//#endif	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -