uk.ac.starlink.table.ColumnInfo Maven / Gradle / Ivy
package uk.ac.starlink.table;
/**
* Contains information about a table column.
* This really does the same thing as its superclass,
* {@link DefaultValueInfo}, but for historical reasons it contains
* some additional methods for access to the
* auxiliary metadata items.
* In earlier versions of the library, columns were allowed to store
* auxiliary metadata and non-column items (like table parameters)
* were not, but now they have the same capabilities.
*
* @author Mark Taylor (Starlink)
*/
public class ColumnInfo extends DefaultValueInfo {
/**
* Constructs a ColumnInfo object.
*
* @param name the name of the column
*/
public ColumnInfo( String name ) {
super( name );
}
/**
* Constructs a new ColumnInfo based on a ValueInfo
* object. All attributes are copied from the template to the new
* object.
*
* @param base the template ValueInfo
*/
public ColumnInfo( ValueInfo base ) {
super( base );
}
/**
* Constructs a new ColumnInfo object with a given name,
* class and description.
*
* @param name the name applying to described values
* @param contentClass the class of which described values should be
* instances
* @param description a textual description of the described values
*/
public ColumnInfo( String name, Class> contentClass,
String description ) {
super( name, contentClass, description );
}
/**
* Gets an item of auxiliary metadata from its specification.
* Currently this just calls getAuxDatumByName(vinfo.getName()),
* but may be revised in future to match on other attributes.
*
* @param vinfo the data item to match
* @return a DescribedValue object representing the
* auxiliary metadata item matching vinfo for this column,
* or null if none exists
*/
public DescribedValue getAuxDatum( ValueInfo vinfo ) {
return getAuxDatumByName( vinfo.getName() );
}
/**
* Gets the value of an item of auxiliary metadata using its specification,
* requiring a particular return type.
* This convenience method works like {@link #getAuxDatum}
* but returns a non-null value
* only if the named item exists and if its value is an instance of
* the given type clazz.
*
* @param vinfo the data item to match
* @param clazz required return type
* @return value of the auxiliary metadata item matching
* vinfo for this
* column if it exists and is an instance of clazz or
* one of its subtypes, otherwise null
*/
public T getAuxDatumValue( ValueInfo vinfo, Class clazz ) {
DescribedValue dval = getAuxDatum( vinfo );
return dval == null ? null : dval.getTypedValue( clazz );
}
/**
* Gets the value of an item of auxiliary metadata by its name,
* requiring a particular return type.
* This convenience method works like {@link #getAuxDatumByName},
* but returns a non-null value only if the named item exists,
* and if its value is an instance of the given type clazz.
*
* @param name the name of an auxiliary metadata item
* @param clazz required return type
* @return value of the auxiliary metadata item matching
* vinfo for this column if it exists and is an
* instance of clazz or one of its subtypes,
* otherwise null
*/
public T getAuxDatumValueByName( String name, Class clazz ) {
DescribedValue dval = getAuxDatumByName( name );
return dval == null ? null : dval.getTypedValue( clazz );
}
}