Operation
public final class NamedOperation extends Object implements Operation
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")
.
Constructor | Description |
---|---|
NamedOperation(Operation baseOperation,
Object name) |
Creates a new named operation.
|
Modifier and Type | Method | Description |
---|---|---|
NamedOperation |
changeName(String newName) |
Finds or creates a named operation that differs from this one only in the name.
|
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.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
named, withNamespace, withNamespaces
public NamedOperation(Operation baseOperation, Object name)
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.NullPointerException
- if either baseOperation
or
name
is null.IllegalArgumentException
- if baseOperation
is itself a
NamedOperation
.public Operation getBaseOperation()
public Object getName()
public final NamedOperation changeName(String newName)
newName
- the new name to replace the old name with.NullPointerException
- if the name is null.public boolean equals(Object obj)
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
baseOperation.hashCode() + 31 * name.hashCode()
.hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
baseOperation.toString() + ":" + name.toString()
.public static Operation getBaseOperation(Operation op)
getBaseOperation()
, otherwise returns the operation as is.op
- the operationpublic static Object getName(Operation op)
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.op
- the operation Submit a bug or feature
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 2015, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Debian+0-9b153-2