Search in sources :

Example 1 with OutputFormFactory

use of org.matheclipse.core.form.output.OutputFormFactory in project symja_android_library by axkr.

the class Symbol method definitionToString.

/** {@inheritDoc} */
@Override
public String definitionToString() throws IOException {
    StringWriter buf = new StringWriter();
    OutputFormFactory off = OutputFormFactory.get(EvalEngine.get().isRelaxedSyntax());
    off.setIgnoreNewLine(true);
    List<IAST> list = definition();
    buf.append("{");
    for (int i = 0; i < list.size(); i++) {
        off.convert(buf, list.get(i));
        if (i < list.size() - 1) {
            buf.append(",\n ");
            off.setColumnCounter(0);
        }
    }
    buf.append("}\n");
    return buf.toString();
}
Also used : StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 2 with OutputFormFactory

use of org.matheclipse.core.form.output.OutputFormFactory in project symja_android_library by axkr.

the class NumberTest method testNumberFormat.

/**
	 * Format a double value with a <code>java.text.DecimalFormat</code> object.
	 */
public void testNumberFormat() {
    StringBuilder buf = new StringBuilder();
    try {
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
        DecimalFormat decimalFormat = new DecimalFormat("0.0####", otherSymbols);
        OutputFormFactory factory = OutputFormFactory.get(true, false, decimalFormat);
        IExpr expr = F.num("12345.123456789");
        factory.convert(buf, expr);
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(buf.toString(), "12345.12346");
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) IExpr(org.matheclipse.core.interfaces.IExpr) IOException(java.io.IOException) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 3 with OutputFormFactory

use of org.matheclipse.core.form.output.OutputFormFactory in project symja_android_library by axkr.

the class PatternMatchingTestCase method check.

public void check(EvalEngine engine, boolean configMode, IAST ast, String strResult) {
    try {
        StringWriter buf = new StringWriter();
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            IAST inExpr = ast;
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER);
            utility.constrainedEval(buf, inExpr);
        } else {
            if (ast != null) {
                OutputFormFactory off = OutputFormFactory.get();
                off.setIgnoreNewLine(true);
                OutputFormFactory.get().convert(buf, ast);
            }
        }
        assertEquals(buf.toString(), strResult);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e, "");
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 4 with OutputFormFactory

use of org.matheclipse.core.form.output.OutputFormFactory in project symja_android_library by axkr.

the class AbstractTestCase method check.

public void check(EvalEngine engine, boolean configMode, IAST ast, String strResult) {
    boolean mode = Config.SERVER_MODE;
    try {
        StringWriter buf = new StringWriter();
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            IAST inExpr = ast;
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER);
            utility.constrainedEval(buf, inExpr);
        } else {
            if (ast != null) {
                OutputFormFactory off = OutputFormFactory.get();
                off.setIgnoreNewLine(true);
                off.convert(buf, ast);
            }
        }
        assertEquals(strResult, buf.toString());
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e);
    } finally {
        Config.SERVER_MODE = mode;
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 5 with OutputFormFactory

use of org.matheclipse.core.form.output.OutputFormFactory in project symja_android_library by axkr.

the class ToString method outputForm.

public static String outputForm(final IExpr expression) {
    try {
        StringBuilder buf = new StringBuilder();
        OutputFormFactory off = OutputFormFactory.get();
        off.setIgnoreNewLine(true);
        off.convert(buf, expression);
        return buf.toString();
    } catch (IOException e) {
        if (Config.SHOW_STACKTRACE) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Aggregations

OutputFormFactory (org.matheclipse.core.form.output.OutputFormFactory)7 StringWriter (java.io.StringWriter)5 TimeConstrainedEvaluator (org.matheclipse.core.eval.TimeConstrainedEvaluator)4 IAST (org.matheclipse.core.interfaces.IAST)4 IOException (java.io.IOException)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 Parser (org.matheclipse.parser.client.Parser)1 ASTNode (org.matheclipse.parser.client.ast.ASTNode)1