Class ListOfValueDatatypeHelper

java.lang.Object
org.faktorips.codegen.dthelpers.AbstractDatatypeHelper
org.faktorips.codegen.dthelpers.ListOfValueDatatypeHelper
All Implemented Interfaces:
BaseDatatypeHelper<JavaCodeFragment>, DatatypeHelper

public class ListOfValueDatatypeHelper extends AbstractDatatypeHelper
A helper class for lists of values. There is no data type for lists though. The data type specified in the constructor is the data type of the elements in the list. valueOfExpression(String) expects a list as expression and returns code that creates a copy of that list. newInstance(String) returns code that creates an empty list. The given value will be ignored.
Author:
Stefan Widmaier
  • Constructor Details

    • ListOfValueDatatypeHelper

      public ListOfValueDatatypeHelper(DatatypeHelper elementDatatypeHelper)
  • Method Details

    • getDatatype

      public ListOfTypeDatatype getDatatype()
      Description copied from interface: DatatypeHelper
      Returns the datatype this is a helper for.
      Specified by:
      getDatatype in interface BaseDatatypeHelper<JavaCodeFragment>
      Specified by:
      getDatatype in interface DatatypeHelper
      Overrides:
      getDatatype in class AbstractDatatypeHelper
    • getBasicDatatype

      public Datatype getBasicDatatype()
      Returns the ValueDatatype of the elements in the list.
    • getBasicJavaClassName

      public String getBasicJavaClassName()
    • getJavaClassName

      public String getJavaClassName()
      Description copied from interface: DatatypeHelper
      Returns the qualified Java class name the datatype represents.
    • valueOfExpression

      protected JavaCodeFragment valueOfExpression(String expression)
      Expects a list as expression and returns code that creates a copy of that list. This method is supposed to be overridden by subclasses.

      It is used within the newInstanceFromExpression(String) method. It returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression.

      If the expression is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object. Preconditions: Expression may not be null or empty. When evaluated the expression must return a String.

      Specified by:
      valueOfExpression in class AbstractDatatypeHelper
    • newInstance

      public JavaCodeFragment newInstance(String expression)
      Returns code that creates a list where the given expression is used as a constructor argument. Returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given value. If the value is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object.
    • referenceOrSafeCopyIfNeccessary

      public JavaCodeFragment referenceOrSafeCopyIfNeccessary(String expression)
      Description copied from interface: DatatypeHelper
      If this is a helper for a mutable data type (like GregorianCalendar for example) this method return the code fragment that creates a copy of the given expression. For immutable data types this method returns the expression unmodified.
      Specified by:
      referenceOrSafeCopyIfNeccessary in interface DatatypeHelper
      Overrides:
      referenceOrSafeCopyIfNeccessary in class AbstractDatatypeHelper
      Parameters:
      expression - An expression (as Java sourcecode)
      Returns:
      s. above
    • getDeclarationJavaTypeFragment

      public JavaCodeFragment getDeclarationJavaTypeFragment()
      Returns code for a list-variable or -argument declarations. e.g. List<ElementJavaClassName>.
    • getValueSetJavaClassName

      public String getValueSetJavaClassName()
      Description copied from interface: DatatypeHelper
      Returns the qualified Java class name for the value datatype. This is the same as DatatypeHelper.getJavaClassName() for most datatypes but might differ for example for List typed values, where the datatype of the list's contents is returned.
    • getRangeJavaClassName

      public String getRangeJavaClassName(boolean useTypesafeCollections)
      Description copied from interface: DatatypeHelper
      Returns the qualified Java class name of the range class of the datatype this is a helper for.
      Specified by:
      getRangeJavaClassName in interface DatatypeHelper
      Overrides:
      getRangeJavaClassName in class AbstractDatatypeHelper
    • newRangeInstance

      public JavaCodeFragment newRangeInstance(JavaCodeFragment lowerBoundExp, JavaCodeFragment upperBoundExp, JavaCodeFragment stepExp, JavaCodeFragment containsNullExp, boolean useTypesafeCollections)
      Description copied from interface: DatatypeHelper
      Returns a JavaCodeFragment containing the source code to create a new instance of a type specific range.
      Specified by:
      newRangeInstance in interface DatatypeHelper
      Overrides:
      newRangeInstance in class AbstractDatatypeHelper
      Parameters:
      lowerBoundExp - the lower bound expression of the range. Can be null to indicate that the lower bound is open
      upperBoundExp - the upper bound expression of the range. Can be null to indicate that the upper bound is open.
      stepExp - the minimum increment expression for values within the lower and upper bounds. Can be null to indicate that this is a continuous range.
      containsNullExp - the containsNull expression
      Returns:
      the code fragment to create a new range instance. Can be null to indicate that a range is not supported.
    • createCastExpression

      public JavaCodeFragment createCastExpression(String bound)
      Description copied from interface: DatatypeHelper
      Returns a JavaCodeFragment with a new value instance, adding a cast to the value's data type in case the value is empty to avoid problems with generics.
      Specified by:
      createCastExpression in interface DatatypeHelper
      Overrides:
      createCastExpression in class AbstractDatatypeHelper
      Parameters:
      bound - the String representation of a value of this datatype
      Returns:
      a JavaCodeFragment containing the code to create (and cast) the value
    • newValueInstance

      public JavaCodeFragment newValueInstance(String value)
      Description copied from interface: DatatypeHelper
      Returns a JavaCodeFragment for the value datatype. This is the same as DatatypeHelper.newInstance(String) for most datatypes but might differ for example for List typed values, where the datatype of the list's contents is returned.