Class CustomFields
java.lang.Object
com.amalgamasimulation.ecoreutils.CustomFields
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 Summary
Modifier and TypeMethodDescriptionstatic booleangetBoolean(CustomFieldContainer container, String customFieldName) Extract the value of a Boolean custom field.static ColorgetColor(CustomFieldContainer container, String customFieldName) Extract the value of a Color custom field.static CustomFieldgetCustomField(CustomFieldContainer container, String customFieldName) Returns the custom field with the specified name.static DayOfWeekgetDayOfWeek(CustomFieldContainer container, String customFieldName) Extract the value of a DayOfWeek custom field.static doublegetDouble(CustomFieldContainer container, String customFieldName) Extract the value of a Double custom field.static intgetInt(CustomFieldContainer container, String customFieldName) Extract the value of an Integer custom field.static LocalDateTimegetLocalDateTime(CustomFieldContainer container, String customFieldName) Extract the value of a LocalDateTime custom field.static LocalTimegetLocalTime(CustomFieldContainer container, String customFieldName) Extract the value of a LocalTime custom field.static longgetLong(CustomFieldContainer container, String customFieldName) Extract the value of a Long custom field.static org.apache.commons.math3.distribution.RealDistributiongetRealDistribution(CustomFieldContainer container, String customFieldName) Extract the value of a RealDistribution custom field.static <T extends org.eclipse.emf.ecore.EObject>
TgetReference(CustomFieldContainer container, String referenceName, Class<T> clazz) Extract a custom reference field.static StringgetString(CustomFieldContainer container, String customFieldName) Extract the value of a String custom field.static CustomReferenceFieldputReference(CustomFieldContainer container, String referenceName, org.eclipse.emf.ecore.EObject object) Add a EObject reference to the custom field container.static <T> CustomFieldputValue(CustomFieldContainer container, String customFieldName, T customFieldValue) Add a custom field to the custom field container.static voidremoveCustomField(CustomFieldContainer container, String customFieldName) Removes the custom field from the container.
-
Method Details
-
getDouble
Extract the value of a Double custom field.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field value
-
getInt
Extract the value of an Integer custom field.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field value
-
getLong
Extract the value of a Long custom field.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field value
-
getBoolean
Extract the value of a Boolean custom field.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field value
-
getString
Extract the value of a String custom field.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field value
-
getColor
Extract the value of a Color custom field.- Parameters:
container- custom field container objectcustomFieldName- 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 objectcustomFieldName- custom field name- Returns:
- custom field value
-
getLocalTime
Extract the value of a LocalTime custom field.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field value
-
getDayOfWeek
Extract the value of a DayOfWeek custom field.- Parameters:
container- custom field container objectcustomFieldName- 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 objectcustomFieldName- 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 objectcustomFieldName- custom field namecustomFieldValue- 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 objectreferenceName- custom field nameclazz- 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 objectreferenceName- reference nameobject- reference value- Returns:
- created CustomReferenceField object
-
removeCustomField
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 objectcustomFieldName- custom field name
-
getCustomField
Returns the custom field with the specified name.- Parameters:
container- custom field container objectcustomFieldName- custom field name- Returns:
- custom field, if found; null otherwise
-