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