src/java.management/share/classes/javax/management/openmbean/OpenMBeanConstructorInfoSupport.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.management.openmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
// java import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.MBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Describes a constructor of an Open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class OpenMBeanConstructorInfoSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    extends MBeanConstructorInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    implements OpenMBeanConstructorInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final long serialVersionUID = -4400441579007477003L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // As this instance is immutable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // these two values need only be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private transient Integer myHashCode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private transient String  myToString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * <p>Constructs an {@code OpenMBeanConstructorInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * instance, which describes the constructor of a class of open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * MBeans with the specified {@code name}, {@code description} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * {@code signature}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * <p>The {@code signature} array parameter is internally copied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * so that subsequent changes to the array referenced by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * signature} have no effect on this instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param name cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param description cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param signature can be null or empty if there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * parameters to describe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * description} are null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @throws ArrayStoreException If {@code signature} is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * array of instances of a subclass of {@code MBeanParameterInfo}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public OpenMBeanConstructorInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                           String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                           OpenMBeanParameterInfo[] signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this(name, description, signature, (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <p>Constructs an {@code OpenMBeanConstructorInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * instance, which describes the constructor of a class of open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * MBeans with the specified {@code name}, {@code description},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * {@code signature}, and {@code descriptor}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <p>The {@code signature} array parameter is internally copied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * so that subsequent changes to the array referenced by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * signature} have no effect on this instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param name cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param description cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param signature can be null or empty if there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * parameters to describe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param descriptor The descriptor for the constructor.  This may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * be null which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * description} are null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws ArrayStoreException If {@code signature} is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * array of instances of a subclass of {@code MBeanParameterInfo}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public OpenMBeanConstructorInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                           String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                           OpenMBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                           Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        super(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
              description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
              arrayCopyCast(signature), // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
              descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // check parameters that should not be null or empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // (unfortunately it is not done in superclass :-( ! )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        //
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   127
        if (name == null || name.trim().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new IllegalArgumentException("Argument name cannot be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                               "null or empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   131
        if (description == null || description.trim().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new IllegalArgumentException("Argument description cannot " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                               "be null or empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static MBeanParameterInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            arrayCopyCast(OpenMBeanParameterInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        MBeanParameterInfo[] dst = new MBeanParameterInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /* ***  Commodity methods from java.lang.Object  *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <p>Compares the specified {@code obj} parameter with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * {@code OpenMBeanConstructorInfoSupport} instance for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * equality.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <p>Returns {@code true} if and only if all of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <li>{@code obj} is non null,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <li>{@code obj} also implements the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * OpenMBeanConstructorInfo} interface,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <li>their names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <li>their signatures are equal.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * This ensures that this {@code equals} method works properly for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * {@code obj} parameters which are different implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * the {@code OpenMBeanConstructorInfo} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param obj the object to be compared for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * {@code OpenMBeanConstructorInfoSupport} instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return {@code true} if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * {@code OpenMBeanConstructorInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // if obj is not a OpenMBeanConstructorInfo, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        OpenMBeanConstructorInfo other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            other = (OpenMBeanConstructorInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // Now, really test for equality between this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // OpenMBeanConstructorInfo implementation and the other:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // their Name should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if ( ! this.getName().equals(other.getName()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // their Signatures should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if ( ! Arrays.equals(this.getSignature(), other.getSignature()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // All tests for equality were successfull
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <p>Returns the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * OpenMBeanConstructorInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p>The hash code of an {@code OpenMBeanConstructorInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * instance is the sum of the hash codes of all elements of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * information used in {@code equals} comparisons (ie: its name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * and signature, where the signature hashCode is calculated by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * call to {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * java.util.Arrays.asList(this.getSignature).hashCode()}).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <p>This ensures that {@code t1.equals(t2)} implies that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * t1.hashCode()==t2.hashCode()} for any two {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * OpenMBeanConstructorInfoSupport} instances {@code t1} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * {@code t2}, as required by the general contract of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * {@link Object#hashCode() Object.hashCode()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <p>However, note that another instance of a class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * the {@code OpenMBeanConstructorInfo} interface may be equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * this {@code OpenMBeanConstructorInfoSupport} instance as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * defined by {@link #equals(java.lang.Object)}, but may have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * different hash code if it is calculated differently.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <p>As {@code OpenMBeanConstructorInfoSupport} instances are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * immutable, the hash code for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * on the first call to {@code hashCode}, and then the same value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * is returned for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * OpenMBeanConstructorInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // Calculate the hash code value if it has not yet been done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        // (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            value += this.getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            value += Arrays.asList(this.getSignature()).hashCode();
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   255
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p>Returns a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * OpenMBeanConstructorInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>The string representation consists of the name of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * (ie {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * javax.management.openmbean.OpenMBeanConstructorInfoSupport}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * the name and signature of the described constructor and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * string representation of its descriptor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <p>As {@code OpenMBeanConstructorInfoSupport} instances are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * immutable, the string representation for this instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * calculated once, on the first call to {@code toString}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * then the same value is returned for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * OpenMBeanConstructorInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // Calculate the string value if it has not yet been done (ie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            myToString = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                .append(this.getClass().getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                .append("(name=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                .append(this.getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                .append(",signature=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                .append(Arrays.asList(this.getSignature()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                .append(",descriptor=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                .append(this.getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                .append(")")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                .toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // return always the same string representation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}