src/java.management/share/classes/javax/management/openmbean/TabularType.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 52902 e3398b2e1ab0
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52902
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.management.openmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
// java import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
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>TabularType</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 TabularData TabularData} values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class TabularType extends OpenType<TabularData> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final long serialVersionUID = 6554071860220659261L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
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 The composite type of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private CompositeType  rowType;
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 The items used to index each row element, kept in the order the user gave
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *         This is an unmodifiable {@link ArrayList}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 52902
diff changeset
    62
    @SuppressWarnings("serial") // Conditionally serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private List<String> indexNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private transient Integer myHashCode = null; // As this instance is immutable, these two values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private transient String  myToString = null; // need only be calculated once.
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>TabularType</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
     * The Java class name of tabular data values this tabular type represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * (ie the class name returned by the {@link OpenType#getClassName() getClassName} method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * is set to the string value returned by <code>TabularData.class.getName()</code>.
24368
2b4801b94265 8038795: Tidy warnings cleanup for javax.management
yan
parents: 23010
diff changeset
    79
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param  typeName  The name given to the tabular type this instance represents; cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <br>&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param  description  The human readable description of the tabular type this instance represents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *                      cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * <br>&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param  rowType  The type of the row elements of tabular data values described by this tabular type instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *                  cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <br>&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param  indexNames  The names of the items the values of which are used to uniquely index each row element in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *                     tabular data values described by this tabular type instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *                     cannot be null or empty. Each element should be an item name defined in <var>rowType</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *                     (no null or empty string allowed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *                     It is important to note that the <b>order</b> of the item names in <var>indexNames</var>
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    93
     *                     is used by the methods {@link TabularData#get(java.lang.Object[]) get} and
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
    94
     *                     {@link TabularData#remove(java.lang.Object[]) remove} of class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *                     <code>TabularData</code> to match their array of values parameter to items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <br>&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @throws IllegalArgumentException  if <var>rowType</var> is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *                                   or <var>indexNames</var> is a null or empty array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *                                   or an element in <var>indexNames</var> is a null or empty string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *                                   or <var>typeName</var> or <var>description</var> is a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <br>&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @throws OpenDataException  if an element's value of <var>indexNames</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *                            is not an item name defined in <var>rowType</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public TabularType(String         typeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                       String         description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                       CompositeType  rowType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                       String[]       indexNames) throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // Check and initialize state defined by parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        super(TabularData.class.getName(), typeName, description, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // Check rowType is not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (rowType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new IllegalArgumentException("Argument rowType cannot be null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // Check indexNames is neither null nor empty and does not contain any null element or empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        checkForNullElement(indexNames, "indexNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        checkForEmptyString(indexNames, "indexNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // Check all indexNames values are valid item names for rowType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        for (int i=0; i<indexNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if ( ! rowType.containsKey(indexNames[i]) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                throw new OpenDataException("Argument's element value indexNames["+ i +"]=\""+ indexNames[i] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                            "\" is not a valid item name for rowType.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // initialize rowType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.rowType    = rowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // initialize indexNames (copy content so that subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // modifs to the array referenced by the indexNames parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // have no impact)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        List<String> tmpList = new ArrayList<String>(indexNames.length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        for (int i=0; i<indexNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            tmpList.add(indexNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        this.indexNames = Collections.unmodifiableList(tmpList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Checks that Object[] arg is neither null nor empty (ie length==0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * and that it does not contain any null element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static void checkForNullElement(Object[] arg, String argName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if ( (arg == null) || (arg.length == 0) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new IllegalArgumentException("Argument "+ argName +"[] cannot be null or empty.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        for (int i=0; i<arg.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (arg[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Checks that String[] does not contain any empty (or blank characters only) string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private static void checkForEmptyString(String[] arg, String argName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        for (int i=0; i<arg.length; i++) {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   169
            if (arg[i].trim().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be an empty string.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /* *** Tabular type specific information methods *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Returns the type of the row elements of tabular data values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * described by this <code>TabularType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @return the type of each row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public CompositeType getRowType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return rowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>Returns, in the same order as was given to this instance's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * constructor, an unmodifiable List of the names of the items the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * values of which are used to uniquely index each row element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * tabular data values described by this <code>TabularType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return a List of String representing the names of the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public List<String> getIndexNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return indexNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Tests whether <var>obj</var> is a value which could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * described by this <code>TabularType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p>If <var>obj</var> is null or is not an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <code>javax.management.openmbean.TabularData</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>isValue</code> returns <code>false</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <p>If <var>obj</var> is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <code>javax.management.openmbean.TabularData</code>, say {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * td}, the result is true if this {@code TabularType} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <em>assignable from</em> {@link TabularData#getTabularType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * td.getTabularType()}, as defined in {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * CompositeType#isValue CompositeType.isValue}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param obj the value whose open type is to be tested for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * compatibility with this <code>TabularType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @return <code>true</code> if <var>obj</var> is a value for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * tabular type, <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public boolean isValue(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // if obj is null or not a TabularData, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (!(obj instanceof TabularData))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // if obj is not a TabularData, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        TabularData value = (TabularData) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        TabularType valueType = value.getTabularType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return isAssignableFrom(valueType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    @Override
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   241
    boolean isAssignableFrom(OpenType<?> ot) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (!(ot instanceof TabularType))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        TabularType tt = (TabularType) ot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!getTypeName().equals(tt.getTypeName()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                !getIndexNames().equals(tt.getIndexNames()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return getRowType().isAssignableFrom(tt.getRowType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /* *** Methods overriden from class Object *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Compares the specified <code>obj</code> parameter with this <code>TabularType</code> instance for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Two <code>TabularType</code> instances are equal if and only if all of the following statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * <li>their type names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <li>their row types are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <li>they use the same index names, in the same order</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <br>&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param  obj  the object to be compared for equality with this <code>TabularType</code> instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *              if <var>obj</var> is <code>null</code>, <code>equals</code> returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @return  <code>true</code> if the specified object is equal to this <code>TabularType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        // if obj is not a TabularType, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        TabularType other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            other = (TabularType) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // Now, really test for equality between this TabularType instance and the other:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // their names should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if ( ! this.getTypeName().equals(other.getTypeName()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // their row types should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if ( ! this.rowType.equals(other.rowType) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // their index names should be equal and in the same order (ensured by List.equals())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if ( ! this.indexNames.equals(other.indexNames) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // All tests for equality were successfull
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return true;
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 the hash code value for this <code>TabularType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * The hash code of a <code>TabularType</code> instance is the sum of the hash codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * of all elements of information used in <code>equals</code> comparisons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * (ie: name, row type, index names).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * for any two <code>TabularType</code> instances <code>t1</code> and <code>t2</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * as required by the general contract of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * {@link Object#hashCode() Object.hashCode()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * As <code>TabularType</code> instances are immutable, the hash code for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * 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
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @return  the hash code value for this <code>TabularType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            value += this.getTypeName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            value += this.rowType.hashCode();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   333
            for (String index : indexNames)
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   334
                value += index.hashCode();
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   335
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Returns a string representation of this <code>TabularType</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * The string representation consists of the name of this class (ie <code>javax.management.openmbean.TabularType</code>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * the type name for this instance, the row type string representation of this instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * and the index names of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * As <code>TabularType</code> instances are immutable, the string representation for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * 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
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return  a string representation of this <code>TabularType</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // Calculate the string representation if it has not yet been done (ie 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            final StringBuilder result = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                .append(this.getClass().getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                .append("(name=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                .append(getTypeName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                .append(",rowType=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                .append(rowType.toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                .append(",indexNames=(");
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   367
            String sep = "";
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   368
            for (String index : indexNames) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   369
                result.append(sep).append(index);
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   370
                sep = ",";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            result.append("))");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            myToString = result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // return always the same string representation for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
}