页面树结构
转至元数据结尾
转至元数据起始

正在查看旧版本。 查看 当前版本.

与当前比较 查看页面历史

« 前一个 版本 2 当前 »

示例代码:

package smartbi;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import smartbi.freequery.metadata.IJavaQueryData;
import smartbi.freequery.metadata.JavaQueryConfig;
import smartbi.freequery.metadata.JavaQueryOutputField;
import smartbi.freequery.metadata.JavaQueryParameter;
import smartbi.freequery.querydata.CellData;
import smartbi.freequery.querydata.GridData;
import smartbi.net.sf.json.JSONObject;
import smartbi.util.StringUtil;
import smartbi.util.ValueType;
public class IntegerGenerator implements IJavaQueryData {
	private static final Random RANDOM = new Random();
	private Integer max = null;
	private Integer min = null;
	/** {@inheritDoc} */
	public void close() {
	}
	/** {@inheritDoc} */
	public List<JavaQueryConfig> getConfigs() {
		return new ArrayList<JavaQueryConfig>();
	}
	/** {@inheritDoc} */
	public GridData getGridData(int from, int count) {
		GridData grid = new GridData();
		List<String> headers = new ArrayList<String>();
		for (JavaQueryOutputField f : getOutputFields()) {
			headers.add(f.getId());
		}
		grid.setStringHeaders(headers);
		List<List<CellData>> data = new ArrayList<List<CellData>>();
		for (int i = from, len = from + count; i < len; i++) {
			List<CellData> row = new ArrayList<CellData>();
			CellData cell = new CellData();
			cell.setType(ValueType.INTEGER);
			cell.setIntValue(generateRandomIntValue());
			row.add(cell);
			data.add(row);
		}
		grid.setData(data);
		return grid;
	}
	private int generateRandomIntValue() {
		int value = RANDOM.nextInt();
		if (min == null && max == null) {
			//
		} else if (min == null) {
			value = RANDOM.nextInt(max);
		} else if (max == null) {
			value = Math.abs(value) + min;
		} else {
			int v0 = Math.min(max, min);
			int v1 = Math.max(max, min);
			value = RANDOM.nextInt(v1) % (v1 - v0 + 1) + v0;
		}
		return value;
	}
	/** {@inheritDoc} */
	public List<JavaQueryOutputField> getOutputFields() {
		List<JavaQueryOutputField> result = new ArrayList<JavaQueryOutputField>();
		result.add(new JavaQueryOutputField("Integer", "Integer", "Integer", "", ValueType.INTEGER, ""));
		return result;
	}
	/** {@inheritDoc} */
	public List<JavaQueryParameter> getParameters() {
		List<JavaQueryParameter> result = new ArrayList<JavaQueryParameter>();
		result.add(new JavaQueryParameter("Max", "Max", "最大值", "", ValueType.INTEGER, true));
		result.add(new JavaQueryParameter("Min", "Min", "最小值", "", ValueType.INTEGER, true));
    /** true代表非必填,允许为空*/
		return result;
	}
	/** {@inheritDoc} */
	public int getRowCount() {
		return Integer.MAX_VALUE;
	}
	/** {@inheritDoc} */
	public void init() {
	}
	/** {@inheritDoc} */
	public void loadConfigs(String configs) {
	}
	/** {@inheritDoc} */
	public String saveConfigs() {
		return new JSONObject().toString();
	}
	/** {@inheritDoc} */
	public void setConfigValue(String key, String value) {
	}
	/** {@inheritDoc} */
	public void setConfigValues(Map<String, String> configValues) {
	}
	/** {@inheritDoc} */
	public void setParameterValue(String id, String value, String displayValue) {
		if (StringUtil.isNullOrEmpty(value)) {
			return;
		} else if ("Max".equals(id)) {
			try {
				max = Double.valueOf(value).intValue();
			} catch (NumberFormatException e) {
				max = null;
			}
		} else if ("Min".equals(id)) {
			try {
				min = Double.valueOf(value).intValue();
			} catch (NumberFormatException e) {
				min = null;
			}
		}
	}
}

  • 无标签