uk.ac.starlink.table
Class DefaultValueInfo

java.lang.Object
  |
  +--uk.ac.starlink.table.DefaultValueInfo
All Implemented Interfaces:
ValueInfo
Direct Known Subclasses:
ColumnInfo

public class DefaultValueInfo
extends Object
implements ValueInfo

Default implementation of the ValueInfo interface. Additionally provides mutator methods for the accessors defined in ValueInfo.


Constructor Summary
DefaultValueInfo()
          Constructs a new generic DefaultValueInfo object without a name.
DefaultValueInfo(String name)
          Constructs a new generic DefaultValueInfo object with a given name.
DefaultValueInfo(String name, Class contentClass)
          Constructs a new DefaultValueInfo object with a given name and class.
DefaultValueInfo(String name, Class contentClass, String description)
          Constructs a new DefaultValueInfo object with a given name, class and description.
DefaultValueInfo(ValueInfo base)
          Constructs a DefaultValueInfo object which is a copy of an existing one.
 
Method Summary
static String formatClass(Class clazz)
          Returns a human-friendly string indicating the class and shape of a given ValueInfo object.
static String formatShape(int[] shape)
          Returns a string representing the shape of this object, if it is array-like.
 String formatValue(Object value, int maxLength)
          Returns a string representation of a given value described by this ValueInfo.
static ValueInfo generalise(ValueInfo vi1, ValueInfo vi2)
          Returns a ValueInfo object which is sufficiently general to cover every object described by either of two given ValueInfo objects.
 TableCellEditor getCellEditor()
          Returns a cell editor suitable for editing the data described by this info, or null if no user editing is possible.
 TableCellRenderer getCellRenderer()
          Returns a renderer suitable for rendering the data described by this info.
 Class getContentClass()
          Returns the java class of the values described by this object.
 String getDescription()
          Returns a description of the values described by this object.
 int getElementSize()
          May indicate the size of a value element stored as the value of this info.
 String getName()
          Returns the name of this object.
 int[] getShape()
          Returns the shape associated with array value types.
 String getUCD()
          Returns the Unified Column Descriptor string applying to the values described by this object.
 String getUnitString()
          Returns a string representing the units of the values described by this object.
 boolean isArray()
          Indicates whether the values described by this object are java arrays.
 boolean isNullable()
          Indicates whether values returned described by this object may have the value null.
 void setContentClass(Class contentClass)
          Sets the java class of objects contained in this column.
 void setDescription(String description)
          Sets a textual description of the values described by this object.
 void setElementSize(int size)
          Sets the element size of values described by this object.
 void setName(String name)
          Sets the name for this object.
 void setNullable(boolean isNullable)
          Sets whether values described by this object may have the value null.
 void setShape(int[] shape)
          Sets the shape of values described by this object.
 void setUCD(String ucd)
          Sets the Unified Content Descriptor string applying to values described by this object.
 void setUnitString(String unitString)
          Sets the string representing the units for the values described by this object.
 String toString()
          Returns a string representation of this object.
 Object unformatString(String rep)
          Returns an object of the sort described by this ValueInfo represented by the given string rep.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultValueInfo

public DefaultValueInfo()
Constructs a new generic DefaultValueInfo object without a name.


DefaultValueInfo

public DefaultValueInfo(String name)
Constructs a new generic DefaultValueInfo object with a given name.

Parameters:
name - the name applying to described values

DefaultValueInfo

public DefaultValueInfo(String name,
                        Class contentClass)
Constructs a new DefaultValueInfo object with a given name and class.

Parameters:
name - the name applying to described values
contentClass - the class of which described values should be instances

DefaultValueInfo

public DefaultValueInfo(String name,
                        Class contentClass,
                        String description)
Constructs a new DefaultValueInfo object with a given name, class and description.

Parameters:
name - the name applying to described values
contentClass - the class of which described values should be instances
description - a textual description of the described values

DefaultValueInfo

public DefaultValueInfo(ValueInfo base)
Constructs a DefaultValueInfo object which is a copy of an existing one. The fields of the new object are copies (where possible not references to) those of the base one.

Parameters:
base - the object to copy
Method Detail

setName

public void setName(String name)
Sets the name for this object.

Parameters:
name - the name

getName

public String getName()
Description copied from interface: ValueInfo
Returns the name of this object.

Specified by:
getName in interface ValueInfo
Returns:
the name

setUnitString

public void setUnitString(String unitString)
Sets the string representing the units for the values described by this object.

Parameters:
unitString - a string giving the units, or null if units are unknown

getUnitString

public String getUnitString()
Description copied from interface: ValueInfo
Returns a string representing the units of the values described by this object. The syntax and conventions should ideally match those adopted by VOTable, as defined by CDS.

Specified by:
getUnitString in interface ValueInfo
Returns:
a string giving the units, or null if units are unknown
See Also:
Standards for Astronomical Catalogues: Units, CDS Strasbourg

setUCD

public void setUCD(String ucd)
Sets the Unified Content Descriptor string applying to values described by this object.

Parameters:
ucd - the UCD, or null if none is known

getUCD

public String getUCD()
Description copied from interface: ValueInfo
Returns the Unified Column Descriptor string applying to the values described by this object.

Specified by:
getUCD in interface ValueInfo
Returns:
the UCD, or null if none is known
See Also:
Unified Column Descriptor scheme, UCD

setDescription

public void setDescription(String description)
Sets a textual description of the values described by this object.

Parameters:
description - a texttual description of this column, or the empty string "" if there is nothing to be said

getDescription

public String getDescription()
Description copied from interface: ValueInfo
Returns a description of the values described by this object. It may contain a short or long textual description of the kind of information represented by the value.

Specified by:
getDescription in interface ValueInfo
Returns:
a textual description, or the empty string "" if there is nothing to be said

getContentClass

public Class getContentClass()
Description copied from interface: ValueInfo
Returns the java class of the values described by this object. The intention is that any Object described by this ValueInfo will be an instance of the returned class or one of its subclasses. Note therefore that it must not return one of the primitive class objects (int.class et al.); the appropriate wrapper classes must be used instead (Integer.class etc).

The class returned should not under normal circumstances be an array of arrays; to express multidimensionality of arrays you should store an array of non-array objects or of primitives and provide shape information via the getShape method. There is nothing to stop you describing arrays of arrays with a ValueInfo, but some other elements of the tables infrastructure and applications may work on the assumption that such objects are not present.

Note that to store sets of more than 231 items it will be necessary to use some custom object, since java arrays are indexed by type int.

Specified by:
getContentClass in interface ValueInfo
Returns:
the java class

setContentClass

public void setContentClass(Class contentClass)
Sets the java class of objects contained in this column.

Parameters:
contentClass - the class of items in this column
Throws:
IllegalArgumentException - if contentClass is primitive

isArray

public boolean isArray()
Description copied from interface: ValueInfo
Indicates whether the values described by this object are java arrays. This convenience method should return the same as
     getContentClass().getComponentType()!=null
 

Specified by:
isArray in interface ValueInfo
Returns:
true iff the values described by this object are java arrays

getShape

public int[] getShape()
Description copied from interface: ValueInfo
Returns the shape associated with array value types. If the class returned by ValueInfo.getContentClass() is a java array type, the return from this method may contain information about the shape of the rectangular array which this represents. The dimensions of the array are given in the elements of the return value of this method, fastest varying first. All elements of the array should be positive, except that the last (slowest varying) element may be <=0 (conventionally -1) to indicate that the number of (shape.length-1)-dimensional slices contained in the value is not known. If nothing is known about the shape of the array values, then a 1-element array whose only element is <=0 should be returned.

If getContentClass does not give an array type (hence isArray returns false) the return value for this method is undefined (but should probably be null).

Specified by:
getShape in interface ValueInfo
Returns:
the shape of the array value

setShape

public void setShape(int[] shape)
Sets the shape of values described by this object.

Parameters:
shape - the shape
Throws:
IllegalArgumentException - if shape has elements apart from the last one which are <=0

getElementSize

public int getElementSize()
Description copied from interface: ValueInfo
May indicate the size of a value element stored as the value of this info. The total size of the value will in this case be the return value of this method multiplied by the number of elements, as indicated by ValueInfo.getShape() (or by 1, if getShape is null).

The exact meaning of the value returned is dependent on this ValueInfo. This method was introduced to return the maximum number of characters in a String-class ValueInfo; this information is necessary for writing out to certain formats (FITS). Other ValueInfo types however may use it for their own purposes.

ValueInfo instances which decline to supply this information should return -1 from this method.

Specified by:
getElementSize in interface ValueInfo
Returns:
notional size of each element an array of values described by this info

setElementSize

public void setElementSize(int size)
Sets the element size of values described by this object.

Parameters:
size - the element size

isNullable

public boolean isNullable()
Description copied from interface: ValueInfo
Indicates whether values returned described by this object may have the value null. In general this should return true, which implies no assertion about the return values (they may or may not be null). But if the values are known never to be null, it may return false.

Specified by:
isNullable in interface ValueInfo
Returns:
false if values are guaranteed non-null

setNullable

public void setNullable(boolean isNullable)
Sets whether values described by this object may have the value null. By setting this to false you assert that no null objects will be returned from this column.

Parameters:
isNullable - false if objects in this column are guaranteed non-null

generalise

public static ValueInfo generalise(ValueInfo vi1,
                                   ValueInfo vi2)
Returns a ValueInfo object which is sufficiently general to cover every object described by either of two given ValueInfo objects. For most of the info attributes this entails setting to null any attribute which is not the same for both, though for contentClass it involves finding the most specific common ancestor class.

Parameters:
vi1 - one ValueInfo object
vi2 - the other ValueInfo object
Returns:
a generalised ValueInfo object

getCellRenderer

public TableCellRenderer getCellRenderer()
Returns a renderer suitable for rendering the data described by this info. Subclasses should override this method if they can format their values in a component better than allowing the formatValue text to be put into a cell.

Specified by:
getCellRenderer in interface ValueInfo
Returns:
a custom renderer

getCellEditor

public TableCellEditor getCellEditor()
Returns a cell editor suitable for editing the data described by this info, or null if no user editing is possible. Subclasses should override this method if they can do better than calling the unformatValue method to turn user text into a cell value (or if they don't even want to attempt that, in which case they should return null).

Returns:
a custom editor, or null

formatValue

public String formatValue(Object value,
                          int maxLength)
Description copied from interface: ValueInfo
Returns a string representation of a given value described by this ValueInfo. The returned string should be no longer than a given maximum length.

Specified by:
formatValue in interface ValueInfo
Parameters:
value - the value to represent
maxLength - the maximum number of characters in the returned string

formatClass

public static String formatClass(Class clazz)
Returns a human-friendly string indicating the class and shape of a given ValueInfo object. This will read something like "Integer" or "byte[][]" or "uk.ac.starlink.FrameSet".

Returns:
a string showing the class and shape of info

formatShape

public static String formatShape(int[] shape)
Returns a string representing the shape of this object, if it is array-like. This will look something like "1024,1024,3" or "2,*".

Parameters:
shape - the shape to format
Returns:
a human-readable representation of the value shape

unformatString

public Object unformatString(String rep)
Description copied from interface: ValueInfo
Returns an object of the sort described by this ValueInfo represented by the given string rep.

Specified by:
unformatString in interface ValueInfo
Parameters:
rep - the string representation of a value described by this ValueInfo
Returns:
the Object value represented by rep; must match this info's content class (or be null)

toString

public String toString()
Returns a string representation of this object. The result indicates the object's name, class and shape.

Overrides:
toString in class Object
Returns:
a string representation of this object

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.