Class AbstractPrimitiveDatatype

java.lang.Object
org.faktorips.datatype.AbstractDatatype
org.faktorips.datatype.AbstractPrimitiveDatatype
All Implemented Interfaces:
Comparable<Datatype>, Datatype, ValueDatatype
Direct Known Subclasses:
PrimitiveBooleanDatatype, PrimitiveIntegerDatatype, PrimitiveLongDatatype

public abstract class AbstractPrimitiveDatatype extends AbstractDatatype implements ValueDatatype
Abstract base class for datatypes representing a Java primtive like boolean.
Author:
Jan Ortmann
  • Constructor Details

    • AbstractPrimitiveDatatype

      public AbstractPrimitiveDatatype()
  • Method Details

    • isPrimitive

      public boolean isPrimitive()
      Description copied from interface: Datatype
      Returns true if this datatype represents one of Java's primitive types.
      Specified by:
      isPrimitive in interface Datatype
    • isAbstract

      public boolean isAbstract()
      Description copied from interface: Datatype
      Returns true if this datatype is an abstract datatype in means of the object oriented paradigm.
      Specified by:
      isAbstract in interface Datatype
    • isValueDatatype

      public boolean isValueDatatype()
      Description copied from interface: Datatype
      Returns true if this datatype represents values.

      If the method returns true, the datatype can be safely casted to ValueDatatype.

      Specified by:
      isValueDatatype in interface Datatype
    • valueToString

      public String valueToString(Object value)
      Description copied from interface: ValueDatatype
      Returns the string representation of the given value compatible to ValueDatatype.getValue(String).
      Specified by:
      valueToString in interface ValueDatatype
      Parameters:
      value - a value of this datatype
      Returns:
      the value's string representation
      See Also:
    • isParsable

      public boolean isParsable(String value)
      If the value is null or an empty string, false is returned. Returns true if the given string can be parsed to a value of this datatype. Returns false otherwise.
      Specified by:
      isParsable in interface ValueDatatype
    • hasNullObject

      public boolean hasNullObject()
      Description copied from interface: Datatype
      Returns true if the datatype has a special instance representing null, otherwise false. The design pattern is called the null-object pattern.
      Specified by:
      hasNullObject in interface Datatype
      Overrides:
      hasNullObject in class AbstractDatatype
      See Also:
      • NullObject
    • getValue

      public abstract Object getValue(String value)
      Description copied from interface: ValueDatatype
      This 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 NumberFormatException when "twelve" is passed to PrimitiveIntegerDatatype.getValue(String).

      Specified by:
      getValue in interface ValueDatatype
      Parameters:
      value - the string representation of a value
      Returns:
      the value as instance of the class this datatype represents
      See Also:
    • areValuesEqual

      public boolean areValuesEqual(String valueA, String valueB)
      Description copied from interface: ValueDatatype
      Returns true if 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 an Integer, but will not be equal if the datatype is a String.
      Specified by:
      areValuesEqual in interface ValueDatatype
      Parameters:
      valueA - The first parameter to compare
      valueB - The second parameter to compare
      Returns:
      true if the two values are equal according to the datatype, returns false if they are different.
    • compare

      public int compare(String valueA, String valueB)
      Description copied from interface: ValueDatatype
      Compares the values created from the two given strings.
      Specified by:
      compare in interface ValueDatatype
      Parameters:
      valueA - The value to compare to valueB
      valueB - 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:
    • getNullObjectId

      public String getNullObjectId()
      Description copied from interface: ValueDatatype
      Returns the string representation of the special null-object, if the datatype uses one.
      Specified by:
      getNullObjectId in interface ValueDatatype
      See Also:
    • isMutable

      public boolean isMutable()
      Description copied from interface: ValueDatatype
      Returns true if this is a mutable datatype, false if it is an immutable datatype.
      Specified by:
      isMutable in interface ValueDatatype
      Returns:
      whether this is a mutable datatype
    • isImmutable

      public boolean isImmutable()
      Description copied from interface: ValueDatatype
      Returns true if this is an immutable datatype, false otherwise.
      Specified by:
      isImmutable in interface ValueDatatype
      Returns:
      whether this is an immutable datatype