jdk/src/share/classes/javax/management/openmbean/SimpleType.java
author rriggs
Tue, 12 Nov 2013 14:03:28 -0500
changeset 21656 d4c777ccb1db
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8028014: Doclint warning/error cleanup in javax.management Summary: Improve generated html by fixing doclint warnings Reviewed-by: sla, jbachorik
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: 1510
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: 1510
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: 1510
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: 1510
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
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.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectStreamException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.math.BigDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// jmx import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The <code>SimpleType</code> class is the <i>open type</i> class whose instances describe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * all <i>open data</i> values which are neither arrays,
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    48
 * nor {@link CompositeData CompositeData} values,
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    49
 * nor {@link TabularData TabularData} values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * It predefines all its possible instances as static fields, and has no public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Given a <code>SimpleType</code> instance describing values whose Java class name is <i>className</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the internal fields corresponding to the name and description of this <code>SimpleType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * are also set to <i>className</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * In other words, its methods <code>getClassName</code>, <code>getTypeName</code> and <code>getDescription</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * all return the same string value <i>className</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public final class SimpleType<T> extends OpenType<T> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static final long serialVersionUID = 2215577471957694503L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // SimpleType instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // IF YOU ADD A SimpleType, YOU MUST UPDATE OpenType and typeArray
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Java class name is <code>java.lang.Void</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final SimpleType<Void> VOID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        new SimpleType<Void>(Void.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Java class name is <code>java.lang.Boolean</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final SimpleType<Boolean> BOOLEAN =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new SimpleType<Boolean>(Boolean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Java class name is <code>java.lang.Character</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final SimpleType<Character> CHARACTER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        new SimpleType<Character>(Character.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Java class name is <code>java.lang.Byte</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final SimpleType<Byte> BYTE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        new SimpleType<Byte>(Byte.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Java class name is <code>java.lang.Short</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final SimpleType<Short> SHORT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        new SimpleType<Short>(Short.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Java class name is <code>java.lang.Integer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static final SimpleType<Integer> INTEGER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        new SimpleType<Integer>(Integer.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Java class name is <code>java.lang.Long</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public static final SimpleType<Long> LONG =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        new SimpleType<Long>(Long.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Java class name is <code>java.lang.Float</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public static final SimpleType<Float> FLOAT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        new SimpleType<Float>(Float.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Java class name is <code>java.lang.Double</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static final SimpleType<Double> DOUBLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        new SimpleType<Double>(Double.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Java class name is <code>java.lang.String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final SimpleType<String> STRING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        new SimpleType<String>(String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Java class name is <code>java.math.BigDecimal</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static final SimpleType<BigDecimal> BIGDECIMAL =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        new SimpleType<BigDecimal>(BigDecimal.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Java class name is <code>java.math.BigInteger</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static final SimpleType<BigInteger> BIGINTEGER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        new SimpleType<BigInteger>(BigInteger.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Java class name is <code>java.util.Date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public static final SimpleType<Date> DATE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        new SimpleType<Date>(Date.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * The <code>SimpleType</code> instance describing values whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Java class name is <code>javax.management.ObjectName</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static final SimpleType<ObjectName> OBJECTNAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        new SimpleType<ObjectName>(ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   166
    private static final SimpleType<?>[] typeArray = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        VOID, BOOLEAN, CHARACTER, BYTE, SHORT, INTEGER, LONG, FLOAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        DOUBLE, STRING, BIGDECIMAL, BIGINTEGER, DATE, OBJECTNAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private transient Integer myHashCode = null;        // As this instance is immutable, these two values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private transient String  myToString = null;        // need only be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /* *** Constructor *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private SimpleType(Class<T> valueClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        super(valueClass.getName(), valueClass.getName(), valueClass.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /* *** SimpleType specific information methods *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Tests whether <var>obj</var> is a value for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <code>SimpleType</code> instance.  <p> This method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <code>true</code> if and only if <var>obj</var> is not null and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <var>obj</var>'s class name is the same as the className field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * defined for this <code>SimpleType</code> instance (ie the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * name returned by the {@link OpenType#getClassName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * getClassName} method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param obj the object to be tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return <code>true</code> if <var>obj</var> is a value for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <code>SimpleType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public boolean isValue(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // Test if obj's class name is the same as for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return this.getClassName().equals(obj.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /* *** Methods overriden from class Object *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Compares the specified <code>obj</code> parameter with this <code>SimpleType</code> instance for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Two <code>SimpleType</code> instances are equal if and only if their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * {@link OpenType#getClassName() getClassName} methods return the same value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param  obj  the object to be compared for equality with this <code>SimpleType</code> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *              if <var>obj</var> is <code>null</code> or is not an instance of the class <code>SimpleType</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *              <code>equals</code> returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return  <code>true</code> if the specified object is equal to this <code>SimpleType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        /* If it weren't for readReplace(), we could replace this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
           with just:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
           return (this == obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   235
        if (!(obj instanceof SimpleType<?>))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   238
        SimpleType<?> other = (SimpleType<?>) obj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // Test if other's className field is the same as for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return this.getClassName().equals(other.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Returns the hash code value for this <code>SimpleType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * The hash code of a <code>SimpleType</code> instance is the the hash code of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * the string value returned by the {@link OpenType#getClassName() getClassName} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * As <code>SimpleType</code> instances are immutable, the hash code for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * on the first call to <code>hashCode</code>, and then the same value is returned for subsequent calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return  the hash code value for this <code>SimpleType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (myHashCode == null) {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   260
            myHashCode = Integer.valueOf(this.getClassName().hashCode());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns a string representation of this <code>SimpleType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * The string representation consists of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * the name of this class (ie <code>javax.management.openmbean.SimpleType</code>) and the type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * for this instance (which is the java class name of the values this <code>SimpleType</code> instance represents).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * As <code>SimpleType</code> instances are immutable, the string representation for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * on the first call to <code>toString</code>, and then the same value is returned for subsequent calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return  a string representation of this <code>SimpleType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        // Calculate the string representation if it has not yet been done (ie 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            myToString = this.getClass().getName()+ "(name="+ getTypeName() +")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // return always the same string representation for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   293
    private static final Map<SimpleType<?>,SimpleType<?>> canonicalTypes =
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   294
        new HashMap<SimpleType<?>,SimpleType<?>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        for (int i = 0; i < typeArray.length; i++) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   297
            final SimpleType<?> type = typeArray[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            canonicalTypes.put(type, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Replace an object read from an {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * java.io.ObjectInputStream} with the unique instance for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @return the replacement object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @exception ObjectStreamException if the read object cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public Object readResolve() throws ObjectStreamException {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   313
        final SimpleType<?> canonical = canonicalTypes.get(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (canonical == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            throw new InvalidObjectException("Invalid SimpleType: " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
}