Package org.eclipse.app4mc.amalthea.model

## Class AmaltheaIndex

- Object
- - AmaltheaIndex

    public final class AmaltheaIndex
    extends Object

This class provides static methods for efficient model navigation, search and delete.

An `AmaltheaCrossReferenceAdapter` is created and attached to the root context of the model. The adapter maintains an index that allows fast access to inverse references and an index based on object name.

The method `getInverseReferences` is called from several generated model objects to compute inverse transient references based on the incoming references.

### Method Summary

All Methods
`static void` `buildIndex​(@NonNull Notifier context)` Creates the index explicitly.
`static void` `delete​(@NonNull EObject eObject)` Deletes the object from its `containing` resource and/or its `containing` object as well as from any other feature that references it within the enclosing root context (resource set, resource or root object).
`static void` `deleteAll​(@NonNull Collection<? extends EObject> eObjects)` Deletes the objects from their `containing` resource and/or their `containing` object as well as from any other feature that references it within the enclosing root context (resource set, resource or root object).
`static void` `deleteAll​(@NonNull Collection<? extends EObject> eObjects, boolean recursive)` Deletes the objects from their `containing` resource and/or their `containing` object as well as from any other feature that references it within the enclosing root context (resource set, resource or root object).
`static void` `dumpAdapterInfo​(@NonNull Notifier context, int info, @NonNull PrintStream stream)` Dumps adapter info to a print stream
`static <T extends INamed> Set<T>` `getElements​(@NonNull Notifier context, @NonNull String name, @NonNull Class<T> targetClass)` Finds elements by name and class
`static <T extends INamed> Set<T>` `getElements​(@NonNull Notifier context, @NonNull Pattern namePattern, @NonNull Class<T> targetClass)` Finds elements by name pattern and class
`static IReferable` `getEObjectByID​(@NonNull Notifier context, @Nullable String id)`
`static <T> EList<T>` `getInverseReferences​(@NonNull EObject eObject, @NonNull EReference resultEReference, @NonNull Set<@NonNull EReference> targetEReferences)` Computes a list of objects that refer to an EObject via dedicated references.
`static List<Set<IReferable>>` `getObjectsWithConflictingNames​(@NonNull Notifier context)`
`static Set<EObject>` `getReferringObjects​(@NonNull EObject eObject)` Returns a set of objects that refer to the given `eObject`.
`static <T extends EObject> Set<T>` `getReferringObjects​(@NonNull EObject eObject, @NonNull Class<T> targetClass)` Returns a type filtered set of objects that refer to the given `eObject`.
`static <T extends EObject> Set<T>` `getReferringObjects​(@NonNull EObject eObject, @NonNull Class<T> targetClass, @NonNull EReference targetEReference)` Returns a filtered set of objects that refer to the given `eObject`

### Methods inherited from class Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### getInverseReferences

    public static <T> EList<T> getInverseReferences​(@NonNull EObject eObject,
                                                    @NonNull EReference resultEReference,
                                                    @NonNull Set<@NonNull EReference> targetEReferences)

Computes a list of objects that refer to an EObject via dedicated references.

This method is called from several generated model objects to compute an inverse transient reference based on the incoming references.

Parameters:
  `eObject` - object that implements a derived transient opposite reference
  `resultEReference` - opposite reference definition (resulting objects are computed)
  `targetEReferences` - list of incoming references
Returns:
  EcoreEList.UnmodifiableEList <T>

#### getReferringObjects

    public static Set<EObject> getReferringObjects​(@NonNull EObject eObject)

Returns a set of objects that refer to the given `eObject`.

Parameters:
  `eObject` -
Returns:
  Set of objects (EObject)

#### getReferringObjects

    public static <T extends EObject> Set<T> getReferringObjects​(@NonNull EObject eObject,
                                                                 @NonNull Class<T> targetClass)

Returns a type filtered set of objects that refer to the given `eObject`.

Parameters:
  `eObject` -
  `targetClass` -
Returns:
  Set of objects of given type <T extends EObject>

#### getReferringObjects

    public static <T extends EObject> Set<T> getReferringObjects​(@NonNull EObject eObject,
                                                                 @NonNull Class<T> targetClass,
                                                                 @NonNull EReference targetEReference)

Returns a filtered set of objects that refer to the given `eObject`

Filters:

- type (`targetClass`)
- reference (`targetEReference`)

Parameters:
  `eObject` -
  `targetClass` -
  `targetEReference` -
Returns:
  Set of objects of given type <T extends EObject>

#### getEObjectByID

    public static IReferable getEObjectByID​(@NonNull Notifier context,
                                            @Nullable String id)

#### getObjectsWithConflictingNames

    public static List<Set<IReferable>> getObjectsWithConflictingNames​(@NonNull Notifier context)

#### buildIndex

    public static void buildIndex​(@NonNull Notifier context)

Creates the index explicitly. If the index is already available the method will have no effect.

This method is optional. Normally the index will be built on demand.

Parameters:
  `eObject` -

#### delete

    public static void delete​(@NonNull EObject eObject)

Deletes the object from its `containing` resource and/or its `containing` object as well as from any other feature that references it within the enclosing root context (resource set, resource or root object). Contained children of the object are similarly removed from any features that reference them.

Parameters:
  `eObject` - object to delete

#### deleteAll

    public static void deleteAll​(@NonNull Collection<? extends EObject> eObjects)

Deletes the objects from their `containing` resource and/or their `containing` object as well as from any other feature that references it within the enclosing root context (resource set, resource or root object). Contained children of the object are similarly removed from any features that reference them.

Parameters:
  `eObjects` - objects to delete

#### deleteAll

    public static void deleteAll​(@NonNull Collection<? extends EObject> eObjects,
                                 boolean recursive)

Deletes the objects from their `containing` resource and/or their `containing` object as well as from any other feature that references it within the enclosing root context (resource set, resource or root object). If recursive is true, contained children of the object are similarly removed from any features that reference them.

Parameters:
  `eObjects` - objects to delete
  `recursive` - true: contained children should also be deleted

#### getElements

    public static <T extends INamed> Set<T> getElements​(@NonNull Notifier context,
                                                        @NonNull String name,
                                                        @NonNull Class<T> targetClass)

Finds elements by name and class

Parameters:
  `context` - EObject, Resource or ResourceSet
  `name` - String
  `targetClass` - for example: `Label.class`
Returns:
  Set of named objects (INamed)

#### getElements

    public static <T extends INamed> Set<T> getElements​(@NonNull Notifier context,
                                                        @NonNull Pattern namePattern,
                                                        @NonNull Class<T> targetClass)

Finds elements by name pattern and class

Parameters:
  `context` - EObject, Resource or ResourceSet
  `namePattern` - for example: `Pattern.compile("Prefix_.*")`
  `targetClass` - for example: `Label.class`
Returns:
  Set of named objects (INamed)

#### dumpAdapterInfo

    public static void dumpAdapterInfo​(@NonNull Notifier context,
                                       int info,
                                       @NonNull PrintStream stream)

Dumps adapter info to a print stream

Parameters:
  `context` - EObject, Resource or ResourceSet
  `info` - content selector
  - 1 - basic adapter info (resources, size of maps)
  - 2 - cross reference map
  - 3 - name index
  `stream` - output stream (use System.out to print to console)