src/jdk.dynalink/share/classes/jdk/dynalink/NamespaceOperation.java
author jlaskey
Thu, 21 Jun 2018 08:58:59 -0300
changeset 50695 36ca515343e0
parent 47216 71c04702a3d5
child 54547 53aecb049e0a
permissions -rw-r--r--
8203637: Fix Sources Reviewed-by: hannesw, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
50695
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    36
   Redistribution and use in source and binary forms, with or without
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    37
   modification, are permitted provided that the following conditions are
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    38
   met:
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    39
   * Redistributions of source code must retain the above copyright
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    40
     notice, this list of conditions and the following disclaimer.
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    41
   * Redistributions in binary form must reproduce the above copyright
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    42
     notice, this list of conditions and the following disclaimer in the
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    43
     documentation and/or other materials provided with the distribution.
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    44
   * Neither the name of the copyright holder nor the names of
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    45
     contributors may be used to endorse or promote products derived from
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    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
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    48
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    49
   IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    50
   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    51
   PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    52
   BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    53
   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    54
   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    55
   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    56
   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    57
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36ca515343e0 8203637: Fix Sources
jlaskey
parents: 47216
diff changeset
    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.Arrays;
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
    64
import java.util.Objects;
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
/**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    67
 * 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
    68
 * 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
    69
 * <pre>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    70
 * Operation propertyGetter = new NamespaceOperation(
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    71
 *     StandardOperation.GET,
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    72
 *     StandardNamespace.PROPERTY);
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    73
 * </pre>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    74
 * 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
    75
 * property getter for a property named "color", you would construct:
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    76
 * <pre>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    77
 * Operation colorPropertyGetter = new NamedOperation(
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    78
 *     new NamespaceOperation(
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    79
 *         StandardOperation.GET,
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    80
 *         StandardNamespace.PROPERTY),
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    81
 *     "color");
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    82
 * </pre>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    83
 * <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
    84
 * 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
    85
 * methods instead, e.g.:
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    86
 * <pre>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    87
 * Operation getElementOrPropertyEmpty =
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    88
 *     StandardOperation.GET
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    89
 *         .withNamespace(StandardNamespace.PROPERTY)
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    90
 *         .named("color");
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    91
 * </pre>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    92
 * <h3>Operations on multiple namespaces</h3>
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    93
 * If multiple namespaces are specified, the namespaces are treated as
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    94
 * 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
    95
 * such operation is "first applicable".
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
    96
 * 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
    97
 * 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
    98
 * 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
    99
 * instead</i>.
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   100
 * <p>
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   101
 * 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
   102
 * 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
   103
 * 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
   104
 * {@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
   105
 * against a Java map will always match
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   106
 * the {@link java.util.Map#isEmpty()} property, but
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   107
 * {@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
   108
 * 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
   109
 * {@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
   110
 * 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
   111
 * operations on multiple namespaces.
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   112
 * <p>
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   113
 * 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
   114
 * 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
   115
 * 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
   116
 * {@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
   117
 * 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
   118
 * 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
   119
 * 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
   120
 * 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
   121
 * source expression {@code obj.color()} could be
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   122
 * {@code GET:METHOD|PROPERTY|ELEMENT:color} and the one for
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   123
 * {@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
   124
 * <p>
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   125
 * 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
   126
 * 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
   127
 * {@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
   128
 * 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
   129
 * {@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
   130
 * <pre>
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   131
 * Operation getElementOrPropertyEmpty = StandardOperation.GET
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   132
 *     .withNamespaces(
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   133
 *         StandardNamespace.ELEMENT,
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   134
 *         StandardNamespace.PROPERTY)
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   135
 *     .named("empty");
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   136
 * </pre>
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   137
 */
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   138
public final class NamespaceOperation implements Operation {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   139
    private final Operation baseOperation;
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   140
    private final Namespace[] namespaces;
33343
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
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   143
     * Constructs a new namespace operation.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   144
     * @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
   145
     * @param namespaces one or more namespaces this operation operates on.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   146
     * @throws IllegalArgumentException if less than one namespace is
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   147
     * 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
   148
     * {@link NamedOperation}.
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   149
     * @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
   150
     * 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
   151
     */
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   152
    public NamespaceOperation(final Operation baseOperation, final Namespace... namespaces) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   153
        this.baseOperation = Objects.requireNonNull(baseOperation, "baseOperation is null");
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   154
        if (baseOperation instanceof NamedOperation) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   155
            throw new IllegalArgumentException("baseOperation is a NamedOperation");
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   156
        } else if (baseOperation instanceof NamespaceOperation) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   157
           throw new IllegalArgumentException("baseOperation is a NamespaceOperation");
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   158
        }
41842
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
        this.namespaces = Objects.requireNonNull(namespaces, "namespaces array is null").clone();
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   161
        if (namespaces.length < 1) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   162
            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
   163
        }
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   164
        for(int i = 0; i < namespaces.length; ++i) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   165
            final int fi = i;
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   166
            Objects.requireNonNull(namespaces[i], () -> "operations[" + fi + "] is null");
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   167
        }
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   168
    }
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   169
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   170
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   171
     * Returns the base operation of this named operation.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   172
     * @return the base operation of this named operation.
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   173
     */
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   174
    public Operation getBaseOperation() {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   175
        return baseOperation;
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   176
    }
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
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   179
     * Returns the namespaces in this namespace operation. The returned
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   180
     * 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
   181
     * object.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   182
     * @return the namespaces in this namespace operation.
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   183
     */
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   184
    public Namespace[] getNamespaces() {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   185
        return namespaces.clone();
33343
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
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   188
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   189
     * Returns the number of namespaces in this namespace operation.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   190
     * @return the number of namespaces in this namespace operation.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   191
     */
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   192
    public int getNamespaceCount() {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   193
        return namespaces.length;
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   194
    }
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   195
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   196
    /**
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   197
     * Returns the i-th namespace in this namespace operation.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   198
     * @param i the namespace index
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   199
     * @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
   200
     * @throws IndexOutOfBoundsException if the index is out of range.
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
    public Namespace getNamespace(final int i) {
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   203
        try {
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   204
            return namespaces[i];
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   205
        } catch (final ArrayIndexOutOfBoundsException e) {
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   206
            throw new IndexOutOfBoundsException(Integer.toString(i));
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   207
        }
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   208
    }
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
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   211
     * 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
   212
     * the specified namespace.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   213
     * @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
   214
     * @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
   215
     * equal to the specified namespace.
33345
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   216
     */
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   217
    public boolean contains(final Namespace namespace) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   218
        Objects.requireNonNull(namespace);
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   219
        for(final Namespace component: namespaces) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   220
            if (component.equals(namespace)) {
33345
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   221
                return true;
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   222
            }
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   223
        }
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   224
        return false;
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   225
    }
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   226
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   227
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   228
     * 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
   229
     * base operation and namespaces are equal.
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   230
     * @param obj the object to compare to
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   231
     * @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
   232
     */
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   233
    @Override
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   234
    public boolean equals(final Object obj) {
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   235
        if (obj instanceof NamespaceOperation) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   236
            final NamespaceOperation other = (NamespaceOperation)obj;
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   237
            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
   238
        }
33688
649d5d76f602 8142422: Smaller Dynalink API adjustments
attila
parents: 33345
diff changeset
   239
        return false;
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   240
    }
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   241
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   242
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   243
     * 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
   244
     * to {@code baseOperation.hashCode() + 31 * Arrays.hashCode(namespaces)}.
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   245
     */
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   246
    @Override
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   247
    public int hashCode() {
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   248
        return baseOperation.hashCode() + 31 * Arrays.hashCode(namespaces);
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   249
    };
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   250
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   251
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   252
     * Returns the string representation of this namespace operation. Defined to
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   253
     * 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
   254
     * 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
   255
     * character (e.g. {@code "GET:PROPERTY|ELEMENT"}).
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   256
     * @return the string representation of this namespace operation.
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   257
     */
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   258
    @Override
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   259
    public String toString() {
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   260
        final StringBuilder b = new StringBuilder();
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   261
        b.append(baseOperation).append(':');
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   262
        b.append(namespaces[0]);
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   263
        for(int i = 1; i < namespaces.length; ++i) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   264
            b.append('|').append(namespaces[i]);
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   265
        }
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   266
        return b.toString();
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   267
    }
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
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   270
     * If the passed operation is a namespace operation, returns its
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   271
     * {@link #getBaseOperation()}, otherwise returns the operation as is.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   272
     * @param op the operation
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   273
     * @return the base operation of the passed operation.
33343
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
    public static Operation getBaseOperation(final Operation op) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   276
        return op instanceof NamespaceOperation ? ((NamespaceOperation )op).getBaseOperation() : op;
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   277
    }
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   278
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   279
    /**
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   280
     * If the passed operation is a namespace operation, returns its
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   281
     * {@link #getNamespaces()}, otherwise returns an empty array.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   282
     * @param op the operation
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   283
     * @return the namespaces of the passed operation.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   284
     */
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   285
    public static Namespace[] getNamespaces(final Operation op) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   286
        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
   287
    }
33345
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   288
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   289
    /**
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   290
     * Returns true if the specified operation is a {@link NamespaceOperation}
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   291
     * 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
   292
     * 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
   293
     * then it returns false.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   294
     * @param op the operation. Must not be null.
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   295
     * @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
   296
     * @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
   297
     * @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
   298
     * 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
   299
     * equal to the searched namespace.
33345
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   300
     */
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   301
    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
   302
        if (op instanceof NamespaceOperation) {
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   303
            final NamespaceOperation no = (NamespaceOperation)op;
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   304
            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
   305
        }
41842
50202a344d28 8168005: Introduce namespaces for GET, SET Dynalink operations
attila
parents: 34447
diff changeset
   306
        return false;
33345
ef8c859f7992 8140273: restore use of CompositeOperation.contains where it is needed
attila
parents: 33343
diff changeset
   307
    }
33343
23abd10384a5 8139931: Introduce Operation objects in Dynalink instead of string encoding
attila
parents:
diff changeset
   308
}