author | mbaesken |
Tue, 02 Jul 2019 13:45:08 +0200 | |
changeset 55556 | 19d0b382f086 |
parent 50695 | 36ca515343e0 |
permissions | -rw-r--r-- |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
1 |
/* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
4 |
* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
10 |
* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
15 |
* accompanied this code). |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
16 |
* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
20 |
* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
23 |
* questions. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
24 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
25 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
26 |
/* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
27 |
* This file is available under and governed by the GNU General Public |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
28 |
* License version 2 only, as published by the Free Software Foundation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
29 |
* However, the following notice accompanied the original version of this |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
30 |
* file, and Oracle licenses the original version of this file under the BSD |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
31 |
* license: |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
32 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
33 |
/* |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
34 |
Copyright 2015 Attila Szegedi |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
35 |
|
50695 | 36 |
Redistribution and use in source and binary forms, with or without |
37 |
modification, are permitted provided that the following conditions are |
|
38 |
met: |
|
39 |
* Redistributions of source code must retain the above copyright |
|
40 |
notice, this list of conditions and the following disclaimer. |
|
41 |
* Redistributions in binary form must reproduce the above copyright |
|
42 |
notice, this list of conditions and the following disclaimer in the |
|
43 |
documentation and/or other materials provided with the distribution. |
|
44 |
* Neither the name of the copyright holder nor the names of |
|
45 |
contributors may be used to endorse or promote products derived from |
|
46 |
this software without specific prior written permission. |
|
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
47 |
|
50695 | 48 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
49 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
50 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
51 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER |
|
52 |
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
53 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
54 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
55 |
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
56 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
57 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
58 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
59 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
60 |
|
34447
ec4c069f9436
8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents:
33688
diff
changeset
|
61 |
package jdk.dynalink; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
62 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
63 |
import java.util.Objects; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
64 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
65 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
66 |
* Operation that associates a name with another operation. Typically used with |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
67 |
* operations that normally take a name or an index to bind them to a fixed |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
68 |
* name. E.g. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
69 |
* <pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
70 |
* new NamedOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
71 |
* new NamespaceOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
72 |
* StandardOperation.GET, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
73 |
* StandardNamespace.PROPERTY), |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
74 |
* "color") |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
75 |
* </pre> |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
76 |
* will be a named operation for getting the property named "color" on the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
77 |
* object it is applied to, and |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
78 |
* <pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
79 |
* new NamedOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
80 |
* new NamespaceOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
81 |
* StandardOperation.GET, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
82 |
* StandardNamespace.ELEMENT), |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
83 |
* 3) |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
84 |
* </pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
85 |
* will be a named operation for getting the element at index 3 from the collection |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
86 |
* it is applied to ("name" in this context is akin to "address" and encompasses both |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
87 |
* textual names, numeric indices, or any other kinds of addressing that linkers can |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
88 |
* understand). In these cases, the expected signature of the call site for the |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
89 |
* operation will change to no longer include the name parameter. Specifically, |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
90 |
* the documentation for all {@link StandardOperation} members describes how |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
91 |
* they are affected by being incorporated into a named operation. |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
92 |
* <p>While {@code NamedOperation} can be constructed directly, it is often convenient |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
93 |
* to use the {@link Operation#named(Object)} factory method instead, e.g.: |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
94 |
* <pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
95 |
* StandardOperation.GET |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
96 |
* .withNamespace(StandardNamespace.ELEMENT), |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
97 |
* .named(3) |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
98 |
* ) |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
99 |
* </pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
100 |
* <p> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
101 |
* Even though {@code NamedOperation} is most often used with {@link NamespaceOperation} as |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
102 |
* its base, it can have other operations as its base too (except another named operation). |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
103 |
* Specifically, {@link StandardOperation#CALL} as well as {@link StandardOperation#NEW} can |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
104 |
* both be used with {@code NamedOperation} directly. The contract for these operations is such |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
105 |
* that when they are used as named operations, their name is only used for diagnostic messages, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
106 |
* usually containing the textual representation of the source expression that retrieved the |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
107 |
* callee, e.g. {@code StandardOperation.CALL.named("window.open")}. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
108 |
* </p> |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
109 |
*/ |
33688 | 110 |
public final class NamedOperation implements Operation { |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
111 |
private final Operation baseOperation; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
112 |
private final Object name; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
113 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
114 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
115 |
* Creates a new named operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
116 |
* @param baseOperation the base operation that is associated with a name. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
117 |
* @param name the name associated with the base operation. Note that the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
118 |
* name is not necessarily a string, but can be an arbitrary object. As the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
119 |
* name is used for addressing, it can be an {@link Integer} when meant |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
120 |
* to be used as an index into an array or list etc. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
121 |
* @throws NullPointerException if either {@code baseOperation} or |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
122 |
* {@code name} is null. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
123 |
* @throws IllegalArgumentException if {@code baseOperation} is itself a |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
124 |
* {@code NamedOperation}. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
125 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
126 |
public NamedOperation(final Operation baseOperation, final Object name) { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
127 |
if (baseOperation instanceof NamedOperation) { |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
128 |
throw new IllegalArgumentException("baseOperation is a NamedOperation"); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
129 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
130 |
this.baseOperation = Objects.requireNonNull(baseOperation, "baseOperation is null"); |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
131 |
this.name = Objects.requireNonNull(name, "name is null"); |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
132 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
133 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
134 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
135 |
* Returns the base operation of this named operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
136 |
* @return the base operation of this named operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
137 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
138 |
public Operation getBaseOperation() { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
139 |
return baseOperation; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
140 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
141 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
142 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
143 |
* Returns the name of this named operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
144 |
* @return the name of this named operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
145 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
146 |
public Object getName() { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
147 |
return name; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
148 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
149 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
150 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
151 |
* Finds or creates a named operation that differs from this one only in the name. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
152 |
* @param newName the new name to replace the old name with. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
153 |
* @return a named operation with the changed name. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
154 |
* @throws NullPointerException if the name is null. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
155 |
*/ |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
156 |
public final NamedOperation changeName(final String newName) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
157 |
return new NamedOperation(baseOperation, newName); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
158 |
} |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
159 |
|
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
160 |
/** |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
161 |
* Compares this named operation to another object. Returns true if the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
162 |
* other object is also a named operation, and both their base operations |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
163 |
* and name are equal. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
164 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
165 |
@Override |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
166 |
public boolean equals(final Object obj) { |
33688 | 167 |
if (obj instanceof NamedOperation) { |
168 |
final NamedOperation other = (NamedOperation)obj; |
|
169 |
return baseOperation.equals(other.baseOperation) && name.equals(other.name); |
|
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
170 |
} |
33688 | 171 |
return false; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
172 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
173 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
174 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
175 |
* Returns the hash code of this named operation. It is defined to be equal |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
176 |
* to {@code baseOperation.hashCode() + 31 * name.hashCode()}. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
177 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
178 |
@Override |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
179 |
public int hashCode() { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
180 |
return baseOperation.hashCode() + 31 * name.hashCode(); |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
181 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
182 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
183 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
184 |
* Returns the string representation of this named operation. It is defined |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
185 |
* to be equal to {@code baseOperation.toString() + ":" + name.toString()}. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
186 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
187 |
@Override |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
188 |
public String toString() { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
189 |
return baseOperation.toString() + ":" + name.toString(); |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
190 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
191 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
192 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
193 |
* If the passed operation is a named operation, returns its |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
194 |
* {@link #getBaseOperation()}, otherwise returns the operation as is. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
195 |
* @param op the operation |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
196 |
* @return the base operation of the passed operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
197 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
198 |
public static Operation getBaseOperation(final Operation op) { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
199 |
return op instanceof NamedOperation ? ((NamedOperation)op).baseOperation : op; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
200 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
201 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
202 |
/** |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
203 |
* If the passed operation is a named operation, returns its |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
204 |
* {@link #getName()}, otherwise returns null. Note that a named operation |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
205 |
* object can never have a null name, therefore returning null is indicative |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
206 |
* that the passed operation is not, in fact, a named operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
207 |
* @param op the operation |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
208 |
* @return the name in the passed operation, or null if it is not a named |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
209 |
* operation. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
210 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
211 |
public static Object getName(final Operation op) { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
212 |
return op instanceof NamedOperation ? ((NamedOperation)op).name : null; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
213 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
214 |
} |