public class MemoryCatalog extends DefaultTableModel implements TableQueryResult, Saveable, SaveableAsHTML
In ASCII form, the data is represented as a tab separated table with an optional header and column headings.
The header may contain comments (starting with '#') or other text. Lines of the form "keyword: value" define properties, which are saved in a Properties object for access by client classes.
A dashed line "---" divides the column headings from the data rows. The column headings should be separated by tabs.
There is one row per line and each row should have the same number of tab separated columns as the table headings.
Modifier and Type | Field and Description |
---|---|
static String |
DEC_COL |
static String |
EQUINOX |
static String |
ID_COL |
static String |
RA_COL |
static String |
SYMBOL |
static String |
X_COL |
static String |
Y_COL |
columnIdentifiers, dataVector
listenerList
ARCHIVE, CATALOG, DIRECTORY, IMAGE_SERVER, LOCAL, NAME_SERVER
Modifier | Constructor and Description |
---|---|
protected |
MemoryCatalog()
This constructor is only for use by derived classes.
|
|
MemoryCatalog(Catalog catalog,
InputStream in)
Initialize the table from the given stream.
|
|
MemoryCatalog(Catalog catalog,
InputStream in,
int maxRows)
Initialize the table from the given stream by reading up to
maxRows of the data (in tab separated table format).
|
|
MemoryCatalog(Catalog catalog,
InputStream in,
QueryArgs queryArgs)
Initialize the table from the given stream by reading up to
maxRows of the data.
|
|
MemoryCatalog(Catalog catalog,
String filename)
Initialize the table from the given file.
|
|
MemoryCatalog(FieldDesc[] fields,
Vector dataVector)
Create a MemoryCatalog with the given information.
|
|
MemoryCatalog(MemoryCatalog table,
FieldDesc[] fields,
Vector dataRows)
Construct a new MemoryCatalog with the given column fields and data rows
(For internal use only).
|
|
MemoryCatalog(String filename)
Initialize the table from the given file
|
Modifier and Type | Method and Description |
---|---|
protected void |
_checkColumnClass(int col,
Object o)
Check the class type for the given column to see if all of the
items are the same type and update the _columnClasses vector, setting
the correct lowest common class for each column.
|
protected void |
_init(InputStream in,
int maxRows)
Initialize the table from the given stream, reading at most maxRows data rows.
|
protected void |
_initColumnClasses()
Determine the best class to use for each column by scanning the table items.
|
protected void |
_initFields()
Initialize the fields array, which describes the table columns
|
protected Vector |
_parseHeading(String s)
Parse the given line looking for tab separated column heading strings
and return a vector containing the strings found.
|
protected Object |
_parseItem(String s)
Parse the given string and return a Double or String
object, depending on the format of the string.
|
protected void |
_parseProperty(String s)
Check for a "keyword: value" pair in the given string and, if found,
save it as a property.
|
protected Vector |
_parseRow(String lineStr)
Parse the given table row looking for tab separated items.
|
protected void |
_saveHeader(PrintStream out)
Save the table header (part before the column headings)
to the given PrintStream.
|
protected void |
_saveProperties(PrintStream out)
Save the table header (part before the column headings)
to the given PrintStream.
|
void |
addRow(Vector row)
Add a row to the table
|
Object |
clone()
Implementation of the clone method (makes a shallow copy).
|
protected boolean |
compareRow(Vector row,
String objectId,
CoordinateRadius region,
SearchCondition[] conditions,
int[] searchCols)
Return true if the given row satisfies the given query arguments.
|
Catalog |
getCatalog()
Return the catalog used to create this table, or null if not known.
|
Class |
getColumnClass(int columnIndex)
Returns the lowest common denominator Class in the column.
|
Vector |
getColumnClasses()
Return the vector used to guess the data type for a column.
|
FieldDesc |
getColumnDesc(int i)
Return a description of the ith table column parameter.
|
Vector |
getColumnIdentifiers()
Allow access to this inherited member variable in a subclass
|
int |
getColumnIndex(String name)
Return the table column index for the given column name
|
String |
getColumnName(int index)
Return the table column name for the given column index
|
Coordinates |
getCoordinates(int rowIndex)
Return a Coordinates object based on the appropriate columns in the given row,
or null if there are no coordinates available for the row.
|
String |
getDescription()
Return a description of the catalog, or null if not available
|
URL |
getDocURL()
Return the documentation URL for the catalog
|
FieldDesc[] |
getFields()
Return an array of objects describing the table columns
|
String |
getFilename()
Return the filename of the local catalog, if known
|
String |
getId()
Return the id or short name of the catalog
|
String |
getName()
Return the name of the catalog
|
int |
getNumColumns()
Return the number of table columns..
|
int |
getNumParams()
Return the number of query parameters that this catalog accepts.
|
FieldDesc |
getParamDesc(int i)
Return a description of the ith query parameter.
|
FieldDesc |
getParamDesc(String name)
Return a description of the named query parameter.
|
CatalogDirectory |
getParent()
Return a reference to the parent catalog directory, or null if not known.
|
Catalog[] |
getPath()
Return an array of Catalog or CatalogDirectory objects representing the
path from the root catalog directory to this catalog.
|
Properties |
getProperties()
Return the properties defined in the table header
|
String |
getProperty(String key)
Return the value of the named property as a String
|
QueryArgs |
getQueryArgs()
Return the object representing the arguments to the query that resulted in this table,
if known, otherwise null.
|
RowCoordinates |
getRowCoordinates()
Return an object storing the column indexes where RA and Dec are found,
using the first plot symbol definition found.
|
String |
getTitle()
Return the title for the catalog
|
String |
getType()
Return the catalog type (normally one of the Catalog constants: CATALOG, ARCHIVE, DIRECTORY, LOCAL, IMAGE_SERVER)
|
Object |
getValueAt(int row,
String name)
Return the value at the given row and columm name
|
WorldCoordinates |
getWCSCenter()
Return the center coordinates for this table from the query arguments,
if known, otherwise return the coordinates of the first row, or null
if there are no world coordinates available.
|
boolean |
hasCol(String name)
return true if the table contains the given column
|
boolean |
hasCoordinates()
Return true if the table has coordinate columns, such as (ra, dec)
|
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns true if the cell at rowIndex and columnIndex
is editable.
|
boolean |
isImageServer()
Return true if this object represents an image server.
|
boolean |
isLocal()
Return true if this is a local catalog, and false if it requires
network access or if a query could hang.
|
boolean |
isMore()
Return true if the query result was truncated and more data would have been available
|
boolean |
isReadOnly()
Return true if the table is read-only and should not be editable
|
static void |
main(String[] args)
Test cases
|
protected Vector |
makeColumnIdentifiers(FieldDesc[] fields)
Create and return a vector of table column identifiers (column headings)
based on the given fields.
|
protected MemoryCatalog |
makeQueryResult(FieldDesc[] fields,
Vector dataRows)
Return a new MemoryCatalog with the given column fields and data rows.
|
void |
print() |
QueryResult |
query(QueryArgs queryArgs)
Query the catalog using the given argument and return the result.
|
void |
saveAs(OutputStream os)
Save the table to the given stream
|
void |
saveAs(String filename)
Save the table to the given filename format.
|
void |
saveAsHTML(String filename)
Save the table to the given filename in HTML format
|
void |
setCatalog(Catalog cat)
Set a reference to the catalog used to create this table.
|
void |
setColumnClasses(Vector v)
Set the vector used to guess the data type for a column.
|
void |
setColumnIdentifiers(Vector columnIdentifiers)
Set the table column headings with a Vector of Strings
|
void |
setDescription(String description)
Set the description of the catalog
|
void |
setDocURL(URL docURL)
Set the doc URL for the catalog
|
void |
setFields(FieldDesc[] fields)
Set the array of objects describing the table columns.
|
void |
setFilename(String filename)
Set the filename of the local catalog
|
void |
setId(String id)
Set the id or short name for the catalog
|
void |
setMore(boolean more)
Called to indicate if the result was truncated and more rows would have been available
|
void |
setName(String name)
Set the name for the catalog
|
void |
setParent(CatalogDirectory catDir)
Set the parent catalog directory
|
void |
setProperties(Properties p)
Replace the table properties
|
void |
setProperty(String key,
String value)
Set the value of the named property
|
void |
setQueryArgs(QueryArgs queryArgs)
Set the object representing the arguments to the query that resulted in this table.
|
void |
setReadOnly(boolean b)
Set to true if the table is read-only and should not be editable
|
void |
setRegionArgs(QueryArgs queryArgs,
CoordinateRadius region)
This method is required to implement the Catalog interface, but currently does nothing here.
|
void |
setRowCoordinates(RowCoordinates rowCoordinates)
Set the RowCoordinates object for this catalog
|
void |
setTitle(String title)
Set the title for the catalog
|
void |
sort(String[] sortCols,
String sortOrder)
Sort the contents of the table by the given sort columns and in the
given order.
|
String |
toString()
Format and return the contents of the table as a String
|
addColumn, addColumn, addColumn, addRow, convertToVector, convertToVector, getColumnCount, getDataVector, getRowCount, getValueAt, insertRow, insertRow, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount, setValueAt
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDataVector
addTableModelListener, getColumnCount, getRowCount, getValueAt, removeTableModelListener, setValueAt
public static final String EQUINOX
public static final String SYMBOL
public static final String ID_COL
public static final String RA_COL
public static final String DEC_COL
public static final String X_COL
public static final String Y_COL
public MemoryCatalog(FieldDesc[] fields, Vector dataVector)
fields
- an array of objects describing the table columnsdataVector
- a vector of data rows, each of which is a vector of column values.more
- true if the query result was truncated and more data would have been available.public MemoryCatalog(Catalog catalog, InputStream in, int maxRows) throws IOException
catalog
- the catalog where the data originated, if knownin
- the stream to read the table data frommaxRows
- the maximum number of data rows to readIOException
public MemoryCatalog(Catalog catalog, InputStream in) throws IOException
catalog
- the catalog where the data originated, if knownin
- the stream to read the catalog data fromIOException
public MemoryCatalog(Catalog catalog, InputStream in, QueryArgs queryArgs) throws IOException
catalog
- the catalog where the data originated, if knownin
- the stream to read the catalog data fromqueryArgs
- represents the arguments to the query that resulted in this tableIOException
public MemoryCatalog(Catalog catalog, String filename) throws IOException
catalog
- the catalog where the data originated, if knownfilename
- the name of the catalog fileIOException
public MemoryCatalog(String filename) throws IOException
filename
- the name of the catalog fileIOException
public MemoryCatalog(MemoryCatalog table, FieldDesc[] fields, Vector dataRows)
table
- the source catalog tablefields
- an array of objects describing the table columnsdataVector
- a vector of data rows, each of which is a vector of column values.protected MemoryCatalog()
public Object clone()
public void setCatalog(Catalog cat)
public Catalog getCatalog()
getCatalog
in interface TableQueryResult
protected void _init(InputStream in, int maxRows) throws IOException
IOException
protected void _parseProperty(String s)
protected Vector _parseHeading(String s)
s
- A line containing tab separated column headings.protected void _initFields()
protected Vector _parseRow(String lineStr)
Item strings that look like numbers are inserted into the result as Doubles.
lineStr
- A string containing a line from the table.protected Object _parseItem(String s)
s
- A String to be parsed.protected void _checkColumnClass(int col, Object o)
col
- The column indexo
- The item in the columnpublic Vector getColumnIdentifiers()
getColumnIdentifiers
in interface TableQueryResult
protected Vector makeColumnIdentifiers(FieldDesc[] fields)
public String getName()
public void setName(String name)
public String getFilename()
public void setFilename(String filename)
public String getId()
public void setId(String id)
public String getTitle()
public void setTitle(String title)
public String getDescription()
getDescription
in interface Catalog
public void setDescription(String description)
public URL getDocURL()
public void setDocURL(URL docURL)
public int getNumParams()
getNumParams
in interface Catalog
public FieldDesc getParamDesc(int i)
getParamDesc
in interface Catalog
public FieldDesc getParamDesc(String name)
getParamDesc
in interface Catalog
public int getNumColumns()
public FieldDesc getColumnDesc(int i)
getColumnDesc
in interface TableQueryResult
public void setRegionArgs(QueryArgs queryArgs, CoordinateRadius region)
setRegionArgs
in interface Catalog
queryArgs
- (in/out) describes the query argumentsregion
- (in) describes the query region (center and radius range)public boolean isLocal()
public boolean isImageServer()
isImageServer
in interface Catalog
public String getType()
public void setParent(CatalogDirectory catDir)
public CatalogDirectory getParent()
public Catalog[] getPath()
public QueryResult query(QueryArgs queryArgs) throws IOException
query
in interface Catalog
queryArgs
- An object describing the query arguments.IOException
protected MemoryCatalog makeQueryResult(FieldDesc[] fields, Vector dataRows)
fields
- an array of objects describing the table columnsdataVector
- a vector of data rows, each of which is a vector of column values.public String toString()
protected boolean compareRow(Vector row, String objectId, CoordinateRadius region, SearchCondition[] conditions, int[] searchCols)
row
- A vector containing the column values for a row.objectId
- If not null, search for an object with this id.region
- The region (center, radius) for a circular search, if not null.conditions
- Specifies the ranges for column values we are search for.searchCols
- An array of column indexes corresponding to the condition
argument (used for efficiency).public boolean isMore()
isMore
in interface TableQueryResult
public void setMore(boolean more)
public void setColumnIdentifiers(Vector columnIdentifiers)
setColumnIdentifiers
in class DefaultTableModel
public void addRow(Vector row)
addRow
in class DefaultTableModel
public boolean hasCol(String name)
public Object getValueAt(int row, String name)
public int getColumnIndex(String name)
getColumnIndex
in interface TableQueryResult
public String getColumnName(int index)
getColumnName
in interface TableModel
getColumnName
in class DefaultTableModel
public Class getColumnClass(int columnIndex)
getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
public Vector getColumnClasses()
public void setColumnClasses(Vector v)
public FieldDesc[] getFields()
public void setFields(FieldDesc[] fields)
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface TableModel
isCellEditable
in class DefaultTableModel
rowIndex
- the row whose value is to be looked upcolumnIndex
- the column whose value is to be looked upDefaultTableModel.setValueAt(java.lang.Object, int, int)
public boolean isReadOnly()
public void setReadOnly(boolean b)
public void sort(String[] sortCols, String sortOrder)
sortCols
- an array of column names to sort bysortOrder
- if true, sort in ascending order, otherwise descending.public boolean hasCoordinates()
hasCoordinates
in interface TableQueryResult
public Coordinates getCoordinates(int rowIndex)
getCoordinates
in interface TableQueryResult
public void print()
public void saveAs(String filename) throws IOException
saveAs
in interface Saveable
IOException
public void saveAs(OutputStream os)
protected void _saveHeader(PrintStream out)
protected void _saveProperties(PrintStream out)
public void saveAsHTML(String filename) throws IOException
saveAsHTML
in interface SaveableAsHTML
IOException
public QueryArgs getQueryArgs()
getQueryArgs
in interface TableQueryResult
public void setQueryArgs(QueryArgs queryArgs)
setQueryArgs
in interface TableQueryResult
public RowCoordinates getRowCoordinates()
getRowCoordinates
in interface TableQueryResult
public void setRowCoordinates(RowCoordinates rowCoordinates)
public WorldCoordinates getWCSCenter()
getWCSCenter
in interface TableQueryResult
protected void _initColumnClasses()
public Properties getProperties()
public void setProperties(Properties p)
public String getProperty(String key)
public static void main(String[] args)
Copyright © 2023 Central Laboratory of the Research Councils. All Rights Reserved.