2022-05-06 01:51:35 +00:00
|
|
|
package dev.plex.toml;
|
2015-06-27 21:35:26 +00:00
|
|
|
|
2015-07-02 05:31:51 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2022-05-06 01:51:35 +00:00
|
|
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
|
|
|
|
|
|
|
class TableArrayValueWriter extends ArrayValueWriter
|
|
|
|
{
|
2015-06-27 19:50:15 +00:00
|
|
|
static final ValueWriter TABLE_ARRAY_VALUE_WRITER = new TableArrayValueWriter();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canWrite(Object value) {
|
|
|
|
return isArrayish(value) && !isArrayOfPrimitive(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-02 05:41:22 +00:00
|
|
|
public void write(Object from, WriterContext context) {
|
|
|
|
Collection<?> values = normalize(from);
|
2015-06-27 19:50:15 +00:00
|
|
|
|
2015-06-28 17:30:35 +00:00
|
|
|
WriterContext subContext = context.pushTableFromArray();
|
2015-06-27 19:50:15 +00:00
|
|
|
|
2015-07-02 05:41:22 +00:00
|
|
|
for (Object value : values) {
|
|
|
|
WRITERS.findWriterFor(value).write(value, subContext);
|
2015-06-27 19:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-27 21:35:26 +00:00
|
|
|
|
|
|
|
private TableArrayValueWriter() {}
|
2015-06-28 21:35:39 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "table-array";
|
|
|
|
}
|
2015-06-27 19:50:15 +00:00
|
|
|
}
|