1/* 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package javax.management; 27 28import java.util.Objects; 29 30 31/** 32 * Describes an argument of an operation exposed by an MBean. 33 * Instances of this class are immutable. Subclasses may be mutable 34 * but this is not recommended. 35 * 36 * @since 1.5 37 */ 38public class MBeanParameterInfo extends MBeanFeatureInfo implements Cloneable { 39 40 /* Serial version */ 41 static final long serialVersionUID = 7432616882776782338L; 42 43 /* All zero-length arrays are interchangeable. */ 44 static final MBeanParameterInfo[] NO_PARAMS = new MBeanParameterInfo[0]; 45 46 /** 47 * @serial The type or class name of the data. 48 */ 49 private final String type; 50 51 52 /** 53 * Constructs an {@code MBeanParameterInfo} object. 54 * 55 * @param name The name of the data 56 * @param type The type or class name of the data 57 * @param description A human readable description of the data. Optional. 58 */ 59 public MBeanParameterInfo(String name, 60 String type, 61 String description) { 62 this(name, type, description, (Descriptor) null); 63 } 64 65 /** 66 * Constructs an {@code MBeanParameterInfo} object. 67 * 68 * @param name The name of the data 69 * @param type The type or class name of the data 70 * @param description A human readable description of the data. Optional. 71 * @param descriptor The descriptor for the operation. This may be null 72 * which is equivalent to an empty descriptor. 73 * 74 * @since 1.6 75 */ 76 public MBeanParameterInfo(String name, 77 String type, 78 String description, 79 Descriptor descriptor) { 80 super(name, description, descriptor); 81 82 this.type = type; 83 } 84 85 86 /** 87 * <p>Returns a shallow clone of this instance. 88 * The clone is obtained by simply calling {@code super.clone()}, 89 * thus calling the default native shallow cloning mechanism 90 * implemented by {@code Object.clone()}. 91 * No deeper cloning of any internal field is made.</p> 92 * 93 * <p>Since this class is immutable, cloning is chiefly of 94 * interest to subclasses.</p> 95 */ 96 public Object clone () { 97 try { 98 return super.clone() ; 99 } catch (CloneNotSupportedException e) { 100 // should not happen as this class is cloneable 101 return null; 102 } 103 } 104 105 /** 106 * Returns the type or class name of the data. 107 * 108 * @return the type string. 109 */ 110 public String getType() { 111 return type; 112 } 113 114 public String toString() { 115 return 116 getClass().getName() + "[" + 117 "description=" + getDescription() + ", " + 118 "name=" + getName() + ", " + 119 "type=" + getType() + ", " + 120 "descriptor=" + getDescriptor() + 121 "]"; 122 } 123 124 /** 125 * Compare this MBeanParameterInfo to another. 126 * 127 * @param o the object to compare to. 128 * 129 * @return true if and only if {@code o} is an MBeanParameterInfo such 130 * that its {@link #getName()}, {@link #getType()}, 131 * {@link #getDescriptor()}, and {@link 132 * #getDescription()} values are equal (not necessarily identical) 133 * to those of this MBeanParameterInfo. 134 */ 135 public boolean equals(Object o) { 136 if (o == this) 137 return true; 138 if (!(o instanceof MBeanParameterInfo)) 139 return false; 140 MBeanParameterInfo p = (MBeanParameterInfo) o; 141 return (Objects.equals(p.getName(), getName()) && 142 Objects.equals(p.getType(), getType()) && 143 Objects.equals(p.getDescription(), getDescription()) && 144 Objects.equals(p.getDescriptor(), getDescriptor())); 145 } 146 147 public int hashCode() { 148 return Objects.hash(getName(), getType()); 149 } 150} 151