jdk/src/share/classes/javax/management/openmbean/CompositeType.java
author yan
Mon, 12 May 2014 14:33:13 +0400
changeset 24368 2b4801b94265
parent 23010 6dadb192ad81
permissions -rw-r--r--
8038795: Tidy warnings cleanup for javax.management Reviewed-by: dfuchs Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
     2
 * Copyright (c) 2000, 2014, 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: 4156
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: 4156
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: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
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.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
// jmx import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The <code>CompositeType</code> class is the <i>open type</i> class
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    43
 * whose instances describe the types of {@link CompositeData CompositeData} values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class CompositeType extends OpenType<CompositeData> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final long serialVersionUID = -5366242454346948798L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @serial Sorted mapping of the item names to their descriptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private TreeMap<String,String> nameToDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @serial Sorted mapping of the item names to their open types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private TreeMap<String,OpenType<?>> nameToType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /* As this instance is immutable, following three values need only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * be calculated once.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private transient Integer myHashCode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private transient String  myToString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private transient Set<String> myNamesSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* *** Constructor *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Constructs a <code>CompositeType</code> instance, checking for the validity of the given parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * The validity constraints are described below for each parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Note that the contents of the three array parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <var>itemNames</var>, <var>itemDescriptions</var> and <var>itemTypes</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * are internally copied so that any subsequent modification of these arrays by the caller of this constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * has no impact on the constructed <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * The Java class name of composite data values this composite type represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * (ie the class name returned by the {@link OpenType#getClassName() getClassName} method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * is set to the string value returned by <code>CompositeData.class.getName()</code>.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
    84
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param  typeName  The name given to the composite type this instance represents; cannot be a null or empty string.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
    86
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param  description  The human readable description of the composite type this instance represents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *                      cannot be a null or empty string.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
    89
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param  itemNames  The names of the items contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *                    composite data values described by this <code>CompositeType</code> instance;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
    92
     *                    cannot be null and should contain at least one element; no element can be a null or empty string.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *                    Note that the order in which the item names are given is not important to differentiate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *                    <code>CompositeType</code> instance from another;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *                    the item names are internally stored sorted in ascending alphanumeric order.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
    96
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param  itemDescriptions  The descriptions, in the same order as <var>itemNames</var>, of the items contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *                           composite data values described by this <code>CompositeType</code> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *                           should be of the same size as <var>itemNames</var>;
1154
4561ee1fb2b7 6405862: Allow CompositeType to have zero items
emcmanus
parents: 715
diff changeset
   100
     *                           no element can be null or an empty string.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
   101
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param  itemTypes  The open type instances, in the same order as <var>itemNames</var>, describing the items contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *                    in the composite data values described by this <code>CompositeType</code> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *                    should be of the same size as <var>itemNames</var>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *                    no element can be null.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
   106
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws IllegalArgumentException  If <var>typeName</var> or <var>description</var> is a null or empty string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *                                   or <var>itemNames</var> or <var>itemDescriptions</var> or <var>itemTypes</var> is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *                                   or any element of <var>itemNames</var> or <var>itemDescriptions</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *                                   is a null or empty string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *                                   or any element of <var>itemTypes</var> is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *                                   or <var>itemNames</var> or <var>itemDescriptions</var> or <var>itemTypes</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *                                   are not of the same size.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
   114
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @throws OpenDataException  If <var>itemNames</var> contains duplicate item names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *                            (case sensitive, but leading and trailing whitespaces removed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public CompositeType(String        typeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                         String        description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                         String[]      itemNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                         String[]      itemDescriptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                         OpenType<?>[] itemTypes) throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // Check and construct state defined by parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        super(CompositeData.class.getName(), typeName, description, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   128
        // Check the 3 arrays are not null or empty (ie length==0) and that there is no null element or empty string in them
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        checkForNullElement(itemNames, "itemNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        checkForNullElement(itemDescriptions, "itemDescriptions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        checkForNullElement(itemTypes, "itemTypes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        checkForEmptyString(itemNames, "itemNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        checkForEmptyString(itemDescriptions, "itemDescriptions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // Check the sizes of the 3 arrays are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if ( (itemNames.length != itemDescriptions.length) || (itemNames.length != itemTypes.length) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new IllegalArgumentException("Array arguments itemNames[], itemDescriptions[] and itemTypes[] "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                               "should be of same length (got "+ itemNames.length +", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                               itemDescriptions.length +" and "+ itemTypes.length +").");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // Initialize internal "names to descriptions" and "names to types" sorted maps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // and, by doing so, check there are no duplicate item names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        nameToDescription = new TreeMap<String,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        nameToType        = new TreeMap<String,OpenType<?>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        for (int i=0; i<itemNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            key = itemNames[i].trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if (nameToDescription.containsKey(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                throw new OpenDataException("Argument's element itemNames["+ i +"]=\""+ itemNames[i] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                            "\" duplicates a previous item names.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            nameToDescription.put(key, itemDescriptions[i].trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            nameToType.put(key, itemTypes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static void checkForNullElement(Object[] arg, String argName) {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   162
        if ( (arg == null) || (arg.length == 0) ) {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   163
            throw new IllegalArgumentException("Argument "+ argName +"[] cannot be null or empty.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        for (int i=0; i<arg.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if (arg[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            }
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 static void checkForEmptyString(String[] arg, String argName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        for (int i=0; i<arg.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (arg[i].trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be an empty string.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /* *** Composite type specific information methods *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns <code>true</code> if this <code>CompositeType</code> instance defines an item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * whose name is <var>itemName</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param itemName the name of the item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return true if an item of this name is present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean containsKey(String itemName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (itemName == null) {
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
        return nameToDescription.containsKey(itemName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns the description of the item whose name is <var>itemName</var>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * or <code>null</code> if this <code>CompositeType</code> instance does not define any item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * whose name is <var>itemName</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param itemName the name of the item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return the description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String getDescription(String itemName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (itemName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return nameToDescription.get(itemName);
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
     * Returns the <i>open type</i> of the item whose name is <var>itemName</var>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * or <code>null</code> if this <code>CompositeType</code> instance does not define any item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * whose name is <var>itemName</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param itemName the name of the time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return the type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public OpenType<?> getType(String itemName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (itemName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return (OpenType<?>) nameToType.get(itemName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns an unmodifiable Set view of all the item names defined by this <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * The set's iterator will return the item names in ascending order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return a {@link Set} of {@link String}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public Set<String> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // Initializes myNamesSet on first call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (myNamesSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            myNamesSet = Collections.unmodifiableSet(nameToDescription.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return myNamesSet; // always return the same value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Tests whether <var>obj</var> is a value which could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * described by this <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>If <var>obj</var> is null or is not an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <code>javax.management.openmbean.CompositeData</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <code>isValue</code> returns <code>false</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>If <var>obj</var> is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <code>javax.management.openmbean.CompositeData</code>, then let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * {@code ct} be its {@code CompositeType} as returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * CompositeData#getCompositeType()}.  The result is true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * {@code this} is <em>assignable from</em> {@code ct}.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * means that:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <li>{@link #getTypeName() this.getTypeName()} equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * {@code ct.getTypeName()}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <li>there are no item names present in {@code this} that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * not also present in {@code ct}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <li>for every item in {@code this}, its type is assignable from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * the type of the corresponding item in {@code ct}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <p>A {@code TabularType} is assignable from another {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * TabularType} if they have the same {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * TabularType#getTypeName() typeName} and {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * TabularType#getIndexNames() index name list}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * {@linkplain TabularType#getRowType() row type} of the first is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * assignable from the row type of the second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <p>An {@code ArrayType} is assignable from another {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * ArrayType} if they have the same {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * ArrayType#getDimension() dimension}; and both are {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * ArrayType#isPrimitiveArray() primitive arrays} or neither is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * and the {@linkplain ArrayType#getElementOpenType() element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * type} of the first is assignable from the element type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <p>In every other case, an {@code OpenType} is assignable from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * another {@code OpenType} only if they are equal.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <p>These rules mean that extra items can be added to a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * CompositeData} without making it invalid for a {@code CompositeType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * that does not have those items.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param  obj  the value whose open type is to be tested for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * with this <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return <code>true</code> if <var>obj</var> is a value for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * composite type, <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public boolean isValue(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // if obj is null or not CompositeData, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (!(obj instanceof CompositeData)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // if obj is not a CompositeData, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        CompositeData value = (CompositeData) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // test value's CompositeType is assignable to this CompositeType instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        CompositeType valueType = value.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return this.isAssignableFrom(valueType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Tests whether values of the given type can be assigned to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * open type.  The result is true if the given type is also a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * CompositeType with the same name ({@link #getTypeName()}), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * every item in this type is also present in the given type with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * the same name and assignable type.  There can be additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * items in the given type, which are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param ot the type to be tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @return true if {@code ot} is assignable to this open type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    @Override
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1154
diff changeset
   332
    boolean isAssignableFrom(OpenType<?> ot) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (!(ot instanceof CompositeType))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        CompositeType ct = (CompositeType) ot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (!ct.getTypeName().equals(getTypeName()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        for (String key : keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            OpenType<?> otItemType = ct.getType(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            OpenType<?> thisItemType = getType(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (otItemType == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    !thisItemType.isAssignableFrom(otItemType))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /* *** Methods overriden from class Object *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Compares the specified <code>obj</code> parameter with this <code>CompositeType</code> instance for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Two <code>CompositeType</code> instances are equal if and only if all of the following statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <li>their type names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <li>their items' names and types are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * </ul>
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
   359
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param  obj  the object to be compared for equality with this <code>CompositeType</code> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *              if <var>obj</var> is <code>null</code>, <code>equals</code> returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @return  <code>true</code> if the specified object is equal to this <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        // if obj is not a CompositeType, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        CompositeType other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            other = (CompositeType) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // Now, really test for equality between this CompositeType instance and the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // their names should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if ( ! this.getTypeName().equals(other.getTypeName()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        // their items names and types should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if ( ! this.nameToType.equals(other.nameToType) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // All tests for equality were successfull
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Returns the hash code value for this <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * The hash code of a <code>CompositeType</code> instance is the sum of the hash codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * of all elements of information used in <code>equals</code> comparisons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * (ie: name, items names, items types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * for any two <code>CompositeType</code> instances <code>t1</code> and <code>t2</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * as required by the general contract of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * {@link Object#hashCode() Object.hashCode()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * As <code>CompositeType</code> instances are immutable, the hash code for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * 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
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return  the hash code value for this <code>CompositeType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            value += this.getTypeName().hashCode();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1154
diff changeset
   423
            for (String key : nameToDescription.keySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                value += key.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                value += this.nameToType.get(key).hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   427
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Returns a string representation of this <code>CompositeType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * The string representation consists of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * the name of this class (ie <code>javax.management.openmbean.CompositeType</code>), the type name for this instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * and the list of the items names and types string representation of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * As <code>CompositeType</code> instances are immutable, the string representation for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * 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
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return  a string representation of this <code>CompositeType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // Calculate the string representation if it has not yet been done (ie 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            final StringBuilder result = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            result.append(this.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            result.append("(name=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            result.append(getTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            result.append(",items=(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            int i=0;
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1154
diff changeset
   458
            Iterator<String> k=nameToType.keySet().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            while (k.hasNext()) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1154
diff changeset
   461
                key = k.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                if (i > 0) result.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                result.append("(itemName=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                result.append(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                result.append(",itemType=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                result.append(nameToType.get(key).toString() +")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            result.append("))");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            myToString = result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // return always the same string representation for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
}