Class CustomFields

java.lang.Object
com.amalgamasimulation.ecoreutils.CustomFields

public final class CustomFields extends Object
Methods to add/read/remove EObject's custom fields. Custom fields are available for EObjects whose EClass is a subtype of CustomFieldContainer EClass.

There are two classes of custom fields: value field and reference field.

A value field can be serialized to a string. Actually, custom value fields are stored as their string representations.
Supported data types are: all primitive Java types and their wrapper classes; String; Color; DayOfWeek, LocalDateTime, LocalTime, and RealDistribution.

Reference fields are references to other EObjects.

  • Method Details

    • getDouble

      public static double getDouble(CustomFieldContainer container, String customFieldName)
      Extract the value of a Double custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getInt

      public static int getInt(CustomFieldContainer container, String customFieldName)
      Extract the value of an Integer custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getLong

      public static long getLong(CustomFieldContainer container, String customFieldName)
      Extract the value of a Long custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getBoolean

      public static boolean getBoolean(CustomFieldContainer container, String customFieldName)
      Extract the value of a Boolean custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getString

      public static String getString(CustomFieldContainer container, String customFieldName)
      Extract the value of a String custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getColor

      public static Color getColor(CustomFieldContainer container, String customFieldName)
      Extract the value of a Color custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getLocalDateTime

      public static LocalDateTime getLocalDateTime(CustomFieldContainer container, String customFieldName)
      Extract the value of a LocalDateTime custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getLocalTime

      public static LocalTime getLocalTime(CustomFieldContainer container, String customFieldName)
      Extract the value of a LocalTime custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getDayOfWeek

      public static DayOfWeek getDayOfWeek(CustomFieldContainer container, String customFieldName)
      Extract the value of a DayOfWeek custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • getRealDistribution

      public static org.apache.commons.math3.distribution.RealDistribution getRealDistribution(CustomFieldContainer container, String customFieldName)
      Extract the value of a RealDistribution custom field.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field value
    • putValue

      public static <T> CustomField putValue(CustomFieldContainer container, String customFieldName, T customFieldValue)
      Add a custom field to the custom field container. If the custom field container previously contained a field with the same name, the old field value is replaced by the specified value.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      customFieldValue - custom field value
      Returns:
      created CustomField object
    • getReference

      public static <T extends org.eclipse.emf.ecore.EObject> T getReference(CustomFieldContainer container, String referenceName, Class<T> clazz)
      Extract a custom reference field.
      Type Parameters:
      T - type of referenced EObject
      Parameters:
      container - custom field container object
      referenceName - custom field name
      clazz - a Class object that denotes the Java type of the referenced EObject
      Returns:
      referenced object
    • putReference

      public static CustomReferenceField putReference(CustomFieldContainer container, String referenceName, org.eclipse.emf.ecore.EObject object)
      Add a EObject reference to the custom field container. If the custom field container previously contained a custom field with the same name, the old field value is replaced by the specified object.
      If the object is not contained (in EMF sense) anywhere and its EClass has no container feature (i.e., the object is not directly designed to be contained anywhere), then the created CustomReferenceField will act as the container (in EMF sense) for the object. This is done so that the object is not lost, as every object in EMF must have a container. The object's containment may be changed later.
      Parameters:
      container - custom field container object
      referenceName - reference name
      object - reference value
      Returns:
      created CustomReferenceField object
    • removeCustomField

      public static void removeCustomField(CustomFieldContainer container, String customFieldName)
      Removes the custom field from the container. If no custom field exists with such name, the method does nothing and throws no exception.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
    • getCustomField

      public static CustomField getCustomField(CustomFieldContainer container, String customFieldName)
      Returns the custom field with the specified name.
      Parameters:
      container - custom field container object
      customFieldName - custom field name
      Returns:
      custom field, if found; null otherwise