Package uk.ac.starlink.ecsv

# Class EcsvDecoder<T>

java.lang.Object
uk.ac.starlink.ecsv.EcsvDecoder<T>

public abstract class EcsvDecoder<T> extends Object
Decodes values in the body of an ECSV file for a given data type.

Since:
  28 Apr 2020
Author:
  Mark Taylor

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`EcsvDecoder(Class<T> clazz, int[] stilShape, String msg)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static EcsvDecoder<?>`
`createDecoder(String datatype, String subtype)`
Returns an instance of this class given a datatype and optional subtype.
`abstract T`
`decode(String txt)`
Attempts to decode the supplied string to a value of this decoder's type.
`Class<T>`
`getContentClass()`
Returns the class to which input values will be decoded.
`int[]`
`getShape()`
Returns the shape of the object that is decoded, in STIL format.
`String`
`getWarning()`
Returns any warning message concerning the behaviour of this decoder.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### EcsvDecoder

protected EcsvDecoder(Class<T> clazz, int[] stilShape, String msg)
Constructor.

Parameters:
  `clazz` - destination class
  `stilShape` - shape specifier in STIL format
  `msg` - warning or diagnostic message concerning decoding, or null if everything is normal

## Method Details

### decode

public abstract T decode(String txt)
Attempts to decode the supplied string to a value of this decoder's type. The supplied string will not be null or the empty string. Implementations should work on the assumption that the supplied string is of an appropriate type for this decoder; if it is not, it is permissiable to throw a NumberFormatException.

Parameters:
  `txt` - non-blank string to decode
Returns:
  typed value
Throws:
  `NumberFormatException` - in case of unrecognised string

### getContentClass

public Class<T> getContentClass()
Returns the class to which input values will be decoded.

Returns:
  destination class

### getShape

public int[] getShape()
Returns the shape of the object that is decoded, in STIL format. That may not be the same as what was specified in the ECSV metadata, if STIL is not smart enough to make sense of it.

Returns:
  STIL shape array, or null for scalar

### getWarning

public String getWarning()
Returns any warning message concerning the behaviour of this decoder.

Returns:
  warning message to be conveyed to user concerning this column, or null if everything is normal

### createDecoder

public static EcsvDecoder<?> createDecoder(String datatype, String subtype)
Returns an instance of this class given a datatype and optional subtype.

Parameters:
  `datatype` - case-sensitive datatype name
  `subtype` - subtype specifier string, or null
Returns:
  decoder for datatype, or null if unknown or unsupported