}
public CTCols addCleanColIntoCols(CTCols cols, CTCol col) {
boolean colOverlaps = false;
for (int i = 0; i < cols.sizeOfColArray(); i++) {
CTCol ithCol = cols.getColArray(i);
long[] range1 = { ithCol.getMin(), ithCol.getMax() };
long[] range2 = { col.getMin(), col.getMax() };
long[] overlappingRange = NumericRanges.getOverlappingRange(range1,
range2);
int overlappingType = NumericRanges.getOverlappingType(range1,
range2);
// different behavior required for each of the 4 different
// overlapping types
if (overlappingType == NumericRanges.OVERLAPS_1_MINOR) {
ithCol.setMax(overlappingRange[0] - 1);
CTCol rangeCol = insertCol(cols, overlappingRange[0],
overlappingRange[1], new CTCol[] { ithCol, col });
i++;
CTCol newCol = insertCol(cols, (overlappingRange[1] + 1), col
.getMax(), new CTCol[] { col });
i++;
} else if (overlappingType == NumericRanges.OVERLAPS_2_MINOR) {
ithCol.setMin(overlappingRange[1] + 1);
CTCol rangeCol = insertCol(cols, overlappingRange[0],
overlappingRange[1], new CTCol[] { ithCol, col });
i++;
CTCol newCol = insertCol(cols, col.getMin(),
(overlappingRange[0] - 1), new CTCol[] { col });
i++;
} else if (overlappingType == NumericRanges.OVERLAPS_2_WRAPS) {
setColumnAttributes(col, ithCol);
if (col.getMin() != ithCol.getMin()) {
CTCol newColBefore = insertCol(cols, col.getMin(), (ithCol
.getMin() - 1), new CTCol[] { col });
i++;
}
if (col.getMax() != ithCol.getMax()) {
CTCol newColAfter = insertCol(cols, (ithCol.getMax() + 1),
col.getMax(), new CTCol[] { col });
i++;
}
} else if (overlappingType == NumericRanges.OVERLAPS_1_WRAPS) {
if (col.getMin() != ithCol.getMin()) {
CTCol newColBefore = insertCol(cols, ithCol.getMin(), (col
.getMin() - 1), new CTCol[] { ithCol });
i++;
}
if (col.getMax() != ithCol.getMax()) {
CTCol newColAfter = insertCol(cols, (col.getMax() + 1),
ithCol.getMax(), new CTCol[] { ithCol });
i++;
}
ithCol.setMin(overlappingRange[0]);
ithCol.setMax(overlappingRange[1]);
setColumnAttributes(col, ithCol);
}
if (overlappingType != NumericRanges.NO_OVERLAPS) {
colOverlaps = true;
}
}
if (!colOverlaps) {
CTCol newCol = cloneCol(cols, col);
}
sortColumns(cols);
return cols;
}