use of org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction in project dbeaver by dbeaver.
the class AggregateColumnsPanel method aggregateValues.
private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
List<AggregateFunctionDescriptor> functions = enabledFunctions;
Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
for (AggregateFunctionDescriptor funcDesc : functions) {
TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
funcItem.setData(funcDesc);
funcItem.setText(0, funcDesc.getLabel());
DBPImage icon = funcDesc.getIcon();
if (icon != null) {
funcItem.setImage(0, DBeaverIcons.getImage(icon));
}
try {
IAggregateFunction func = funcDesc.createFunction();
funcMap.put(func, funcItem);
} catch (DBException e) {
log.error(e);
}
}
IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
int[] funcCount = new int[funcs.length];
for (Object element : values) {
for (int i = 0; i < funcs.length; i++) {
if (funcs[i].accumulate(element)) {
funcCount[i]++;
}
}
}
for (int i = 0; i < funcs.length; i++) {
if (funcCount[i] <= 0) {
continue;
}
IAggregateFunction func = funcs[i];
Object result = func.getResult(funcCount[i]);
if (result != null) {
TreeItem treeItem = funcMap.get(func);
String strValue;
if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
strValue = DOUBLE_FORMAT.format(result);
} else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
strValue = INTEGER_FORMAT.format(result);
} else {
strValue = result.toString();
}
treeItem.setText(1, strValue);
}
}
}
use of org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction in project dbeaver by serge-rider.
the class AggregateColumnsPanel method aggregateValues.
private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
List<AggregateFunctionDescriptor> functions = enabledFunctions;
Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
for (AggregateFunctionDescriptor funcDesc : functions) {
TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
funcItem.setData(funcDesc);
funcItem.setText(0, funcDesc.getLabel());
DBPImage icon = funcDesc.getIcon();
if (icon != null) {
funcItem.setImage(0, DBeaverIcons.getImage(icon));
}
try {
IAggregateFunction func = funcDesc.createFunction();
funcMap.put(func, funcItem);
} catch (DBException e) {
log.error(e);
}
}
IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
int[] funcCount = new int[funcs.length];
for (Object element : values) {
for (int i = 0; i < funcs.length; i++) {
if (funcs[i].accumulate(element, aggregateAsStrings)) {
funcCount[i]++;
}
}
}
for (int i = 0; i < funcs.length; i++) {
if (funcCount[i] <= 0) {
continue;
}
IAggregateFunction func = funcs[i];
Object result = func.getResult(funcCount[i]);
if (result != null) {
TreeItem treeItem = funcMap.get(func);
String strValue;
if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
strValue = DOUBLE_FORMAT.format(result);
} else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
strValue = INTEGER_FORMAT.format(result);
} else {
strValue = result.toString();
}
if (strValue != null) {
treeItem.setText(1, strValue);
}
}
}
}
use of org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction in project dbeaver by serge-rider.
the class AggregateColumnsPanel method aggregateValues.
private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
List<AggregateFunctionDescriptor> functions = enabledFunctions;
Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
for (AggregateFunctionDescriptor funcDesc : functions) {
TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
funcItem.setData(funcDesc);
funcItem.setText(0, funcDesc.getLabel());
funcItem.setImage(0, DBeaverIcons.getImage(funcDesc.getIcon()));
try {
IAggregateFunction func = funcDesc.createFunction();
funcMap.put(func, funcItem);
} catch (DBException e) {
log.error(e);
}
}
IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
int[] funcCount = new int[funcs.length];
for (Object element : values) {
for (int i = 0; i < funcs.length; i++) {
if (funcs[i].accumulate(element)) {
funcCount[i]++;
}
}
}
for (int i = 0; i < funcs.length; i++) {
if (funcCount[i] <= 0) {
continue;
}
IAggregateFunction func = funcs[i];
Object result = func.getResult(funcCount[i]);
if (result != null) {
TreeItem treeItem = funcMap.get(func);
String strValue;
if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
strValue = DOUBLE_FORMAT.format(result);
} else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
strValue = INTEGER_FORMAT.format(result);
} else {
strValue = result.toString();
}
treeItem.setText(1, strValue);
}
}
}
Aggregations