jdk/src/share/classes/javax/management/openmbean/CompositeDataSupport.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1020 e7a021898dff
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.SortedMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
// jmx import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
//
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 <tt>CompositeDataSupport</tt> class is the <i>open data</i> class which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * implements the <tt>CompositeData</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class CompositeDataSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    implements CompositeData, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static final long serialVersionUID = 8003518976613702244L;
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 Internal representation of the mapping of item names to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * respective values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *         A {@link SortedMap} is used for faster retrieval of elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private SortedMap<String, Object> contents = new TreeMap<String, Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @serial The <i>composite type </i> of this <i>composite data</i> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private CompositeType compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Constructs a <tt>CompositeDataSupport</tt> instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <tt>compositeType</tt>, whose item values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * are specified by <tt>itemValues[]</tt>, in the same order as in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <tt>itemNames[]</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * As a <tt>CompositeType</tt> does not specify any order on its items,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * the <tt>itemNames[]</tt> parameter is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * to specify the order in which the values are given in <tt>itemValues[]</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * The items contained in this <tt>CompositeDataSupport</tt> instance are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * internally stored in a <tt>TreeMap</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * thus sorted in ascending lexicographic order of their names, for faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * retrieval of individual item values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * The constructor checks that all the constraints listed below for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * parameter are satisfied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * and throws the appropriate exception if they are not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param  compositeType  the <i>composite type </i> of this <i>composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * data</i> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *                        must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param  itemNames  <tt>itemNames</tt> must list, in any order, all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * item names defined in <tt>compositeType</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *                    the order in which the names are listed, is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * match values in <tt>itemValues[]</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *                    must not be null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param  itemValues  the values of the items, listed in the same order as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * their respective names in <tt>itemNames</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *                     each item value can be null, but if it is non-null it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *                     a valid value for the open type defined in <tt>compositeType</tt> for the corresponding item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *                     must be of the same size as <tt>itemNames</tt>; must not be null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @throws  IllegalArgumentException  <tt>compositeType</tt> is null, or <tt>itemNames[]</tt> or <tt>itemValues[]</tt> is null or empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *                                    or one of the elements in <tt>itemNames[]</tt>  is a null or empty string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *                                    or <tt>itemNames[]</tt> and <tt>itemValues[]</tt> are not of the same size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @throws  OpenDataException  <tt>itemNames[]</tt> or <tt>itemValues[]</tt>'s size differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *                             the number of items defined in <tt>compositeType</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *                             or one of the elements in <tt>itemNames[]</tt> does not exist as an item name defined in <tt>compositeType</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *                             or one of the elements in <tt>itemValues[]</tt> is not a valid value for the corresponding item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *                             as defined in <tt>compositeType</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public CompositeDataSupport(CompositeType compositeType, String[] itemNames, Object[] itemValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // Check compositeType is not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (compositeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new IllegalArgumentException("Argument compositeType cannot be null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // item names defined in compositeType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        Set<String> namesSet = compositeType.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // Check the array itemNames is not null or empty (length!=0) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // that there is no null element or empty string in it
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
        checkForEmptyString(itemNames, "itemNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // Check the array itemValues is not null or empty (length!=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // (NOTE: we allow null values as array elements)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if ( (itemValues == null) || (itemValues.length == 0) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new IllegalArgumentException("Argument itemValues[] cannot be null or empty.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // Check that the sizes of the 2 arrays itemNames and itemValues are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (itemNames.length != itemValues.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new IllegalArgumentException("Array arguments itemNames[] and itemValues[] "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                               "should be of same length (got "+ itemNames.length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                               " and "+ itemValues.length +").");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // Check the size of the 2 arrays is equal to the number of items defined in compositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (itemNames.length != namesSet.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throw new OpenDataException("The size of array arguments itemNames[] and itemValues[] should be equal to the number of items defined"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                        " in argument compositeType (found "+ itemNames.length +" elements in itemNames[] and itemValues[],"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                        " expecting "+ namesSet.size() +" elements according to compositeType.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // Check parameter itemNames[] contains all names defined in the compositeType of this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if ( ! Arrays.asList(itemNames).containsAll(namesSet) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new OpenDataException("Argument itemNames[] does not contain all names defined in the compositeType of this instance.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // Check each element of itemValues[], if not null, is of the open type defined for the corresponding item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        OpenType<?> itemType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        for (int i=0; i<itemValues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            itemType = compositeType.getType(itemNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if ( (itemValues[i] != null) && (! itemType.isValue(itemValues[i])) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                throw new OpenDataException("Argument's element itemValues["+ i +"]=\""+ itemValues[i] +"\" is not a valid value for"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                            " this item (itemName="+ itemNames[i] +",itemType="+ itemType +").");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // Initialize internal fields: compositeType and contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.compositeType = compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        for (int i=0; i<itemNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            this.contents.put(itemNames[i], itemValues[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Constructs a <tt>CompositeDataSupport</tt> instance with the specified <tt>compositeType</tt>, whose item names and corresponding values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * are given by the mappings in the map <tt>items</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * This constructor converts the keys to a string array and the values to an object array and calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <tt>CompositeDataSupport(javax.management.openmbean.CompositeType, java.lang.String[], java.lang.Object[])</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param  compositeType  the <i>composite type </i> of this <i>composite data</i> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *                        must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param  items  the mappings of all the item names to their values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *                <tt>items</tt> must contain all the item names defined in <tt>compositeType</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *                must not be null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @throws  IllegalArgumentException  <tt>compositeType</tt> is null, or <tt>items</tt> is null or empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *                                    or one of the keys in <tt>items</tt>  is a null or empty string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *                                    or one of the values in <tt>items</tt>  is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @throws  OpenDataException  <tt>items</tt>' size differs from the number of items defined in <tt>compositeType</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *                             or one of the keys in <tt>items</tt> does not exist as an item name defined in <tt>compositeType</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *                             or one of the values in <tt>items</tt> is not a valid value for the corresponding item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *                             as defined in <tt>compositeType</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @throws ArrayStoreException  one or more keys in <tt>items</tt> is not of the class <tt>java.lang.String</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public CompositeDataSupport(CompositeType compositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                Map<String,?> items)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // Let the other constructor do the job, as the call to another constructor must be the first call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this( compositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
              (items==null  ?  null  :  items.keySet().toArray(new String[items.size()])), // may raise an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
              (items==null  ?  null  :  items.values().toArray()) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    private static void checkForNullElement(Object[] arg, String argName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if ( (arg == null) || (arg.length == 0) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                       "Argument "+ argName +"[] cannot be null or empty.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        for (int i=0; i<arg.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (arg[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                       "Argument's element "+ argName +"["+ i +"] cannot be null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static void checkForEmptyString(String[] arg, String argName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        for (int i=0; i<arg.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (arg[i].trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                  "Argument's element "+ argName +"["+ i +"] cannot be an empty string.");
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Returns the <i>composite type </i> of this <i>composite data</i> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public CompositeType getCompositeType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Returns the value of the item whose name is <tt>key</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws IllegalArgumentException  if <tt>key</tt> is a null or empty String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @throws InvalidKeyException  if <tt>key</tt> is not an existing item name for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * this <tt>CompositeData</tt> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public Object get(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if ( (key == null) || (key.trim().equals("")) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            throw new IllegalArgumentException("Argument key cannot be a null or empty String.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if ( ! contents.containsKey(key.trim())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            throw new InvalidKeyException("Argument key=\""+ key.trim() +"\" is not an existing item name for this CompositeData instance.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return contents.get(key.trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Returns an array of the values of the items whose names are specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <tt>keys</tt>, in the same order as <tt>keys</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @throws IllegalArgumentException  if an element in <tt>keys</tt> is a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * or empty String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws InvalidKeyException  if an element in <tt>keys</tt> is not an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * item name for this <tt>CompositeData</tt> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public Object[] getAll(String[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if ( (keys == null) || (keys.length == 0) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return new Object[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        Object[] results = new Object[keys.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        for (int i=0; i<keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            results[i] = this.get(keys[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return results;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns <tt>true</tt> if and only if this <tt>CompositeData</tt> instance contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * an item whose name is <tt>key</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * If <tt>key</tt> is a null or empty String, this method simply returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public boolean containsKey(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if ( (key == null) || (key.trim().equals("")) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return contents.containsKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Returns <tt>true</tt> if and only if this <tt>CompositeData</tt> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * contains an item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * whose value is <tt>value</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public boolean containsValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return contents.containsValue(value);
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
     * Returns an unmodifiable Collection view of the item values contained in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <tt>CompositeData</tt> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * The returned collection's iterator will return the values in the ascending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * lexicographic order of the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * item names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public Collection<?> values() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return Collections.unmodifiableCollection(contents.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Compares the specified <var>obj</var> parameter with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <code>CompositeDataSupport</code> instance for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Returns <tt>true</tt> if and only if all of the following statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <li><var>obj</var> is non null,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <li><var>obj</var> also implements the <code>CompositeData</code> interface,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <li>their composite types are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <li>their contents, i.e. (name, value) pairs are equal. If a value contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * the content is an array, the value comparison is done as if by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * the {@link java.util.Arrays#deepEquals(Object[], Object[]) deepEquals} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * for arrays of object reference types or the appropriate overloading of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * {@code Arrays.equals(e1,e2)} for arrays of primitive types</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * This ensures that this <tt>equals</tt> method works properly for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * <var>obj</var> parameters which are different implementations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <code>CompositeData</code> interface, with the restrictions mentioned in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * {@link java.util.Collection#equals(Object) equals}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * method of the <tt>java.util.Collection</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param  obj  the object to be compared for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <code>CompositeDataSupport</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @return  <code>true</code> if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <code>CompositeDataSupport</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // if obj is not a CompositeData, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (!(obj instanceof CompositeData)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        CompositeData other = (CompositeData) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // their compositeType should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (!this.getCompositeType().equals(other.getCompositeType()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (contents.size() != other.values().size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        for (Map.Entry<String,Object> entry : contents.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            Object e1 = entry.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            Object e2 = other.get(entry.getKey());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (e1 == e2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            if (e1 == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            boolean eq = e1.getClass().isArray() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                Arrays.deepEquals(new Object[] {e1}, new Object[] {e2}) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                e1.equals(e2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (!eq)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        // All tests for equality were successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Returns the hash code value for this <code>CompositeDataSupport</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * The hash code of a <code>CompositeDataSupport</code> instance is the sum of the hash codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * of all elements of information used in <code>equals</code> comparisons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * (ie: its <i>composite type</i> and all the item values).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * for any two <code>CompositeDataSupport</code> instances <code>t1</code> and <code>t2</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * as required by the general contract of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * {@link Object#hashCode() Object.hashCode()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Each item value's hash code is added to the returned hash code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * If an item value is an array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * its hash code is obtained as if by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * {@link java.util.Arrays#deepHashCode(Object[]) deepHashCode} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * for arrays of object reference types or the appropriate overloading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * of {@code Arrays.hashCode(e)} for arrays of primitive types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @return the hash code value for this <code>CompositeDataSupport</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        int hashcode = compositeType.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        for (Object o : contents.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (o instanceof Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                hashcode += Arrays.deepHashCode((Object[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            else if (o instanceof byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                hashcode += Arrays.hashCode((byte[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            else if (o instanceof short[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                hashcode += Arrays.hashCode((short[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            else if (o instanceof int[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                hashcode += Arrays.hashCode((int[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            else if (o instanceof long[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                hashcode += Arrays.hashCode((long[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            else if (o instanceof char[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                hashcode += Arrays.hashCode((char[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            else if (o instanceof float[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                hashcode += Arrays.hashCode((float[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            else if (o instanceof double[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                hashcode += Arrays.hashCode((double[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            else if (o instanceof boolean[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                hashcode += Arrays.hashCode((boolean[]) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            else if (o != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                hashcode += o.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return hashcode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Returns a string representation of this <code>CompositeDataSupport</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * The string representation consists of the name of this class (ie <code>javax.management.openmbean.CompositeDataSupport</code>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * the string representation of the composite type of this instance, and the string representation of the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * (ie list the itemName=itemValue mappings).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @return  a string representation of this <code>CompositeDataSupport</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        return new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            .append(this.getClass().getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            .append("(compositeType=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            .append(compositeType.toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            .append(",contents=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            .append(contents.toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            .append(")")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            .toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
}