Interface NamedDatatype
- All Superinterfaces:
Comparable<Datatype>,Datatype,ValueDatatype
- All Known Subinterfaces:
EnumDatatype
- All Known Implementing Classes:
CurrencyDatatype,DefaultGenericEnumDatatype,GenericEnumDatatype
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.
-
Field Summary
Fields inherited from interface org.faktorips.datatype.Datatype
BIG_DECIMAL, BOOLEAN, DECIMAL, DOUBLE, GREGORIAN_CALENDAR, INTEGER, LONG, MONEY, PRIMITIVE_BOOLEAN, PRIMITIVE_INT, PRIMITIVE_LONG, STRING, VOID -
Method Summary
Modifier and TypeMethodDescriptiongetValueByName(String name) This method parses the given string and returns the value as an instance of the class this value datatype represents.default ObjectgetValueByName(String name, Locale locale) This method parses the given string and returns the value as an instance of the class this value datatype represents.getValueName(String id) Returns a short description of the value of this datatype specified by the ID.default StringgetValueName(String id, Locale locale) Returns a short description of the value of this datatype specified by the ID.booleanReturnstrueif an implementation of this interface supports names that describe the datatype's value.Methods inherited from interface java.lang.Comparable
compareToMethods inherited from interface org.faktorips.datatype.Datatype
getName, getQualifiedName, hasNullObject, isAbstract, isEnum, isPrimitive, isValueDatatype, isVoidMethods inherited from interface org.faktorips.datatype.ValueDatatype
areValuesEqual, checkReadyToUse, compare, getDefaultValue, getNullObjectId, getValue, getWrapperType, isImmutable, isMutable, isNull, isParsable, supportsCompare, valueToString
-
Method Details
-
isSupportingNames
boolean isSupportingNames()Returnstrueif 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 returnsfalsea call to thegetValueName(String)method is supposed to throw anIllegalStateException. -
getValueName
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 datatypeIllegalStateException- if the datatypedoes not support names
-
getValueName
Returns a short description of the value of this datatype specified by the ID. TheLocalecan be used for internationalization. If no locale is provide theLocale.getDefault()will be used.- Parameters:
id- the ID for the valuelocale- the locale used for internationalization- Throws:
IllegalArgumentException- if the given ID is not a valid ID of this datatypeIllegalStateException- if the datatypedoes not support names
-
getValueByName
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 byValueDatatype.getValue(String)) but of the name as returned bygetValueName(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
This method parses the given string and returns the value as an instance of the class this value datatype represents. TheLocalecan be used for internationalization. If no locale is provide theLocale.getDefault()will be used.The difference to
ValueDatatype.getValue(String)is that the given string is not a representation of the ID (as used byValueDatatype.getValue(String)) but of the name as returned bygetValueName(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 valuelocale- the locale used for internationalization- Returns:
- the value as instance of the class this datatype represents
-