Class GenericValueDatatype
- All Implemented Interfaces:
Comparable<Datatype>,Datatype,ValueDatatype
- Direct Known Subclasses:
DefaultGenericValueDatatype,GenericEnumDatatype
This allows to defined a datatype based on a Java class by declaring it, instead of writing code.
- Author:
- Jan Ortmann
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanareValuesEqual(String valueA, String valueB) Returnstrueif both given strings represent the same value defined by this datatype.org.faktorips.runtime.MessageListValidates the value datatype and returns a message list containing error messages if the datatype is invalid.protected voidintCompares the values created from the two given strings.intbooleanabstract Class<?> Returns the class represented by this datatype.abstract StringReturns the name of the class represented by this datatype.org.faktorips.util.MethodAccessReturns the datatype's default value.Returns the java class that is represented by this generic datatypegetName()Returns the datatype's name.Returns the String identification of the special NullObject.Returns the datatype's qualified name.protected org.faktorips.util.MethodAccessThis method parses the given string and returns the value as an instance of the class this value datatype represents.If this datatype represents a primitive type, this method returns the datatype that represents the wrapper class.inthashCode()booleanReturnstrueif the datatype has a special instance representing null.booleanReturnstrueif this datatype is an abstract datatype in means of the object oriented paradigm.booleanisEnum()Returnstrueif this value datatype is an enum datatype.booleanReturnstrueif this is an immutable datatype,falseotherwise.booleanReturnstrueif this is a mutable datatype,falseif it is an immutable datatype.booleanReturnstrueif the given string isnullor the representation of the null object (if the datatype value class makes use of the null object pattern.)booleanisParsable(String value) Returnstrueif the given string can be parsed to a value of this datatype.booleanReturnstrueif this datatype represents one of Java's primitive types.booleanReturnstrueif this datatype represents values.booleanisVoid()voidsetAllValuesMethodName(String getAllValuesMethodName) voidsetIsParsableMethodName(String isParsableMethodName) voidsetNullObjectDefined(boolean flag) Sets if this datatype is an application of the NullObject pattern.voidsetNullObjectId(String specialNullValueId) Sets the String identification of the special NullObject.voidsetQualifiedName(String qualifiedName) voidsetToStringMethodName(String toStringMethodName) voidsetValueOfMethodName(String valueOfMethodName) booleantoString()valueToString(Object value) Returns the string representation of the given value compatible toValueDatatype.getValue(String).
-
Field Details
-
MSGCODE_PREFIX
- See Also:
-
MSGCODE_JAVACLASS_NOT_FOUND
- See Also:
-
MSGCODE_PREFIX_GET_VALUE_METHOD
- See Also:
-
MSGCODE_PREFIX_IS_PARSABLE_METHOD
- See Also:
-
MSGCODE_PREFIX_TO_STRING_METHOD
- See Also:
-
MSGCODE_PREFIX_VALUE_OF_METHOD
- See Also:
-
MSGCODE_SPECIALCASE_NULL_NOT_FOUND
- See Also:
-
MSGCODE_SPECIALCASE_NULL_IS_NOT_NULL
- See Also:
-
MSGCODE_GETVALUE_METHOD_NOT_FOUND
- See Also:
-
MSGCODE_ISPARSABLE_METHOD_NOT_FOUND
- See Also:
-
MSGCODE_TOSTRING_METHOD_NOT_FOUND
- See Also:
-
MSGCODE_VALUE_OF_METHOD_NOT_FOUND
- See Also:
-
MSGCODE_PREFIX_GET_ALL_VALUES_METHOD
- See Also:
-
MSGCODE_GET_ALL_VALUES_METHOD_NOT_FOUND
- See Also:
-
-
Constructor Details
-
GenericValueDatatype
public GenericValueDatatype()
-
-
Method Details
-
getDefaultValue
Description copied from interface:ValueDatatypeReturns the datatype's default value. For datatypes representing objects the method returnsnull. For datatypes representing Java primitives the Java default value is returned, e.g. 0 for int.- Specified by:
getDefaultValuein interfaceValueDatatype- See Also:
-
getAdaptedClass
Returns the class represented by this datatype. If the class can't be found,nullis returned. In this case thevalidate()method returns a message list containing an error message. -
getAdaptedClassName
Returns the name of the class represented by this datatype. This method must return a value, even if the class itself can't be found. -
checkReadyToUse
public org.faktorips.runtime.MessageList checkReadyToUse()Description copied from interface:ValueDatatypeValidates the value datatype and returns a message list containing error messages if the datatype is invalid. If the datatype is valid an empty list is returned.Value datatypes like the predefined datatypes (defined by the constants in this class) are always valid. However generic datatypes that implement this interface might be invalid.
- Specified by:
checkReadyToUsein interfaceValueDatatype
-
getToStringMethod
protected org.faktorips.util.MethodAccess getToStringMethod() -
getIsParsableMethodName
-
setIsParsableMethodName
-
hasNullObject
public boolean hasNullObject()Returnstrueif the datatype has a special instance representing null. (This is known as the NullObject pattern).- Specified by:
hasNullObjectin interfaceDatatype- See Also:
-
setNullObjectDefined
public void setNullObjectDefined(boolean flag) Sets if this datatype is an application of the NullObject pattern. -
getNullObjectId
Returns the String identification of the special NullObject.- Specified by:
getNullObjectIdin interfaceValueDatatype- See Also:
-
setNullObjectId
Sets the String identification of the special NullObject. -
getValueOfMethodName
-
setValueOfMethodName
-
getToStringMethodName
-
setToStringMethodName
-
setQualifiedName
-
getWrapperType
Description copied from interface:ValueDatatypeIf this datatype represents a primitive type, this method returns the datatype that represents the wrapper class. Returnsnullif this datatype does not represent a primitive.- Specified by:
getWrapperTypein interfaceValueDatatype
-
isParsable
Description copied from interface:ValueDatatypeReturnstrueif the given string can be parsed to a value of this datatype. Returnsfalseotherwise.- Specified by:
isParsablein interfaceValueDatatype
-
getValue
Description copied from interface:ValueDatatypeThis method parses the given string and returns the value as an instance of the class this value datatype represents.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.
May throw different exceptions if the given string does not represent any value, for example a
NumberFormatExceptionwhen"twelve"is passed toPrimitiveIntegerDatatype.getValue(String).- Specified by:
getValuein interfaceValueDatatype- Parameters:
value- the string representation of a value- Returns:
- the value as instance of the class this datatype represents
- See Also:
-
valueToString
Description copied from interface:ValueDatatypeReturns the string representation of the given value compatible toValueDatatype.getValue(String).- Specified by:
valueToStringin interfaceValueDatatype- Parameters:
value- a value of this datatype- Returns:
- the value's string representation
- See Also:
-
isNull
Description copied from interface:ValueDatatypeReturnstrueif the given string isnullor the representation of the null object (if the datatype value class makes use of the null object pattern.) Returnsfalseotherwise.- Specified by:
isNullin interfaceValueDatatype- See Also:
-
isEnum
public boolean isEnum()Description copied from interface:DatatypeReturnstrueif this value datatype is an enum datatype. In this case the instance can be cast toEnumDatatype. Returnsfalseotherwise. -
getName
Description copied from interface:DatatypeReturns the datatype's name. -
getQualifiedName
Description copied from interface:DatatypeReturns the datatype's qualified name.The qualified name identifies the datatype.
- Specified by:
getQualifiedNamein interfaceDatatype
-
hashCode
public int hashCode() -
equals
-
isVoid
public boolean isVoid()Description copied from interface:Datatype -
isPrimitive
public boolean isPrimitive()Description copied from interface:DatatypeReturnstrueif this datatype represents one of Java's primitive types.- Specified by:
isPrimitivein interfaceDatatype
-
isAbstract
public boolean isAbstract()Description copied from interface:DatatypeReturnstrueif this datatype is an abstract datatype in means of the object oriented paradigm.- Specified by:
isAbstractin interfaceDatatype
-
isValueDatatype
public boolean isValueDatatype()Description copied from interface:DatatypeReturnstrueif this datatype represents values.If the method returns
true, the datatype can be safely casted toValueDatatype.- Specified by:
isValueDatatypein interfaceDatatype
-
getJavaClassName
Returns the java class that is represented by this generic datatype -
compareTo
- Specified by:
compareToin interfaceComparable<Datatype>
-
toString
-
clearCache
protected void clearCache() -
areValuesEqual
Description copied from interface:ValueDatatypeReturnstrueif both given strings represent the same value defined by this datatype. The String " 1" (a blank followed by the char '1') and "1" (just the char '1') are equal if the datatype is anInteger, but will not be equal if the datatype is aString.- Specified by:
areValuesEqualin interfaceValueDatatype- Parameters:
valueA- The first parameter to comparevalueB- The second parameter to compare- Returns:
trueif the two values are equal according to the datatype, returnsfalseif they are different.
-
compare
Description copied from interface:ValueDatatypeCompares the values created from the two given strings.- Specified by:
comparein interfaceValueDatatype- Parameters:
valueA- The value to compare to valueBvalueB- The value to compare to valueA- Returns:
- A value less than 0 if valueA is less than valueB, 0 if valueA is equal to valueB and a value greater than 0 if valueA is greater than valueB.
- See Also:
-
supportsCompare
public boolean supportsCompare()- Specified by:
supportsComparein interfaceValueDatatype- Returns:
trueif this datatype is able to compare two values.
-
isImmutable
public boolean isImmutable()Description copied from interface:ValueDatatypeReturnstrueif this is an immutable datatype,falseotherwise.- Specified by:
isImmutablein interfaceValueDatatype- Returns:
- whether this is an immutable datatype
-
isMutable
public boolean isMutable()Description copied from interface:ValueDatatypeReturnstrueif this is a mutable datatype,falseif it is an immutable datatype.- Specified by:
isMutablein interfaceValueDatatype- Returns:
- whether this is a mutable datatype
-
getAllValuesMethod
public org.faktorips.util.MethodAccess getAllValuesMethod() -
setAllValuesMethodName
-
getAllValuesMethodName
-