public class Tables extends Object
Modifier and Type | Field and Description |
---|---|
static DefaultValueInfo |
DEC_INFO
ValueInfo representing Declination.
|
static ValueInfo |
NULL_VALUE_INFO
ValueInfo which may be used as part of a column's metadata to indicate
a special value (preferably a
Number
that should be interpreted as a null (blank). |
static ValueInfo |
QUERY_STATUS_INFO
ValueInfo that indicates result of a query.
|
static DefaultValueInfo |
RA_INFO
ValueInfo representing Right Ascension.
|
static ValueInfo |
UBYTE_FLAG_INFO
ValueInfo which may be used as part of a column's auxiliary metadata
to indicate that the column's data represents, and can be
serialised as, unsigned byte values.
|
Constructor and Description |
---|
Tables() |
Modifier and Type | Method and Description |
---|---|
static TableSequence |
arrayTableSequence(StarTable[] tables)
Convenience method to construct a TableSequence for a supplied array
of tables.
|
static int |
assertLongToInt(long lval)
Casts a long to an int, with an assertion that no truncation occurs.
|
static int |
checkedLongToInt(long lval)
Convenience method to get an
int value
from a long . |
static long |
checksumData(RowSequence rseq,
Checksum checksum)
Feeds the data from a row sequence to a supplied checksum accumulator.
|
static int |
checksumData(StarTable table)
Returns a checksum of all the cell data in a given table.
|
static void |
checkTable(StarTable table)
Diagnostic method which tests the invariants of a StarTable.
|
static String |
collapseWhitespace(String txt)
Collapses whitespace in a string.
|
static StarTable |
deleteColumn(StarTable startab,
int icol)
Returns a table equivalent to the original but with a given column
deleted.
|
static void |
fixColumns(ColumnInfo[][] infoLists,
JoinFixAction[] fixActs)
Performs deduplication of column names for N lists of column metadata
objects that will be combined to form a new table.
|
static <T> T |
getAuxDatumValue(ValueInfo info,
ValueInfo auxKey,
Class<T> auxClazz)
Utility method to return an auxiliary metadata item from a ValueInfo.
|
static ColumnInfo[] |
getColumnInfos(StarTable startab)
Convenience method to return an array of all the column headers
in a given table.
|
static RowSplittable |
getDefaultRowSplittable(StarTable table)
Returns a RowSplittable object with generic characteristics
for a given table.
|
static DescribedValue |
getDescribedValueByName(Collection<DescribedValue> dvals,
String name)
Utility method to locate an element in a list of DescribedValue
given the name of its ValueInfo member.
|
static String[] |
getElementLabels(int[] shape)
Returns an array of strings suitable as labels or label suffixes
for elements of an array as returned by
ValueInfo.getShape() . |
static <T> T |
getTypedValue(DescribedValue dval,
Class<T> clazz)
Utility method to get a typed value from a, possibly null,
described value.
|
static String |
getUtype(ValueInfo info)
Deprecated.
use
ValueInfo.getUtype() instead |
static Object |
getValue(Collection<DescribedValue> dvals,
ValueInfo info)
Returns the value from a list of
DescribedValue objects
which corresponds to a given info key. |
static String |
getXtype(ValueInfo info)
Deprecated.
use
ValueInfo.getXtype() instead |
static boolean |
isBlank(Object value)
Indicates whether a given value is conventionally regarded as a
blank value.
|
static StarTable |
randomTable(StarTable startab)
Returns a table based on a given table and guaranteed to have
random access.
|
static void |
setDescribedValue(Collection<DescribedValue> dvals,
DescribedValue dval)
Utility method to update a list of DescribedValues with a new entry.
|
static void |
setUtype(ValueInfo info,
String utype)
Deprecated.
use
DefaultValueInfo.setUtype(java.lang.String) instead |
static void |
setXtype(ValueInfo info,
String xtype)
Deprecated.
use
DefaultValueInfo.setXtype(java.lang.String) instead |
static TableSequence |
singleTableSequence(StarTable table)
Convenience method to construct a TableSequence for a single table.
|
static StarTable |
sortTable(StarTable table,
int[] colIndices,
boolean up,
boolean nullsLast)
Returns a sorted version of a table.
|
static void |
streamStarTable(StarTable source,
TableSink sink)
Copies the data and metadata from a
StarTable into a
table sink. |
static StarTable[] |
tableArray(TableSequence tseq)
Convenience method to construct an array of StarTables from a
TableSequence.
|
static String |
tableToString(StarTable table,
String ofmt)
Returns the contents of a table as a string.
|
public static final ValueInfo NULL_VALUE_INFO
Number
that should be interpreted as a null (blank).
This should only be used on nullable columns, and really only
on ones with a contentClass which is an integer (or possibly boolean)
type; for other types, there is usually a value which can
conventionally be understood to mean blank.
Note this is here as a standard key to use when software components
wish to communicate this information; the table system does not
guarantee to honour instances of this value in a column's
auxiliary data. It is the job of a StarTable instance to ensure
that a null
is returned from the table interrogation methods
if that is what is meant.public static final ValueInfo UBYTE_FLAG_INFO
Boolean.TRUE
(other values are treated as if absent).
Data representing unsigned byte values will normally be represented
within STIL by Short (16-bit integer) signed values,
since there is no unsigned byte type in java.
However, this flag may be used to indicate that the
values can be serialised to unsigned-byte-capable output formats
(for instance FITS and VOTable) using an unsigned byte serialisation.
This annotation will normally only be honoured if the data type of
the column is (scalar or array) short integer (16-bit) values.
Some care should be exercised in applying this flag or (especially)
modifying values in columns it applies to, that the actual column
value range remains in the unsigned byte data range (0..255),
since otherwise problems will result if it is serialised.public static final ValueInfo QUERY_STATUS_INFO
public static final DefaultValueInfo RA_INFO
public static final DefaultValueInfo DEC_INFO
public static StarTable randomTable(StarTable startab) throws IOException
stab
has random
access then it is returned, otherwise a new random access table
is built using its data.
This convenience method is equivalent to calling
StoragePolicy.getDefaultPolicy().randomTable(startab)
.
startab
- original tablestartab
and with
isRandom()==true
IOException
public static ColumnInfo[] getColumnInfos(StarTable startab)
startab
- the table being enquired aboutpublic static StarTable deleteColumn(StarTable startab, int icol)
startab
- the table from which to delete a columnicol
- the index of the column to be deletedIndexOutOfBoundsException
- if startab
has no column
at icol
public static void streamStarTable(StarTable source, TableSink sink) throws IOException
StarTable
into a
table sink.
This method is supplied for convenience; its implementation is
very straightforward.source
- table to be copiedsink
- table destinationIOException
public static RowSplittable getDefaultRowSplittable(StarTable table) throws IOException
RowAccess
objects, and for a non-random table
it will not be capable of splits.table
- tableIOException
public static void checkTable(StarTable table) throws IOException
That a table passes this test does not guarantee that the table has no bugs. This method should not generally be used in production code, since it may be expensive in time and/or memory.
table
- table to testAssertionError
- if an invariant is violatedIOException
- if there is an I/O errorpublic static int checksumData(StarTable table) throws IOException
table
- table to checksumIOException
public static long checksumData(RowSequence rseq, Checksum checksum) throws IOException
rseq
- row sequence containing datachecksum
- checksum accumulatorIOException
public static boolean isBlank(Object value)
null
, but some classes have
additional non-null
values which count as blanks,
for instance zero-length Strings and floating Not-A-Number values.value
- value to testvalue
counts as a blank valuepublic static String collapseWhitespace(String txt)
whitespace='collapse'
:
leading and trailing whitespace is removed,
and any other run of whitespace is replaced by a single space character.txt
- input string (may be null)public static TableSequence singleTableSequence(StarTable table)
table
- tablepublic static TableSequence arrayTableSequence(StarTable[] tables)
tables
- table arraypublic static StarTable[] tableArray(TableSequence tseq) throws IOException
tseq
- table sequenceIOException
public static StarTable sortTable(StarTable table, int[] colIndices, boolean up, boolean nullsLast) throws IOException
colIndices
argument; the first element is the primary sort key, but in case
of a tie the second element is used, and so on. The original table
is not affected. The natural comparison order of the values in
the table is used, and blank values may be ranked at the start or
end of the collation order.table
- table to sort - must be random accesscolIndices
- indices of the columns which are to act as sort
keys; first element is primary key etcup
- true for sorting into ascending order, false for
descending ordernullsLast
- true if blank values should be considered
last in the collation order, false if they should
be considered firsttable
but in an
order determined by the other argumentsIOException
- if table.isRandom
is not truepublic static String tableToString(StarTable table, String ofmt)
table
- input tableofmt
- output format specifier, or null for plain text outputpublic static int checkedLongToInt(long lval)
int
value
from a long
.
If the supplied long integer lval
is out of the range
which can be represented in an int
, then unlike a
typecast, this method will throw
an IllegalArgumentException
.lval
- the long
value to convertint
value which has the same value
as lval
IllegalArgumentException
- if the conversion cannot be donepublic static int assertLongToInt(long lval)
lval
- long value, asserted to be in the range
Integer.MIN_VALUE..Integer.MAX_VALUElval
public static String[] getElementLabels(int[] shape)
ValueInfo.getShape()
.
If the given shape
cannot be decomposed into a fixed
size array, returns null
.shape
- vector giving dimensions of an array value@Deprecated public static String getUtype(ValueInfo info)
ValueInfo.getUtype()
insteadinfo
- metadata itemsetUtype(uk.ac.starlink.table.ValueInfo, java.lang.String)
@Deprecated public static void setUtype(ValueInfo info, String utype)
DefaultValueInfo.setUtype(java.lang.String)
insteadinfo
- metadata itemutype
- new utype valuegetUtype(uk.ac.starlink.table.ValueInfo)
@Deprecated public static String getXtype(ValueInfo info)
ValueInfo.getXtype()
insteadxtype
attribute of
the VOTable format. Other table formats may or may not be able
to represent it.info
- metadata item@Deprecated public static void setXtype(ValueInfo info, String xtype)
DefaultValueInfo.setXtype(java.lang.String)
insteadinfo
- metadata itemxtype
- new xtype valuegetXtype(uk.ac.starlink.table.ValueInfo)
public static void setDescribedValue(Collection<DescribedValue> dvals, DescribedValue dval)
dvals
- list to modifydval
- new entry to addpublic static DescribedValue getDescribedValueByName(Collection<DescribedValue> dvals, String name)
dvals
- list to queryname
- required value of namedvals
for which
getInfo().getName()
matches name
public static <T> T getAuxDatumValue(ValueInfo info, ValueInfo auxKey, Class<T> auxClazz)
info
- metadata itemauxKey
- info identifying aux metadata entry in info
auxClazz
- required result typepublic static <T> T getTypedValue(DescribedValue dval, Class<T> clazz)
dval
- described value, or nullclazz
- required return typedval
, or null if dval is null,
or if dval's value has the wrong typepublic static Object getValue(Collection<DescribedValue> dvals, ValueInfo info)
DescribedValue
objects
which corresponds to a given info key.
If the key is not represented in the list, or if its value is null,
then null is returned.dvals
- list of DescribedValue objectsinfo
- key giving the value you wantpublic static void fixColumns(ColumnInfo[][] infoLists, JoinFixAction[] fixActs)
infoLists
- array of N arrays of column metadata objectsfixActs
- array of N policies for renaming columnsCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.