public AttributeColumn convertAttributeColumnToNewDynamicColumn(AttributeTable table, AttributeColumn column, double low, double high, boolean lopen, boolean ropen, String newColumnTitle) {
return convertColumnToDynamic(table, column, low, high, lopen, ropen, newColumnTitle);
}
private AttributeColumn convertColumnToDynamic(AttributeTable table, AttributeColumn column, double low, double high, boolean lopen, boolean ropen, String newColumnTitle) {
AttributeType oldType = column.getType();
AttributeType newType = TypeConvertor.getDynamicType(oldType);
if (newColumnTitle != null) {
if (newColumnTitle.equals(column.getTitle())) {
throw new IllegalArgumentException("Column titles can't be equal");
}
}
int oldColumnIndex = column.getIndex();
Attributes rows[] = getTableAttributeRows(table);
Object[] oldValues = new Object[rows.length];
for (int i = 0; i < rows.length; i++) {
oldValues[i] = rows[i].getValue(oldColumnIndex);
}
AttributeColumn newColumn;
if (newColumnTitle == null) {
newColumn = table.replaceColumn(column, column.getId(), column.getTitle(), newType, column.getOrigin(), null);
} else {
newColumn = table.addColumn(newColumnTitle, newColumnTitle, newType, column.getOrigin(), null);
}
int newColumnIndex = newColumn.getIndex();
Object value;
for (int i = 0; i < rows.length; i++) {
if (oldValues[i] != null) {
Interval interval = new Interval(low, high, lopen, ropen, oldValues[i]);
value = newType.createDynamicObject(Arrays.asList(new Interval[]{interval}));
} else {
value = null;
}
rows[i].setValue(newColumnIndex, value);