Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removal of redundent attribute "rowSize" #92

Merged
merged 2 commits into from Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 26 additions & 12 deletions src/main/java/nom/tam/fits/BinaryTable.java
Expand Up @@ -58,6 +58,7 @@
import nom.tam.util.FitsIO;
import nom.tam.util.RandomAccess;
import nom.tam.util.TableException;
import nom.tam.util.type.PrimitiveTypeHandler;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
Expand Down Expand Up @@ -141,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 @@ -538,10 +553,12 @@ public int addRow(Object[] o) throws FitsException {
public void deleteColumns(int start, int len) throws FitsException {
ensureData();
try {
this.rowLen = this.table.deleteColumns(start, len);
this.table.deleteColumns(start, len);
// Need to get rid of the column level metadata.
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.rowLen();
this.columnList.remove(i);
}
}
Expand Down Expand Up @@ -1286,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 @@ -1352,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 @@ -1363,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 @@ -1565,7 +1583,7 @@ private int processCol(Header header, int col) throws FitsException {
}
if (colDesc.isVarying) {
dims = new int[]{
2
2
};
colBase = int.class;
bSize = FitsIO.BYTES_IN_INTEGER * 2;
Expand Down Expand Up @@ -1763,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
Expand Up @@ -54,6 +54,10 @@ public class CompressedTableHDU extends BinaryTableHDU {
* the binary table to compress
* @param tileRows
* the number of rows that should be compressed per tile.
* @param columnCompressionAlgorithms
* the compression algorithms to use for the columns (optional
* default compression will be used if a column has no
* compression specified)
* @return the prepared compressed binaary table hdu.
* @throws FitsException
* if the binary table could not be used to create a compressed
Expand Down
24 changes: 2 additions & 22 deletions src/main/java/nom/tam/util/ColumnTable.java
Expand Up @@ -280,9 +280,6 @@ public void read(ColumnTable<?> table, ArrayDataInput is, int index, int arrOffs
/** The number of rows */
private int nrow;

/** The size of a row in bytes */
private int rowSize;

/**
* The base type of each row (using the second character of the [x class
* names of the arrays.
Expand Down Expand Up @@ -346,8 +343,6 @@ public void addColumn(Object newColumn, int size) throws TableException {
String classname = newColumn.getClass().getName();
this.nrow = checkColumnConsistency(newColumn, classname, this.nrow, size);

this.rowSize += this.nrow * ArrayFuncs.getBaseLength(newColumn);

int ncol = this.arrays.length;

Object[] newArrays = new Object[ncol + 1];
Expand Down Expand Up @@ -434,9 +429,6 @@ public void addRow(Object[] row) throws TableException {
}
initializePointers();
this.nrow += 1;
if (rowSize == 0) {
this.rowSize = this.nrow * ArrayFuncs.getBaseLength(getRow(this.nrow - 1));
}
}
}

Expand Down Expand Up @@ -485,7 +477,6 @@ protected void checkArrayConsistency(Object[] newArrays, int[] newSizes) throws
}

this.nrow = ratio;
this.rowSize = newRowSize;
this.arrays = newArrays;
this.sizes = newSizes;
}
Expand Down Expand Up @@ -531,7 +522,6 @@ public ColumnTable<T> copy() throws TableException {
/**
* Delete a contiguous set of columns from the table.
*
* @return the rowlength
* @param start
* The first column (0-indexed) to be deleted.
* @param len
Expand All @@ -540,16 +530,13 @@ public ColumnTable<T> copy() throws TableException {
* if the request goes outside the boundaries of the table or if
* the length is negative.
*/
public int deleteColumns(int start, int len) throws TableException {
public void deleteColumns(int start, int len) throws TableException {
int ncol = this.arrays.length;
if (start < 0 || len < 0 || start + len > ncol) {
throw new TableException("Invalid request to delete columns start: " + start + " length:" + len + " for table with " + ncol + " columns.");
}
if (len == 0) {
return this.rowSize;
}
for (int i = start; i < start + len; i += 1) {
this.rowSize -= this.sizes[i] * ArrayFuncs.getBaseLength(this.arrays[i]);
return;
}
int ocol = ncol;
ncol -= len;
Expand Down Expand Up @@ -577,7 +564,6 @@ public int deleteColumns(int start, int len) throws TableException {
this.types = newTypes;

initializePointers();
return this.rowSize;
}

/**
Expand Down Expand Up @@ -905,9 +891,6 @@ private void setup(Object[] newArrays, int[] newSizes) throws TableException {
* if the write operation failed
*/
public void write(ArrayDataOutput os) throws IOException {
if (this.rowSize == 0) {
return;
}
int[] columnIndex = new int[MAX_COLUMN_INDEXES];
for (int row = 0; row < this.nrow; row += 1) {
Arrays.fill(columnIndex, 0);
Expand Down Expand Up @@ -939,9 +922,6 @@ public void write(ArrayDataOutput os) throws IOException {
* if the write operation failed
*/
public void write(ArrayDataOutput os, int rowStart, int rowEnd, int columnNr) throws IOException {
if (this.rowSize == 0) {
return;
}
int[] columnIndex = new int[MAX_COLUMN_INDEXES];
for (int row = 0; row < this.nrow; row += 1) {
if (row >= rowStart && row < rowEnd) {
Expand Down