Module jdk.dynalink
Package jdk.dynalink

## Class NamedOperation

- java.lang.Object
- - jdk.dynalink.NamedOperation

All Implemented Interfaces:
  Operation

    public final class NamedOperation
    extends Object
    implements Operation

Operation that associates a name with another operation. Typically used with operations that normally take a name or an index to bind them to a fixed name. E.g. `new NamedOperation(StandardOperation.GET_PROPERTY, "color")` will be a named operation for getting the property named "color" on the object it is applied to, and `new NamedOperation(StandardOperation.GET_ELEMENT, 3)` will be a named operation for getting the element at index 3 from the collection it is applied to. In these cases, the expected signature of the call site for the operation will change to no longer include the name parameter. Specifically, the documentation for all `StandardOperation` members describes how they are affected by being incorporated into a named operation.

### Constructor Summary

Constructors
Constructor and Description
`NamedOperation(Operation baseOperation, Object name)` Creates a new named operation.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`boolean` `equals(Object obj)` Compares this named operation to another object.
`Operation` `getBaseOperation()` Returns the base operation of this named operation.
`static Operation` `getBaseOperation(Operation op)` If the passed operation is a named operation, returns its `getBaseOperation()`, otherwise returns the operation as is.
`Object` `getName()` Returns the name of this named operation.
`static Object` `getName(Operation op)` If the passed operation is a named operation, returns its `getName()`, otherwise returns null.
`int` `hashCode()` Returns the hash code of this named operation.
`String` `toString()` Returns the string representation of this named operation.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### NamedOperation

    public NamedOperation(Operation baseOperation,
                          Object name)

Creates a new named operation.

Parameters:
  `baseOperation` - the base operation that is associated with a name.
  `name` - the name associated with the base operation. Note that the name is not necessarily a string, but can be an arbitrary object. As the name is used for addressing, it can be an `Integer` when meant to be used as an index into an array or list etc.
Throws:
  `NullPointerException` - if either `baseOperation` or `name` is null.
  `IllegalArgumentException` - if `baseOperation` is itself a `NamedOperation`.

### Method Detail

#### getBaseOperation

    public Operation getBaseOperation()

Returns the base operation of this named operation.

Returns:
  the base operation of this named operation.

#### getName

    public Object getName()

Returns the name of this named operation.

Returns:
  the name of this named operation.

#### equals

    public boolean equals(Object obj)

Compares this named operation to another object. Returns true if the other object is also a named operation, and both their base operations and name are equal.

Overrides:
  `equals` in class `Object`
Parameters:
  `obj` - the reference object with which to compare.
Returns:
  `true` if this object is the same as the obj argument; `false` otherwise.
See Also:
  `Object.hashCode()`, `HashMap`

#### hashCode

    public int hashCode()

Returns the hash code of this named operation. It is defined to be equal to `baseOperation.hashCode() + 31 * name.hashCode()`.

Overrides:
  `hashCode` in class `Object`
Returns:
  a hash code value for this object.
See Also:
  `Object.equals(java.lang.Object)`, `System.identityHashCode(java.lang.Object)`

#### toString

    public String toString()

Returns the string representation of this named operation. It is defined to be equal to `baseOperation.toString() + ":" + name.toString()`.

Overrides:
  `toString` in class `Object`
Returns:
  a string representation of the object.

#### getBaseOperation

    public static Operation getBaseOperation(Operation op)

If the passed operation is a named operation, returns its `getBaseOperation()`, otherwise returns the operation as is.

Parameters:
  `op` - the operation
Returns:
  the base operation of the passed operation.

#### getName

    public static Object getName(Operation op)

If the passed operation is a named operation, returns its `getName()`, otherwise returns null. Note that a named operation object can never have a null name, therefore returning null is indicative that the passed operation is not, in fact, a named operation.

Parameters:
  `op` - the operation
Returns:
  the name in the passed operation, or null if it is not a named operation.