Skip to content

Commit

Permalink
some refactorings after rowSize deletion #92
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchieGitHub committed May 29, 2016
1 parent 630e2dd commit c028fee
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/main/java/nom/tam/fits/BinaryTable.java
Expand Up @@ -142,6 +142,20 @@ public int[] getDimens() {
return this.dimens;
}

/**
* @return new instance of the array with space for the specified number
* of rows.
* @param nRow
* the number of rows to allocate the array for
*/
public Object newInstance(int nRow) {
return ArrayFuncs.newInstance(ArrayFuncs.getBaseClass(this.model), this.size * nRow);
}

public int rowLen() {
return this.size * PrimitiveTypeHandler.valueOf(this.base).size();
}

/**
* @return Is this a variable length column using longs? [Must have
* isVarying true too]
Expand Down Expand Up @@ -544,7 +558,7 @@ public void deleteColumns(int start, int len) throws FitsException {
for (int i = start + len - 1; i >= start; i -= 1) {
if (i >= 0 && i <= this.columnList.size()) {
ColumnDesc columnDesc = this.columnList.get(i);
this.rowLen -= columnDesc.size * PrimitiveTypeHandler.valueOf(columnDesc.base).size();
this.rowLen -= columnDesc.rowLen();
this.columnList.remove(i);
}
}
Expand Down Expand Up @@ -1289,7 +1303,7 @@ private ColumnTable<SaveState> createTable() throws FitsException {
arrCol[i] = desc.column;
desc.column = null;
} else {
arrCol[i] = ArrayFuncs.newInstance(ArrayFuncs.getBaseClass(desc.model), desc.size * this.nRow);
arrCol[i] = desc.newInstance(this.nRow);
}
}
this.table = createColumnTable(arrCol, sizes);
Expand Down Expand Up @@ -1355,8 +1369,9 @@ private void ensureDataSilent() {
}

/**
* @return row from the file. * @throws FitsException if the operation
* failed
* @return row from the file.
* @throws FitsException
* if the operation failed
*/
private Object[] getFileRow(int row) throws FitsException {

Expand All @@ -1366,7 +1381,7 @@ private Object[] getFileRow(int row) throws FitsException {
Object[] data = new Object[this.columnList.size()];
for (int col = 0; col < data.length; col++) {
ColumnDesc colDesc = this.columnList.get(col);
data[col] = ArrayFuncs.newInstance(ArrayFuncs.getBaseClass(colDesc.model), colDesc.size);
data[col] = colDesc.newInstance(1);
}

try {
Expand Down Expand Up @@ -1766,22 +1781,18 @@ int addFlattenedColumn(Object o, int[] dims, boolean allocated) throws FitsExcep
* FitsException if the operation failed
*/
void fillForColumn(Header h, int col, Cursor<String, HeaderCard> iter) throws FitsException {

String tform;
ColumnDesc colDesc = this.columnList.get(col);

String tform;
if (colDesc.isVarying) {
if (colDesc.isLongVary) {
tform = "1Q";
} else {
tform = "1P";
}

} else {
tform = "" + colDesc.size;

tform = Integer.toString(colDesc.size);
}

if (colDesc.base == int.class) {
tform += "J";
} else if (colDesc.base == short.class || colDesc.base == char.class) {
Expand Down

0 comments on commit c028fee

Please sign in to comment.