## org.eclipse.emf.edit.command
Class RemoveCommand

    java.lang.Object
      org.eclipse.emf.common.command.AbstractCommand
          org.eclipse.emf.edit.command.AbstractOverrideableCommand
              org.eclipse.emf.edit.command.RemoveCommand

All Implemented Interfaces:
  Command, OverrideableCommand

    public class RemoveCommand

extends AbstractOverrideableCommand

The remove command logically acts upon an owner object that has a collection-type feature from which objects can be removed. The static create methods delegate command creation to `EditingDomain.createCommand`, which may or may not result in the actual creation of an instance of this class.

The implementation of this class is low-level and EMF specific; it allows one or more objects to be removed from a many-valued feature of an owner. i.e., it is almost equivalent of the call

       ((EList)((EObject)owner).eGet((EStructuralFeature)feature)).removeAll((Collection)collection);

It can also be used as a near-equivalent to the call

       ((EList)extent).removeAll((Collection)collection);

which is how root objects are removed from the contents of a resource.

The one difference is that, while `EList.removeAll(Collection)` removes all values equal to a value in the collection, this command will remove no more than one value per value in the collection. When duplicates are allowed and present in the list, this command will first look for identical (`==`) values, in order, and failing that, equal values (`.equals()`).

Like all the low-level commands in this package, the remove command is undoable.

A remove command is an `OverrideableCommand`.

Nested Class Summary

Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand
`AbstractCommand.NonDirtying`

Field Summary
`protected java.util.Collection<?>` `affectedObjects` The is the value returned by `Command.getAffectedObjects()`.
`protected java.util.Collection<java.lang.Object>` `collection` This is the collection of objects being removed.
`protected static java.lang.String` `DESCRIPTION` This caches the description.
`protected static java.lang.String` `DESCRIPTION_FOR_LIST` This caches the description for a list-based command.
`protected EStructuralFeature` `feature` This is the feature of the owner object upon the command will act.
`protected int[]` `indices` These are the indices at which to reinsert the removed objects during an undo so as to achieve the original list order.
`protected static java.lang.String` `LABEL` This caches the label.
`protected EObject` `owner` This is the owner object upon which the command will act.
`protected EList<java.lang.Object>` `ownerList` This is the list from which the command will remove.

Fields inherited from class org.eclipse.emf.edit.command.AbstractOverrideableCommand
`domain, overrideCommand`

Fields inherited from class org.eclipse.emf.common.command.AbstractCommand
`description, isExecutable, isPrepared, label`

Constructor Summary
`RemoveCommand(EditingDomain domain, EList<?> list, java.util.Collection<?> collection)` This constructs a primitive command to remove a collection of values from the specified extent.
`RemoveCommand(EditingDomain domain, EList<?> list, java.lang.Object value)` This constructs a primitive command to remove a particular value from the specified extent.
`RemoveCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.util.Collection<?> collection)` This constructs a primitive command to remove a collection of values from the specified feature of the owner.
`RemoveCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value)` This constructs a primitive command to remove a particular value from the specified feature of the owner.

Method Summary
`protected boolean` `contains(int[] values, int target)` Returns whether the given int array contains the given target value.
`protected boolean` `containsExact(java.util.Collection<?> collection, java.lang.Object target)` Returns whether the given collection contains the given target object itself (according to ==, not .equals()).
`static Command` `create(EditingDomain domain, java.util.Collection<?> collection)` This creates a command to remove multiple objects.
`static Command` `create(EditingDomain domain, java.lang.Object value)` This creates a command to remove an object.
`static Command` `create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.util.Collection<?> collection)` This creates a command to remove a collection of values from the specified feature of the owner.
`static Command` `create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.lang.Object value)` This creates a command to remove a particular value from the specified feature of the owner.
`void` `doExecute()` This is overrideable command's implementation of execute.
`java.util.Collection<?>` `doGetAffectedObjects()` This is overrideable command's implementation of getAffectedObjects.
`java.util.Collection<?>` `doGetResult()` This is overrideable command's implementation of getResult.
`void` `doRedo()` This is overrideable command's implementation of redo.
`void` `doUndo()` This is overrideable command's implementation of undo.
`java.util.Collection<?>` `getCollection()` This returns the collection of objects being removed.
`EStructuralFeature` `getFeature()` This returns the feature of the owner object upon the command will act.
`int[]` `getIndices()` These returns the indices at which to reinsert the removed objects during an undo so as to achieve the original list order.
`EObject` `getOwner()` This returns the owner object upon which the command will act.
`EList<java.lang.Object>` `getOwnerList()` This returns the list from which the command will remove.
`protected void` `merge(java.util.List<java.lang.Object> objects1, int[] indices1, java.util.List<java.lang.Object> objects2, int[] indices2)` Merges two sets of object lists and index arrays, such that both are ordered by increasing indices.
`protected boolean` `prepare()` Called at most once in `AbstractCommand.canExecute()` to give the command an opportunity to ready itself for execution.
`protected boolean` `removeExact(java.util.Collection<?> collection, java.lang.Object target)` Removes the first occurrence of the given target object, itself, from the collection.
`java.lang.String` `toString()` This gives an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of `field:value` pairs.

Methods inherited from class org.eclipse.emf.edit.command.AbstractOverrideableCommand
`canExecute, canUndo, dispose, doCanExecute, doCanUndo, doDispose, doGetChildrenToCopy, doGetDescription, doGetLabel, execute, getAffectedObjects, getChildrenToCopy, getDescription, getDomain, getLabel, getOverride, getOwnerList, getResult, redo, setOverride, undo, updateEMap`

Methods inherited from class org.eclipse.emf.common.command.AbstractCommand
`chain, setDescription, setLabel`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.eclipse.emf.common.command.Command
`chain`

Field Detail

### LABEL

    protected static final java.lang.String LABEL

  This caches the label.

### DESCRIPTION

    protected static final java.lang.String DESCRIPTION

  This caches the description.

### DESCRIPTION_FOR_LIST

    protected static final java.lang.String DESCRIPTION_FOR_LIST

  This caches the description for a list-based command.

### owner

    protected EObject owner

  This is the owner object upon which the command will act. It could be null, in the case that we are dealing with an `EList`.

### feature

    protected EStructuralFeature feature

  This is the feature of the owner object upon the command will act. It could be null, in the case that we are dealing with an `EList`.

### ownerList

    protected EList<java.lang.Object> ownerList

  This is the list from which the command will remove.

### collection

    protected java.util.Collection<java.lang.Object> collection

  This is the collection of objects being removed.

### indices

    protected int[] indices

  These are the indices at which to reinsert the removed objects during an undo so as to achieve the original list order.

### affectedObjects

    protected java.util.Collection<?> affectedObjects

  The is the value returned by `Command.getAffectedObjects()`. The affected objects are different after an execute than after an undo, so we record it.

Constructor Detail

### RemoveCommand

    public RemoveCommand(EditingDomain domain,
                         EObject owner,
                         EStructuralFeature feature,
                         java.lang.Object value)

  This constructs a primitive command to remove a particular value from the specified feature of the owner.

### RemoveCommand

    public RemoveCommand(EditingDomain domain,
                         EObject owner,
                         EStructuralFeature feature,
                         java.util.Collection<?> collection)

  This constructs a primitive command to remove a collection of values from the specified feature of the owner.

### RemoveCommand

    public RemoveCommand(EditingDomain domain,
                         EList<?> list,
                         java.lang.Object value)

  This constructs a primitive command to remove a particular value from the specified extent.

### RemoveCommand

    public RemoveCommand(EditingDomain domain,
                         EList<?> list,
                         java.util.Collection<?> collection)

  This constructs a primitive command to remove a collection of values from the specified extent.

Method Detail

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object value)

  This creates a command to remove an object.

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object owner,
                                 java.lang.Object feature,
                                 java.lang.Object value)

  This creates a command to remove a particular value from the specified feature of the owner.

### create

    public static Command create(EditingDomain domain,
                                 java.util.Collection<?> collection)

  This creates a command to remove multiple objects.

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object owner,
                                 java.lang.Object feature,
                                 java.util.Collection<?> collection)

  This creates a command to remove a collection of values from the specified feature of the owner.

### getOwner

    public EObject getOwner()

  This returns the owner object upon which the command will act. It could be null, in the case that we are dealing with an `EList`.

### getFeature

    public EStructuralFeature getFeature()

  This returns the feature of the owner object upon the command will act. It could be null, in the case that we are dealing with an `EList`.

### getOwnerList

    public EList<java.lang.Object> getOwnerList()

  This returns the list from which the command will remove.

### getCollection

    public java.util.Collection<?> getCollection()

  This returns the collection of objects being removed.

### getIndices

    public int[] getIndices()

  These returns the indices at which to reinsert the removed objects during an undo so as to achieve the original list order.

### prepare

    protected boolean prepare()

  Description copied from class: `AbstractCommand`
  Called at most once in `AbstractCommand.canExecute()` to give the command an opportunity to ready itself for execution. The returned value is stored in `AbstractCommand.canExecute()`. In other words, you can override this method to initialize and to yield a cached value for the all subsequent calls to canExecute.

  Overrides:
    `prepare` in class `AbstractCommand`
  Returns:
    whether the command is executable.

### doExecute

    public void doExecute()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of execute.

  Specified by:
    `doExecute` in interface `OverrideableCommand`
  Specified by:
    `doExecute` in class `AbstractOverrideableCommand`

### containsExact

    protected boolean containsExact(java.util.Collection<?> collection,
                                    java.lang.Object target)

  Returns whether the given collection contains the given target object itself (according to ==, not .equals()).

### contains

    protected boolean contains(int[] values,
                               int target)

  Returns whether the given int array contains the given target value.

### removeExact

    protected boolean removeExact(java.util.Collection<?> collection,
                                  java.lang.Object target)

  Removes the first occurrence of the given target object, itself, from the collection.

### merge

    protected void merge(java.util.List<java.lang.Object> objects1,
                         int[] indices1,
                         java.util.List<java.lang.Object> objects2,
                         int[] indices2)

  Merges two sets of object lists and index arrays, such that both are ordered by increasing indices. The results are stored as the `collection` and `indices`. The two input sets must already be in increasing index order, with the corresponding object-index pairs in the same positions.

### doUndo

    public void doUndo()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of undo.

  Specified by:
    `doUndo` in interface `OverrideableCommand`
  Specified by:
    `doUndo` in class `AbstractOverrideableCommand`

### doRedo

    public void doRedo()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of redo.

  Specified by:
    `doRedo` in interface `OverrideableCommand`
  Specified by:
    `doRedo` in class `AbstractOverrideableCommand`

### doGetResult

    public java.util.Collection<?> doGetResult()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of getResult.

  Specified by:
    `doGetResult` in interface `OverrideableCommand`
  Overrides:
    `doGetResult` in class `AbstractOverrideableCommand`

### doGetAffectedObjects

    public java.util.Collection<?> doGetAffectedObjects()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of getAffectedObjects.

  Specified by:
    `doGetAffectedObjects` in interface `OverrideableCommand`
  Overrides:
    `doGetAffectedObjects` in class `AbstractOverrideableCommand`

### toString

    public java.lang.String toString()

  This gives an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of `field:value` pairs.

  Overrides:
    `toString` in class `AbstractOverrideableCommand`
  Returns:
    string representation.

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.