# Class Datatype<T>

java.lang.Object
uk.ac.starlink.tfcat.Datatype<T>

public abstract class Datatype<T> extends Object
Characterises the type of data held by a field.

Since:
  9 Feb 2022
Author:
  Mark Taylor

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Datatype<Boolean>`
`BOOL`
Boolean type.
`static final Datatype<Double>`
`FLOAT`
Floating point type.
`static final Datatype<Long>`
`INT`
Integer type.
`static final Datatype<String>`
`STRING`
String type.

## Method Summary

Modifier and Type
Method
Description
`abstract T`
`decode(String txt)`
Decodes a string value that has this type.
`static Datatype<?>`
`forName(String name)`
Returns the datatype instance for a given type name.
`String`
`getName()`
Returns the name of this datatype, as used in the datatype member of a field.
`Class<T>`
`getTypeClass()`
Returns the object class represented by this datatype.
`abstract boolean`
`isType(String txt)`
Indicates whether a string value appears to have this type.
`String`
`toString()`

### Methods inherited from class Object

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

## Field Details

### INT

public static final Datatype<Long> INT
Integer type.

### FLOAT

public static final Datatype<Double> FLOAT
Floating point type.

### BOOL

public static final Datatype<Boolean> BOOL
Boolean type.

### STRING

public static final Datatype<String> STRING
String type.

## Method Details

### getName

public String getName()
Returns the name of this datatype, as used in the datatype member of a field.

Returns:
  type name

### getTypeClass

public Class<T> getTypeClass()
Returns the object class represented by this datatype.

Returns:
  class

### decode

public abstract T decode(String txt)
Decodes a string value that has this type.

Parameters:
  `txt` - JSON string representation of a typed value
Returns:
  typed value
Throws:
  `RuntimeException` - if the value cannot be decoded

### isType

public abstract boolean isType(String txt)
Indicates whether a string value appears to have this type. If this returns true, then `decode(String)` should return a value without error.

Parameters:
  `txt` - JSON string representation of a typed value
Returns:
  true if the string is of the right type

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### forName

public static Datatype<?> forName(String name)
Returns the datatype instance for a given type name.

Parameters:
  `name` - datatype name
Returns:
  Datatype instance, or null if none matches name