Search in sources :

Example 6 with Object

use of java.lang.Object in project clochure by videlalvaro.

the class LispReader method interpretToken.

private static Object interpretToken(String s) {
    if (s.equals("nil")) {
        return null;
    } else if (s.equals("true")) {
        return RT.T;
    } else if (s.equals("false")) {
        return RT.F;
    } else if (s.equals("/")) {
        return SLASH;
    } else if (s.equals("clojure.core//")) {
        return CLOJURE_SLASH;
    }
    Object ret = null;
    ret = matchSymbol(s);
    if (ret != null)
        return ret;
    throw Util.runtimeException("Invalid token: " + s);
}
Also used : Object(java.lang.Object)

Example 7 with Object

use of java.lang.Object in project clochure by videlalvaro.

the class LispReader method readDelimitedList.

public static List readDelimitedList(char delim, PushbackReader r, boolean isRecursive) {
    final int firstline = (r instanceof LineNumberingPushbackReader) ? ((LineNumberingPushbackReader) r).getLineNumber() : -1;
    ArrayList a = new ArrayList();
    for (; ; ) {
        int ch = read1(r);
        while (isWhitespace(ch)) ch = read1(r);
        if (ch == -1) {
            if (firstline < 0)
                throw Util.runtimeException("EOF while reading");
            else
                throw Util.runtimeException("EOF while reading, starting at line " + firstline);
        }
        if (ch == delim)
            break;
        IFn macroFn = getMacro(ch);
        if (macroFn != null) {
            Object mret = macroFn.invoke(r, (char) ch);
            //no op macros return the reader
            if (mret != r)
                a.add(mret);
        } else {
            unread(r, ch);
            Object o = read(r, true, null, isRecursive);
            if (o != r)
                a.add(o);
        }
    }
    return a;
}
Also used : ArrayList(java.util.ArrayList) Object(java.lang.Object)

Example 8 with Object

use of java.lang.Object in project clochure by videlalvaro.

the class LispReader method read.

public static Object read(PushbackReader r, boolean eofIsError, Object eofValue, boolean isRecursive) {
    if (RT.READEVAL.deref() == UNKNOWN)
        throw Util.runtimeException("Reading disallowed - *read-eval* bound to :unknown");
    try {
        for (; ; ) {
            int ch = read1(r);
            while (isWhitespace(ch)) ch = read1(r);
            if (ch == -1) {
                if (eofIsError)
                    throw Util.runtimeException("EOF while reading");
                return eofValue;
            }
            if (Character.isDigit(ch)) {
                Object n = readNumber(r, (char) ch);
                if (RT.suppressRead())
                    return null;
                return n;
            }
            IFn macroFn = getMacro(ch);
            if (macroFn != null) {
                Object ret = macroFn.invoke(r, (char) ch);
                if (RT.suppressRead())
                    return null;
                //no op macros return the reader
                if (ret == r)
                    continue;
                return ret;
            }
            if (ch == '+' || ch == '-') {
                int ch2 = read1(r);
                if (Character.isDigit(ch2)) {
                    unread(r, ch2);
                    Object n = readNumber(r, (char) ch);
                    if (RT.suppressRead())
                        return null;
                    return n;
                }
                unread(r, ch2);
            }
            String token = readToken(r, (char) ch);
            if (RT.suppressRead())
                return null;
            return interpretToken(token);
        }
    } catch (Exception e) {
        if (isRecursive || !(r instanceof LineNumberingPushbackReader))
            throw Util.sneakyThrow(e);
        LineNumberingPushbackReader rdr = (LineNumberingPushbackReader) r;
        //throw Util.runtimeException(String.format("ReaderError:(%d,1) %s", rdr.getLineNumber(), e.getMessage()), e);
        throw new ReaderException(rdr.getLineNumber(), rdr.getColumnNumber(), e);
    }
}
Also used : Object(java.lang.Object) String(java.lang.String) IllegalStateException(java.lang.IllegalStateException) UnsupportedOperationException(java.lang.UnsupportedOperationException) IOException(java.io.IOException) NumberFormatException(java.lang.NumberFormatException) RuntimeException(java.lang.RuntimeException) IllegalArgumentException(java.lang.IllegalArgumentException) Exception(java.lang.Exception)

Example 9 with Object

use of java.lang.Object in project dhis2-core by dhis2.

the class ArithmeticMean method run.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void run(Stack inStack) throws ParseException {
    checkStack(inStack);
    Object param = inStack.pop();
    if (param instanceof List) {
        List<Double> vals = CustomFunctions.checkVector(param);
        int n = vals.size();
        if (n == 0) {
            inStack.push(new Double(0));
        } else {
            double sum = 0;
            for (Double v : vals) {
                sum = sum + v;
            }
            inStack.push(new Double(sum / n));
        }
    } else {
        throw new ParseException("Invalid aggregate value in expression");
    }
}
Also used : Object(java.lang.Object) List(java.util.List) ParseException(org.nfunk.jep.ParseException)

Example 10 with Object

use of java.lang.Object in project dhis2-core by dhis2.

the class MedianValue method run.

// nFunk's JEP run() method uses the raw Stack type
@SuppressWarnings({ "rawtypes", "unchecked" })
public void run(Stack inStack) throws ParseException {
    checkStack(inStack);
    Object param = inStack.pop();
    List<Double> vals = CustomFunctions.checkVector(param);
    int n = vals.size();
    // Sort it here
    if (n % 2 == 0) {
        inStack.push(new Double((vals.get(n / 2) + vals.get(n / 2 + 1)) / 2));
    } else {
        inStack.push(new Double(vals.get((n + 1) / 2)));
    }
}
Also used : Object(java.lang.Object)

Aggregations

Object (java.lang.Object)26 String (java.lang.String)7 IOException (java.io.IOException)4 NumberFormatException (java.lang.NumberFormatException)4 Override (java.lang.Override)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 List (java.util.List)3 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Exception (java.lang.Exception)2 IllegalArgumentException (java.lang.IllegalArgumentException)2 IllegalStateException (java.lang.IllegalStateException)2 RuntimeException (java.lang.RuntimeException)2 StringBuilder (java.lang.StringBuilder)2 UnsupportedOperationException (java.lang.UnsupportedOperationException)2 SeekableByteChannel (java.nio.channels.SeekableByteChannel)2 FileSystem (java.nio.file.FileSystem)2 Path (java.nio.file.Path)2