Class EMFUtils

Object
EMFUtils

public class EMFUtils extends Object
Utility methods for working with emf model objects.
Author:
Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    add(EObject eobject, String property, Object value)
    Adds a value to a multi-valued propert of an eobject.
    static void
    add(EObject eobject, EStructuralFeature feature, Object value)
    Adds a value to a multi-valued propert of an eobject.
    static EObject
    clone(EObject prototype, EFactory factory, boolean deep)
    Clones an eobject, with the option of performing a deep clone in which referenced eobjects are also cloned.
    static void
    copy(EObject source, EObject target)
    Copies all the properties from one object to anoter.
    static EStructuralFeature
    feature(EObject eobject, String property)
    Method which looks up a structure feature of an eobject, first doing an exact name match, then a case insensitive one.
    static List<EStructuralFeature>
    features(EObject eobject, Class<?> propertyType)
    Method which looks up structural features of an eobject by type.
    static List<Object>
    get(List objects, String property)
    Obtains the values of a particular property on each EObject in a list.
    static Object
    get(EObject eobject, String property)
    Gets the property of an eobject.
    static Object
    getFromMap(EObject eobject, String property, Object key)
    Returns a value from a map based property of an eobject.
    static Object
    getFromMapSafe(EObject eobject, String property, String key)
    Returns a value from a map based property of an eobject, handling null cases and the case where the property is not actually a map.
    static boolean
    has(EObject eobject, String property)
    Determines if an eobject has a particular property.
    static boolean
    isCollection(EObject eobject, String property)
    Determines if a property of an eobject is a collection.
    static boolean
    isCollection(EObject eobject, EStructuralFeature feature)
    Determines if a feature of an eobject is a collection.
    static boolean
    isSet(List objects, String property)
    Determines if a particular propety has been set on each EObject in a list.
    static boolean
    isSet(EObject eobject, String property)
    Determines if a particular propety has been set on an eobject.
    static boolean
    isUnset(List objects, String property)
    Determines if a particular propety is unset on each EObject in a list.
    static void
    set(List objects, String property, Object value)
    Sets a particular property on each EObject in a list to a particular value.
    static void
    set(List objects, String property, List values)
    Sets a particular property on each EObject in a list to a particular value.
    static void
    set(EObject eobject, String property, Object value)
    Sets a property of an eobject.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EMFUtils

      public EMFUtils()
  • Method Details

    • has

      public static boolean has(EObject eobject, String property)
      Determines if an eobject has a particular property.
      Parameters:
      eobject - The eobject.
      property - The property to check for.
      Returns:
      true if the property exists, otherwise false</code.
    • set

      public static void set(EObject eobject, String property, Object value)
      Sets a property of an eobject.
      Parameters:
      eobject - THe object.
      property - The property to set.
      value - The value of the property.
    • get

      public static Object get(EObject eobject, String property)
      Gets the property of an eobject.
      Parameters:
      eobject - The object.
      property - The property to get.
      Returns:
      The value of the property.
    • getFromMap

      public static Object getFromMap(EObject eobject, String property, Object key)
      Returns a value from a map based property of an eobject.

      This method does not sort of checking of the property, use getFromMapSafe(EObject, String, String) for more leniency.

      Parameters:
      eobject - The object.
      property - The map property.
      key - The key to obtain from the map.
      Returns:
      The map value, possibly null.
    • getFromMapSafe

      public static Object getFromMapSafe(EObject eobject, String property, String key)
      Returns a value from a map based property of an eobject, handling null cases and the case where the property is not actually a map.

      This method returns null in cases where the the property does not exist, or it is not a map.

      Parameters:
      eobject - The object.
      property - The map property.
      key - The key to obtain from the map.
      Returns:
      The map value, possibly null.
    • add

      public static void add(EObject eobject, String property, Object value)
      Adds a value to a multi-valued propert of an eobject.

      The property must map to a multi-valued property of the eobject. The isCollection(EObject, String) method can be used to test this.

      Parameters:
      eobject - The object.
      property - The multi-valued property.
      value - The value to add.
    • add

      public static void add(EObject eobject, EStructuralFeature feature, Object value)
      Adds a value to a multi-valued propert of an eobject.

      The feature must map to a multi-valued property of the eobject. The #isCollection(EStructuralFeature) method can be used to test this.

      Parameters:
      eobject - The object.
      feature - The multi-valued feature.
      value - The value to add.
    • isCollection

      public static boolean isCollection(EObject eobject, String property)
      Determines if a property of an eobject is a collection.

      In the event the property does not exist, this method will return false

      Returns:
      true if hte property is a collection, otherwise false
    • isCollection

      public static boolean isCollection(EObject eobject, EStructuralFeature feature)
      Determines if a feature of an eobject is a collection.
      Returns:
      true if the feature is a collection, otherwise false
    • feature

      public static EStructuralFeature feature(EObject eobject, String property)
      Method which looks up a structure feature of an eobject, first doing an exact name match, then a case insensitive one.
      Parameters:
      eobject - The eobject.
      property - The property
      Returns:
      The structure feature, or null if not found.
    • features

      public static List<EStructuralFeature> features(EObject eobject, Class<?> propertyType)
      Method which looks up structural features of an eobject by type.
      Parameters:
      eobject - The eobject.
      propertyType - The type of the properties.
      Returns:
      The list of structure features, or an empty list if none are found.
    • set

      public static void set(List objects, String property, List values)
      Sets a particular property on each EObject in a list to a particular value.

      The following must hold: objects.size() == values.size()

      Parameters:
      objects - A list of EObject.
      property - The property to set on each eobject in objects
      values - The value to set on each eobjct in objects
    • set

      public static void set(List objects, String property, Object value)
      Sets a particular property on each EObject in a list to a particular value.

      Parameters:
      objects - A list of EObject.
      property - The property to set on each eobject in objects
      value - The value to set on each eobjct in objects
    • get

      public static List<Object> get(List objects, String property)
      Obtains the values of a particular property on each EObject in a list.
      Parameters:
      objects - A list of EObject.
      property - The property to obtain.
      Returns:
      The list of values.
    • isSet

      public static boolean isSet(EObject eobject, String property)
      Determines if a particular propety has been set on an eobject.
      Parameters:
      eobject - The eobject.
      property - The property to check.
      Returns:
      true if the property has been set, otherwise false
    • isSet

      public static boolean isSet(List objects, String property)
      Determines if a particular propety has been set on each EObject in a list.
      Parameters:
      objects - A list of EObject
      property - The property to check.
      Returns:
      true if every element in the list has been set, otherwise false
    • isUnset

      public static boolean isUnset(List objects, String property)
      Determines if a particular propety is unset on each EObject in a list.
      Parameters:
      objects - A list of EObject
      property - The property to check.
      Returns:
      true if every element in the list is unset, otherwise false
    • clone

      public static EObject clone(EObject prototype, EFactory factory, boolean deep)
      Clones an eobject, with the option of performing a deep clone in which referenced eobjects are also cloned.
      Parameters:
      prototype - The object to be cloned from.
      factory - The factory used to create the clone.
      deep - indicating wether to perform a deep clone.
      Returns:
      THe cloned object, with all properties the same to the original.
    • copy

      public static void copy(EObject source, EObject target)
      Copies all the properties from one object to anoter.
      Parameters:
      source - The object to copy from.
      target - The object to copy to.