use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method booleanLogicOperationsMerge.
@Override
public Column booleanLogicOperationsMerge(Table table, Column[] columnsToMerge, BooleanOperations[] booleanOperations, String newColumnTitle) {
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
if (table == null || columnsToMerge == null || booleanOperations == null || booleanOperations.length != columnsToMerge.length - 1) {
throw new IllegalArgumentException("table, columns or operations can't be null and operations length must be columns length -1");
}
for (Column column : columnsToMerge) {
if (!column.getTypeClass().equals(Boolean.class)) {
throw new IllegalArgumentException("All columns have to be boolean columns");
}
}
Column newColumn;
newColumn = ac.addAttributeColumn(table, newColumnTitle, Boolean.class);
if (newColumn == null) {
return null;
}
Boolean value;
Boolean secondValue;
for (Element row : ac.getTableAttributeRows(table)) {
value = (Boolean) row.getAttribute(columnsToMerge[0]);
// Use false if null
value = value != null ? value : false;
for (int i = 0; i < booleanOperations.length; i++) {
secondValue = (Boolean) row.getAttribute(columnsToMerge[i + 1]);
// Use false if null
secondValue = secondValue != null ? secondValue : false;
switch(booleanOperations[i]) {
case AND:
value = value && secondValue;
break;
case OR:
value = value || secondValue;
break;
case XOR:
value = value ^ secondValue;
break;
case NAND:
value = !(value && secondValue);
break;
case NOR:
value = !(value || secondValue);
break;
}
}
row.setAttribute(newColumn, value);
}
return newColumn;
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method minValueNumbersMerge.
@Override
public Column minValueNumbersMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Column newColumn;
// Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
if (newColumn == null) {
return null;
}
BigDecimal min;
for (Element row : ac.getTableAttributeRows(table)) {
min = StatisticsUtils.minValue(ac.getRowNumbers(row, columnsToMerge));
row.setAttribute(newColumn, min);
}
return newColumn;
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method firstQuartileNumberMerge.
@Override
public Column firstQuartileNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Column newColumn;
// Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
if (newColumn == null) {
return null;
}
BigDecimal Q1;
for (Element row : ac.getTableAttributeRows(table)) {
Q1 = StatisticsUtils.quartile1(ac.getRowNumbers(row, columnsToMerge));
row.setAttribute(newColumn, Q1);
}
return newColumn;
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class ClearColumnData method canManipulateColumn.
@Override
public boolean canManipulateColumn(Table table, Column column) {
boolean result;
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
result = ac.canClearColumnData(column);
// Also make sure that there is at least 1 row
return result && ac.getTableRowsCount(table) > 0;
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class EditEdges method prepareEdgesAttributes.
/**
* Prepare set of attributes of the edges.
*
* @return Set of these attributes
*/
private Sheet.Set prepareEdgesAttributes() {
try {
// DynamicModel dm=Lookup.getDefault().lookup(DynamicController.class).getModel();
// if(dm!=null){
// currentTimeFormat=dm.getTimeFormat();
// }
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Sheet.Set set = new Sheet.Set();
set.setName("attributes");
if (edges.length > 1) {
set.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.attributes.text.multiple"));
} else {
set.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.attributes.text", edges[0].getLabel()));
}
Edge row = edges[0];
AttributeValueWrapper wrap;
for (Column column : row.getAttributeColumns()) {
if (multipleEdges) {
wrap = new MultipleRowsAttributeValueWrapper(edges, column, currentTimeFormat, dateTimeZone);
} else {
wrap = new SingleRowAttributeValueWrapper(edges[0], column, currentTimeFormat, dateTimeZone);
}
Class<?> type = column.getTypeClass();
Property p;
PropertyEditor propEditor = PropertyEditorManager.findEditor(type);
if (ac.canChangeColumnData(column)) {
// Editable column, provide "set" method:
if (propEditor != null && !type.isArray()) {
// The type can be edited by default:
p = new PropertySupport.Reflection(wrap, type, "getValue" + type.getSimpleName(), "setValue" + type.getSimpleName());
} else {
// Use the AttributeType as String:
p = new PropertySupport.Reflection(wrap, String.class, "getValueAsString", "setValueAsString");
}
} else // Not editable column, do not provide "set" method:
{
if (propEditor != null) {
// The type can be edited by default:
p = new PropertySupport.Reflection(wrap, type, "getValue" + type.getSimpleName(), null);
} else {
// Use the AttributeType as String:
p = new PropertySupport.Reflection(wrap, String.class, "getValueAsString", null);
}
}
p.setDisplayName(column.getTitle());
p.setName(column.getId());
set.put(p);
}
return set;
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
Aggregations