use of org.matheclipse.core.interfaces.IAssociation in project symja_android_library by axkr.
the class ASTDataset method normal.
@Override
public IASTAppendable normal(boolean nilIfUnevaluated) {
Cache<IAST, IAST> cache = CacheBuilder.newBuilder().maximumSize(500).build();
final List<String> names = fTable.columnNames();
List<IStringX> namesStr = new ArrayList<IStringX>(names.size());
for (int i = 0; i < names.size(); i++) {
namesStr.add(F.stringx(names.get(i)));
}
if (names.size() == 1) {
Column<?> column = fTable.column(names.get(0));
ColumnType t = column.type();
IASTAppendable resultList = F.ListAlloc(column.size());
for (int j = 0; j < column.size(); j++) {
Object obj = column.get(j);
IExpr expr = F.NIL;
expr = dataToExpr(obj, t);
resultList.append(expr);
}
return resultList;
}
IASTAppendable list = F.ListAlloc(names.size());
int size = fTable.rowCount();
for (int k = 0; k < size; k++) {
Row row = fTable.row(k);
IAssociation assoc = F.assoc();
for (int j = 0; j < row.columnCount(); j++) {
String columnName = names.get(j);
IStringX colName = namesStr.get(j);
ColumnType t = row.getColumnType(columnName);
Object obj = row.getObject(j);
if (t.equals(ColumnType.EXPR)) {
IExpr expr = (IExpr) obj;
ruleCache(cache, assoc, F.Rule(colName, expr));
} else if (t.equals(ColumnType.BOOLEAN)) {
Boolean b = row.getBoolean(j);
if (b) {
ruleCache(cache, assoc, F.Rule(colName, S.True));
} else {
ruleCache(cache, assoc, F.Rule(colName, S.False));
}
} else if (t.equals(ColumnType.SHORT)) {
short sValue = row.getShort(j);
ruleCache(cache, assoc, F.Rule(colName, F.ZZ(sValue)));
} else if (t.equals(ColumnType.INTEGER)) {
int iValue = row.getInt(j);
ruleCache(cache, assoc, F.Rule(colName, F.ZZ(iValue)));
} else if (t.equals(ColumnType.LONG)) {
long lValue = row.getLong(j);
ruleCache(cache, assoc, F.Rule(colName, F.ZZ(lValue)));
} else if (t.equals(ColumnType.FLOAT)) {
float fValue = row.getFloat(j);
ruleCache(cache, assoc, F.Rule(colName, F.num(fValue)));
} else if (t.equals(ColumnType.DOUBLE)) {
double dValue = row.getDouble(j);
ruleCache(cache, assoc, F.Rule(colName, F.num(dValue)));
} else if (t.equals(ColumnType.STRING)) {
ruleCache(cache, assoc, F.Rule(colName, F.stringx(row.getString(j))));
} else if (t.equals(ColumnType.LOCAL_DATE_TIME)) {
LocalDateTime lDate = row.getDateTime(j);
ruleCache(cache, assoc, F.Rule(colName, DateObjectExpr.newInstance(lDate)));
} else if (t.equals(ColumnType.LOCAL_DATE)) {
LocalDate lDate = row.getDate(j);
ruleCache(cache, assoc, F.Rule(colName, DateObjectExpr.newInstance(lDate.atStartOfDay())));
} else if (t.equals(ColumnType.LOCAL_TIME)) {
LocalTime lTime = row.getTime(j);
ruleCache(cache, assoc, F.Rule(colName, TimeObjectExpr.newInstance(lTime)));
} else if (t.equals(ColumnType.SKIP)) {
// ruleCache(cache, assoc, F.Rule(colName, F.Missing));
ruleCache(cache, assoc, F.Rule(colName, F.Missing(S.NotAvailable)));
} else {
IExpr valueStr = F.stringx(obj.toString());
ruleCache(cache, assoc, F.Rule(colName, valueStr));
}
}
if (size == 1) {
return assoc;
}
list.append(assoc);
}
return list;
}
use of org.matheclipse.core.interfaces.IAssociation in project symja_android_library by axkr.
the class VisitorLevelSpecification method visit.
@Override
public IExpr visit(IAssociation assoc) {
IAssociation[] result = new IAssociation[] { F.NIL };
if (assoc.isPresent()) {
int[] minDepth = new int[] { 0 };
try {
fCurrentLevel++;
if (fIncludeHeads) {
// no include head for associations
}
assoc.forEach((x, i) -> {
final IExpr temp = x.accept(this);
if (temp.isPresent()) {
if (!result[0].isPresent()) {
result[0] = createResult(assoc, temp);
}
result[0].set(i, assoc.getRule(i).setAtCopy(2, temp));
}
if (fCurrentDepth < minDepth[0]) {
minDepth[0] = fCurrentDepth;
}
});
} finally {
fCurrentLevel--;
}
fCurrentDepth = --minDepth[0];
if (isInRange(fCurrentLevel, minDepth[0])) {
if (!result[0].isPresent()) {
return fFunction.apply(assoc);
} else {
IExpr temp = fFunction.apply(result[0]);
if (temp.isPresent()) {
return temp;
}
}
}
}
return result[0];
}
Aggregations