author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 41842 | nashorn/src/jdk.dynalink/share/classes/jdk/dynalink/NamespaceOperation.java@50202a344d28 |
child 50695 | 36ca515343e0 |
permissions | -rw-r--r-- |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
1 |
/* |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
33343
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 |
/* |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
34 |
Copyright 2016 Attila Szegedi |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
35 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
36 |
Licensed under both the Apache License, Version 2.0 (the "Apache License") |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
37 |
and the BSD License (the "BSD License"), with licensee being free to |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
38 |
choose either of the two at their discretion. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
39 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
40 |
You may not use this file except in compliance with either the Apache |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
41 |
License or the BSD License. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
42 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
43 |
If you choose to use this file in compliance with the Apache License, the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
44 |
following notice applies to you: |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
45 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
46 |
You may obtain a copy of the Apache License at |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
47 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
48 |
http://www.apache.org/licenses/LICENSE-2.0 |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
49 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
50 |
Unless required by applicable law or agreed to in writing, software |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
51 |
distributed under the License is distributed on an "AS IS" BASIS, |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
52 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
53 |
implied. See the License for the specific language governing |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
54 |
permissions and limitations under the License. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
55 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
56 |
If you choose to use this file in compliance with the BSD License, the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
57 |
following notice applies to you: |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
58 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
59 |
Redistribution and use in source and binary forms, with or without |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
60 |
modification, are permitted provided that the following conditions are |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
61 |
met: |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
62 |
* Redistributions of source code must retain the above copyright |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
63 |
notice, this list of conditions and the following disclaimer. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
64 |
* Redistributions in binary form must reproduce the above copyright |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
65 |
notice, this list of conditions and the following disclaimer in the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
66 |
documentation and/or other materials provided with the distribution. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
67 |
* Neither the name of the copyright holder nor the names of |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
68 |
contributors may be used to endorse or promote products derived from |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
69 |
this software without specific prior written permission. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
70 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
71 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
72 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
73 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
74 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
75 |
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
76 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
77 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
78 |
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
79 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
80 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
81 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
82 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
83 |
|
34447
ec4c069f9436
8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents:
33688
diff
changeset
|
84 |
package jdk.dynalink; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
85 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
86 |
import java.util.Arrays; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
87 |
import java.util.Objects; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
88 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
89 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
90 |
* Describes an operation that operates on at least one {@link Namespace} of |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
91 |
* an object. E.g. a property getter would be described as |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
92 |
* <pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
93 |
* Operation propertyGetter = new NamespaceOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
94 |
* StandardOperation.GET, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
95 |
* StandardNamespace.PROPERTY); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
96 |
* </pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
97 |
* They are often combined with {@link NamedOperation}, e.g. to express a |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
98 |
* property getter for a property named "color", you would construct: |
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 |
* Operation colorPropertyGetter = new NamedOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
101 |
* new NamespaceOperation( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
102 |
* StandardOperation.GET, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
103 |
* StandardNamespace.PROPERTY), |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
104 |
* "color"); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
105 |
* </pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
106 |
* <p>While {@code NamespaceOperation} can be constructed directly, it is often convenient |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
107 |
* to use the {@link Operation#withNamespace(Namespace)} and {@link Operation#withNamespaces(Namespace...)} factory |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
108 |
* methods instead, e.g.: |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
109 |
* <pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
110 |
* Operation getElementOrPropertyEmpty = |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
111 |
* StandardOperation.GET |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
112 |
* .withNamespace(StandardNamespace.PROPERTY) |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
113 |
* .named("color"); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
114 |
* </pre> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
115 |
* <h3>Operations on multiple namespaces</h3> |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
116 |
* If multiple namespaces are specified, the namespaces are treated as |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
117 |
* alternatives to each other in order of preference. The semantics of |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
118 |
* such operation is "first applicable". |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
119 |
* That is, a composite of {@code GET:PROPERTY|ELEMENT:color} should be |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
120 |
* interpreted as <i>get the property named "color" on the object, but if the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
121 |
* property does not exist, then get the collection element named "color" |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
122 |
* instead</i>. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
123 |
* <p> |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
124 |
* Operations with multiple namespaces are helpful in implementation of languages that |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
125 |
* don't distinguish between one or more of the namespaces, or when expressing operations |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
126 |
* against objects that can be considered both ordinary objects and collections, e.g. Java |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
127 |
* {@link java.util.Map} objects. A {@code GET:PROPERTY|ELEMENT:empty} operation |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
128 |
* against a Java map will always match |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
129 |
* the {@link java.util.Map#isEmpty()} property, but |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
130 |
* {@code GET:ELEMENT|PROPERTY:empty} will actually match a map element with |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
131 |
* key {@code "empty"} if the map contains that key, and only fall back to the |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
132 |
* {@code isEmpty()} property getter if the map does not contain the key. If |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
133 |
* the source language mandates this semantics, it can be easily achieved using |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
134 |
* operations on multiple namespaces. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
135 |
* <p> |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
136 |
* Even if the language itself doesn't distinguish between some of the |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
137 |
* namespaces, it can be helpful to map different syntaxes to different namespace orderings. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
138 |
* E.g. the source expression {@code obj.color} could map to |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
139 |
* {@code GET:PROPERTY|ELEMENT|METHOD:color}, but a different source |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
140 |
* expression that looks like collection element access {@code obj[key]} could |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
141 |
* be expressed instead as {@code GET:ELEMENT|PROPERTY|METHOD} in order to favor the |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
142 |
* element semantics. Finally, if the retrieved value is subsequently called, then it makes sense |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
143 |
* to bring {@code METHOD} to the front of the namespace list: the getter part of the |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
144 |
* source expression {@code obj.color()} could be |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
145 |
* {@code GET:METHOD|PROPERTY|ELEMENT:color} and the one for |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
146 |
* {@code obj[key]()} could be {@code GET:METHOD|ELEMENT|PROPERTY}. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
147 |
* <p> |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
148 |
* The base operation of a namespace operation can not itself be a namespace or named |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
149 |
* operation, but rather one of simple operations such are elements of |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
150 |
* {@link StandardOperation}. A namespace operation itself can serve as the base |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
151 |
* operation of a named operation, though; a typical way to construct e.g. the |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
152 |
* {@code GET:ELEMENT|PROPERTY:empty} from above would be: |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
153 |
* <pre> |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
154 |
* Operation getElementOrPropertyEmpty = StandardOperation.GET |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
155 |
* .withNamespaces( |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
156 |
* StandardNamespace.ELEMENT, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
157 |
* StandardNamespace.PROPERTY) |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
158 |
* .named("empty"); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
159 |
* </pre> |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
160 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
161 |
public final class NamespaceOperation implements Operation { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
162 |
private final Operation baseOperation; |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
163 |
private final Namespace[] namespaces; |
33343
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 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
166 |
* Constructs a new namespace operation. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
167 |
* @param baseOperation the base operation that operates on one or more namespaces. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
168 |
* @param namespaces one or more namespaces this operation operates on. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
169 |
* @throws IllegalArgumentException if less than one namespace is |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
170 |
* specified, or the base operation is itself a {@link NamespaceOperation} or a |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
171 |
* {@link NamedOperation}. |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
172 |
* @throws NullPointerException if either the {@code namespaces} array or any of its |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
173 |
* elements are {@code null}, or if {@code baseOperation} is {@code null}. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
174 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
175 |
public NamespaceOperation(final Operation baseOperation, final Namespace... namespaces) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
176 |
this.baseOperation = Objects.requireNonNull(baseOperation, "baseOperation is null"); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
177 |
if (baseOperation instanceof NamedOperation) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
178 |
throw new IllegalArgumentException("baseOperation is a NamedOperation"); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
179 |
} else if (baseOperation instanceof NamespaceOperation) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
180 |
throw new IllegalArgumentException("baseOperation is a NamespaceOperation"); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
181 |
} |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
182 |
|
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
183 |
this.namespaces = Objects.requireNonNull(namespaces, "namespaces array is null").clone(); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
184 |
if (namespaces.length < 1) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
185 |
throw new IllegalArgumentException("Must specify at least one namespace"); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
186 |
} |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
187 |
for(int i = 0; i < namespaces.length; ++i) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
188 |
final int fi = i; |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
189 |
Objects.requireNonNull(namespaces[i], () -> "operations[" + fi + "] is null"); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
190 |
} |
33343
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 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
194 |
* Returns the base operation of this named operation. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
195 |
* @return the base operation of this named operation. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
196 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
197 |
public Operation getBaseOperation() { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
198 |
return baseOperation; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
199 |
} |
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 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
202 |
* Returns the namespaces in this namespace operation. The returned |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
203 |
* array is a copy and changes to it don't have effect on this |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
204 |
* object. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
205 |
* @return the namespaces in this namespace operation. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
206 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
207 |
public Namespace[] getNamespaces() { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
208 |
return namespaces.clone(); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
209 |
} |
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 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
212 |
* Returns the number of namespaces in this namespace operation. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
213 |
* @return the number of namespaces in this namespace operation. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
214 |
*/ |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
215 |
public int getNamespaceCount() { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
216 |
return namespaces.length; |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
217 |
} |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
218 |
|
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
219 |
/** |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
220 |
* Returns the i-th namespace in this namespace operation. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
221 |
* @param i the namespace index |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
222 |
* @return the i-th namespace in this namespace operation. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
223 |
* @throws IndexOutOfBoundsException if the index is out of range. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
224 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
225 |
public Namespace getNamespace(final int i) { |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
226 |
try { |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
227 |
return namespaces[i]; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
228 |
} catch (final ArrayIndexOutOfBoundsException e) { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
229 |
throw new IndexOutOfBoundsException(Integer.toString(i)); |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
230 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
231 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
232 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
233 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
234 |
* Returns true if this namespace operation contains a namespace equal to |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
235 |
* the specified namespace. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
236 |
* @param namespace the namespace being searched for. Must not be null. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
237 |
* @return true if the if this namespace operation contains a namespace |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
238 |
* equal to the specified namespace. |
33345
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
239 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
240 |
public boolean contains(final Namespace namespace) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
241 |
Objects.requireNonNull(namespace); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
242 |
for(final Namespace component: namespaces) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
243 |
if (component.equals(namespace)) { |
33345
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
244 |
return true; |
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
245 |
} |
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
246 |
} |
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
247 |
return false; |
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
248 |
} |
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
249 |
|
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
250 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
251 |
* Returns true if the other object is also a namespace operation and their |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
252 |
* base operation and namespaces are equal. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
253 |
* @param obj the object to compare to |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
254 |
* @return true if this object is equal to the other one, false otherwise. |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
255 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
256 |
@Override |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
257 |
public boolean equals(final Object obj) { |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
258 |
if (obj instanceof NamespaceOperation) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
259 |
final NamespaceOperation other = (NamespaceOperation)obj; |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
260 |
return baseOperation.equals(other.baseOperation) && Arrays.equals(namespaces, other.namespaces); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
261 |
} |
33688 | 262 |
return false; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
263 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
264 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
265 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
266 |
* Returns the hash code of this namespace operation. Defined to be equal |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
267 |
* to {@code baseOperation.hashCode() + 31 * Arrays.hashCode(namespaces)}. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
268 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
269 |
@Override |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
270 |
public int hashCode() { |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
271 |
return baseOperation.hashCode() + 31 * Arrays.hashCode(namespaces); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
272 |
}; |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
273 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
274 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
275 |
* Returns the string representation of this namespace operation. Defined to |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
276 |
* be the {@code toString} of its base operation, followed by a colon character, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
277 |
* followed with the list of its namespaces separated with the vertical line |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
278 |
* character (e.g. {@code "GET:PROPERTY|ELEMENT"}). |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
279 |
* @return the string representation of this namespace operation. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
280 |
*/ |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
281 |
@Override |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
282 |
public String toString() { |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
283 |
final StringBuilder b = new StringBuilder(); |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
284 |
b.append(baseOperation).append(':'); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
285 |
b.append(namespaces[0]); |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
286 |
for(int i = 1; i < namespaces.length; ++i) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
287 |
b.append('|').append(namespaces[i]); |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
288 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
289 |
return b.toString(); |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
290 |
} |
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
291 |
|
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
292 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
293 |
* If the passed operation is a namespace operation, returns its |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
294 |
* {@link #getBaseOperation()}, otherwise returns the operation as is. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
295 |
* @param op the operation |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
296 |
* @return the base operation of the passed operation. |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
297 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
298 |
public static Operation getBaseOperation(final Operation op) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
299 |
return op instanceof NamespaceOperation ? ((NamespaceOperation )op).getBaseOperation() : op; |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
300 |
} |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
301 |
|
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
302 |
/** |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
303 |
* If the passed operation is a namespace operation, returns its |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
304 |
* {@link #getNamespaces()}, otherwise returns an empty array. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
305 |
* @param op the operation |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
306 |
* @return the namespaces of the passed operation. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
307 |
*/ |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
308 |
public static Namespace[] getNamespaces(final Operation op) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
309 |
return op instanceof NamespaceOperation ? ((NamespaceOperation)op).getNamespaces() : new Namespace[0]; |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
310 |
} |
33345
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
311 |
|
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
312 |
/** |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
313 |
* Returns true if the specified operation is a {@link NamespaceOperation} |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
314 |
* and its base operation is equal to the specified operation, and it |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
315 |
* contains the specified namespace. If it is not a {@link NamespaceOperation}, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
316 |
* then it returns false. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
317 |
* @param op the operation. Must not be null. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
318 |
* @param baseOperation the base operation being searched for. Must not be null. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
319 |
* @param namespace the namespace being searched for. Must not be null. |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
320 |
* @return true if the if the passed operation is a {@link NamespaceOperation}, |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
321 |
* its base operation equals the searched base operation, and contains a namespace |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
322 |
* equal to the searched namespace. |
33345
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
323 |
*/ |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
324 |
public static boolean contains(final Operation op, final Operation baseOperation, final Namespace namespace) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
325 |
if (op instanceof NamespaceOperation) { |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
326 |
final NamespaceOperation no = (NamespaceOperation)op; |
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
327 |
return no.baseOperation.equals(baseOperation) && no.contains(namespace); |
33345
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
328 |
} |
41842
50202a344d28
8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents:
34447
diff
changeset
|
329 |
return false; |
33345
ef8c859f7992
8140273: restore use of CompositeOperation.contains where it is needed
attila
parents:
33343
diff
changeset
|
330 |
} |
33343
23abd10384a5
8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff
changeset
|
331 |
} |