- 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( 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, andnew 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 allStandardOperationmembers describes how they are affected by being incorporated into a named operation.While
NamedOperationcan be constructed directly, it is often convenient to use theOperation.named(Object)factory method instead, e.g.:StandardOperation.GET .withNamespace(StandardNamespace.ELEMENT), .named(3) )Even though
NamedOperationis most often used withNamespaceOperationas its base, it can have other operations as its base too (except another named operation). Specifically,StandardOperation.CALLas well asStandardOperation.NEWcan both be used withNamedOperationdirectly. 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").
-
-
Constructor Summary
Constructors Constructor Description NamedOperation(Operation baseOperation, Object name)Creates a new named operation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NamedOperationchangeName(String newName)Finds or creates a named operation that differs from this one only in the name.booleanequals(Object obj)Compares this named operation to another object.OperationgetBaseOperation()Returns the base operation of this named operation.static OperationgetBaseOperation(Operation op)If the passed operation is a named operation, returns itsgetBaseOperation(), otherwise returns the operation as is.ObjectgetName()Returns the name of this named operation.static ObjectgetName(Operation op)If the passed operation is a named operation, returns itsgetName(), otherwise returns null.inthashCode()Returns the hash code of this named operation.StringtoString()Returns the string representation of this named operation.-
Methods declared in class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods declared in interface jdk.dynalink.Operation
named, withNamespace, withNamespaces
-
-
-
-
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 anIntegerwhen meant to be used as an index into an array or list etc.- Throws:
NullPointerException- if eitherbaseOperationornameis null.IllegalArgumentException- ifbaseOperationis itself aNamedOperation.
-
-
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.
-
changeName
public final NamedOperation changeName(String newName)
Finds or creates a named operation that differs from this one only in the name.- Parameters:
newName- the new name to replace the old name with.- Returns:
- a named operation with the changed name.
- Throws:
NullPointerException- if the name is null.
-
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:
equalsin classObject- Parameters:
obj- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
Returns the hash code of this named operation. It is defined to be equal tobaseOperation.hashCode() + 31 * name.hashCode().- Overrides:
hashCodein classObject- 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 tobaseOperation.toString() + ":" + name.toString().
-
getBaseOperation
public static Operation getBaseOperation(Operation op)
If the passed operation is a named operation, returns itsgetBaseOperation(), 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 itsgetName(), 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.
-
-