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);
}
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;
}
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);
}
}
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");
}
}
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)));
}
}
Aggregations