Interface NamedDatatype

All Superinterfaces:
Comparable<Datatype>, Datatype, ValueDatatype
All Known Subinterfaces:
EnumDatatype
All Known Implementing Classes:
CurrencyDatatype, DefaultGenericEnumDatatype, GenericEnumDatatype

public interface NamedDatatype extends ValueDatatype
A ValueDatatype that can have a human readable name (for example currency symbols like $ and € or full names like "annual payment" or "monthly payment") for each of its values. That name can be displayed in addition to or instead of the actual value (like USD or EUR or a payment mode 1 or 12), which is used as the technical ID and to persist values of the datatype.

Note that due to the inheritance hierarchy of datatypes, presence of this interface is no guarantee that the implementation actually supports names - only those that return true from their isSupportingNames() method do.

  • Method Details

    • isSupportingNames

      boolean isSupportingNames()
      Returns true if an implementation of this interface supports names that describe the datatype's value. E.g. an enum datatype PaymentMode might return the name "annual" for the annual payment mode with ID "1". If this method returns false a call to the getValueName(String) method is supposed to throw an IllegalStateException.
    • getValueName

      String getValueName(String id)
      Returns a short description of the value of this datatype specified by the ID.
      Throws:
      IllegalArgumentException - if the given ID is not a valid ID of this datatype
      IllegalStateException - if the datatype does not support names
    • getValueName

      default String getValueName(String id, Locale locale)
      Returns a short description of the value of this datatype specified by the ID. The Locale can be used for internationalization. If no locale is provide the Locale.getDefault() will be used.
      Parameters:
      id - the ID for the value
      locale - the locale used for internationalization
      Throws:
      IllegalArgumentException - if the given ID is not a valid ID of this datatype
      IllegalStateException - if the datatype does not support names
    • getValueByName

      Object getValueByName(String name)
      This method parses the given string and returns the value as an instance of the class this value datatype represents.

      The difference to ValueDatatype.getValue(String) is that the given string is not a representation of the ID (as used by ValueDatatype.getValue(String)) but of the name as returned by getValueName(String).

      Use with caution: During development time Faktor-IPS maintains all values with their string representation. This allows to change the value's datatype without the need to convert the value from one class to another (e.g. if the string representation is 42 you can change the datatype from integer to string without converting the integer object to a string object.

      Parameters:
      name - the name representation of a value
      Returns:
      the value as instance of the class this datatype represents
    • getValueByName

      default Object getValueByName(String name, Locale locale)
      This method parses the given string and returns the value as an instance of the class this value datatype represents. The Locale can be used for internationalization. If no locale is provide the Locale.getDefault() will be used.

      The difference to ValueDatatype.getValue(String) is that the given string is not a representation of the ID (as used by ValueDatatype.getValue(String)) but of the name as returned by getValueName(String,Locale).

      Use with caution: During development time Faktor-IPS maintains all values with their string representation. This allows to change the value's datatype without the need to convert the value from one class to another (e.g. if the string representation is 42 you can change the datatype from integer to string without converting the integer object to a string object.

      Parameters:
      name - the name representation of a value
      locale - the locale used for internationalization
      Returns:
      the value as instance of the class this datatype represents