package com.d2yml.tool.Vcharts;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class VchartsUtil {
public List<String> columns = new ArrayList<>();
public List<Map<String, Object>> rows = new ArrayList<>();
public List<String> getColumns() {
return columns;
}
public void setColumns(String columns) {
this.columns.add(columns);
}
public List<Map<String, Object>> getRows() {
return rows;
}
public boolean setRows(Map<String, Object> rows) {
boolean add = this.rows.add(rows);
return add;
}
public myRow createRow() {
Map<String, Object> map = new HashMap<String, Object>();
return new myRow(map);
}
@Override
public String toString() {
return "VchartsUtil [columns=" + columns + ", rows=" + rows + "]";
}
public static void main(String[] args) {
VchartsUtil v = new VchartsUtil();
v.setColumns("aaa");
v.setColumns("bbb");
v.createRow().set("a1", 1).set("a2", 2).set("a3", 3).commit(v);
}
}
class myRow {
Map<String, Object> map = new HashMap<String, Object>();
public myRow(Map<String, Object> map2) {
this.map = map2;
}
public myRow set(String key, Object value) {
map.put(key, value);
return this;
}
public boolean commit(VchartsUtil v) {
if (map.size() > v.getColumns().size()) {
throw new IndexOutOfBoundsException("row长度: " + map.size() + " 超出所设置的column长度: " + v.getColumns().size());
}
return v.setRows(map);
}
}