APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.dynalink

public final Class NamedOperation

extends Object
implements Operation
Class Inheritance
All Implemented Interfaces
jdk.dynalink.Operation
Imports
java.util.Objects

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(
        new NamespaceOperation(
            StandardOperation.GET,
            StandardNamespace.PROPERTY),
        "color")
will be a named operation for getting the property named "color" on the object it is applied to, and
    new NamedOperation(
        new NamespaceOperation(
            StandardOperation.GET,
            StandardNamespace.ELEMENT),
        3)
will be a named operation for getting the element at index 3 from the collection it is applied to ("name" in this context is akin to "address" and encompasses both textual names, numeric indices, or any other kinds of addressing that linkers can understand). 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.

While NamedOperation can be constructed directly, it is often convenient to use the Operation#named(Object) factory method instead, e.g.:

   StandardOperation.GET
       .withNamespace(StandardNamespace.ELEMENT),
       .named(3)
    )

Even though NamedOperation is most often used with NamespaceOperation as its base, it can have other operations as its base too (except another named operation). Specifically, StandardOperation#CALL as well as StandardOperation#NEW can both be used with NamedOperation directly. The contract for these operations is such that when they are used as named operations, their name is only used for diagnostic messages, usually containing the textual representation of the source expression that retrieved the callee, e.g. StandardOperation.CALL.named("window.open").

Since
9

Field Summary

Modifier and TypeField and Description
private final Operation
private final Object

Constructor Summary

AccessConstructor and Description
public
NamedOperation(final Operation
the base operation that is associated with a name.
baseOperation
,
final Object
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.
name
)

Creates a new named operation.

Method Summary

Modifier and TypeMethod and Description
public final NamedOperation

Returns:

a named operation with the changed name.
changeName
(final String
the new name to replace the old name with.
newName
)

Finds or creates a named operation that differs from this one only in the name.

public boolean
equals(final Object obj)

Overrides java.lang.Object.equals.

Compares this named operation to another object.

public Operation

Returns:

the base operation of this named operation.
getBaseOperation
()

Returns the base operation of this named operation.

public static Operation

Returns:

the base operation of the passed operation.
getBaseOperation
(final Operation
the operation
op
)

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

public Object

Returns:

the name of this named operation.
getName
()

Returns the name of this named operation.

public static Object

Returns:

the name in the passed operation, or null if it is not a named operation.
getName
(final Operation
the operation
op
)

If the passed operation is a named operation, returns its getName(), otherwise returns null.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code of this named operation.

public String
toString()

Overrides java.lang.Object.toString.

Returns the string representation of this named operation.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

baseOperationback to summary
private final Operation baseOperation
nameback to summary
private final Object name

Constructor Detail

NamedOperationback to summary
public NamedOperation(final Operation baseOperation, final Object name)

Creates a new named operation.

Parameters
baseOperation:Operation

the base operation that is associated with a name.

name:Object

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.

Exceptions
NullPointerException:
if either baseOperation or name is null.
IllegalArgumentException:
if baseOperation is itself a NamedOperation.

Method Detail

changeNameback to summary
public final NamedOperation changeName(final String newName)

Finds or creates a named operation that differs from this one only in the name.

Parameters
newName:String

the new name to replace the old name with.

Returns:NamedOperation

a named operation with the changed name.

Exceptions
NullPointerException:
if the name is null.
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

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.

Annotations
@Override
getBaseOperationback to summary
public Operation getBaseOperation()

Returns the base operation of this named operation.

Returns:Operation

the base operation of this named operation.

getBaseOperationback to summary
public static Operation getBaseOperation(final Operation op)

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

Parameters
op:Operation

the operation

Returns:Operation

the base operation of the passed operation.

getNameback to summary
public Object getName()

Returns the name of this named operation.

Returns:Object

the name of this named operation.

getNameback to summary
public static Object getName(final 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:Operation

the operation

Returns:Object

the name in the passed operation, or null if it is not a named operation.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

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

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

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

Annotations
@Override