All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.ac.starlink.table.ColumnStarTable Maven / Gradle / Ivy

There is a newer version: 4.3
Show newest version
package uk.ac.starlink.table;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * A random-access StarTable that manages its data in columns.
 * The data in each column
 * is managed by a ColumnData object which can be accessed
 * directly using the {@link #getColumnData} method.  Columns can be
 * added and substituted.  If the columns permit it then table cells
 * can be written to as well as read from.
 * 

* Concrete subclasses of this abstract class must implement * {@link #getRowCount}. * If you just need a ColumnStarTable with a fixed number of rows * you can use the static convenience method {@link #makeTableWithRows}. * * @author Mark Taylor (Starlink) */ public abstract class ColumnStarTable extends RandomStarTable { public List columns_ = new ArrayList(); /** * Default constructor. */ public ColumnStarTable() { } /** * Initialises a ColumnStarTable using a template * StarTable to provide per-table metadata. * The newly constructed object will have copies of the template's * name, parameters etc. * * @param template the template StarTable */ public ColumnStarTable( StarTable template ) { setName( template.getName() ); setParameters( new ArrayList( template .getParameters() ) ); } /** * Gets the number of rows in the table (which must be applicable to * all the columns). Since this is a RandomStarTable the * return value must be non-negative. * * @return number of rows */ public abstract long getRowCount(); public int getColumnCount() { return columns_.size(); } public ColumnInfo getColumnInfo( int icol ) { return getColumnData( icol ).getColumnInfo(); } public Object getCell( long lrow, int icol ) throws IOException { return getColumnData( icol ).readValue( lrow ); } /** * Stores an object in a given cell of the table. * * @param lrow the row index * @param icol the column index * @param value the value to store * @throws IOException if an I/O error occurs * @throws UnsupportedOperationException if column icol is not * writable (!getColumnData(icol).isWritable()); */ public void setCell( long lrow, int icol, Object value ) throws IOException { ColumnData coldata = getColumnData( icol ); if ( coldata.isWritable() ) { coldata.storeValue( lrow, value ); } else { throw new UnsupportedOperationException( "Column " + coldata + " not writable" ); } } /** * Returns the ColumnData object for a given column. * * @param icol the index of the column for which the result is required * @return the ColumnData for column icol */ public ColumnData getColumnData( int icol ) { return columns_.get( icol ); } /** * Appends a new column to the end of this model. * * @param coldata the new column object to add */ public void addColumn( ColumnData coldata ) { columns_.add( coldata ); } /** * Substitutes a new column for the one which is currently in a given * position. The old one is discarded. * * @param icol the column index to change * @param coldata the new column data object */ public void setColumn( int icol, ColumnData coldata ) { columns_.set( icol, coldata ); } /** * Convenience method to return a ColumnStarTable * with a fixed number of rows. * * @param nrow the number of rows this table will have */ public static ColumnStarTable makeTableWithRows( final long nrow ) { return new ColumnStarTable() { public long getRowCount() { return nrow; } }; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy