1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/* * @(#)Attribute.java 4.25 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.management; // java import import java.io.Serializable; /** * Represents an MBean attribute by associating its name with its value. * The MBean server and other objects use this class to get and set attributes values. * * @since 1.5 */ public class Attribute implements Serializable { /* Serial version */ private static final long serialVersionUID = 2484220110589082382L; /** * @serial Attribute name. */ private String name; /** * @serial Attribute value */ private Object value= null; /** * Constructs an Attribute object which associates the given attribute name with the given value. * * @param name A String containing the name of the attribute to be created. Cannot be null. * @param value The Object which is assigned to the attribute. This object must be of the same type as the attribute. * */ public Attribute(String name, Object value) { if (name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null ")); } this.name = name; this.value = value; } /** * Returns a String containing the name of the attribute. * * @return the name of the attribute. */ public String getName() { return name; } /** * Returns an Object that is the value of this attribute. * * @return the value of the attribute. */ public Object getValue() { return value; } /** * Compares the current Attribute Object with another Attribute Object. * * @param object The Attribute that the current Attribute is to be compared with. * * @return True if the two Attribute objects are equal, otherwise false. */ public boolean equals(Object object) { if (!(object instanceof Attribute)) { return false; } Attribute val = (Attribute) object; if (value == null) { if (val.getValue() == null) { return name.equals(val.getName()); } else { return false; } } return ((name.equals(val.getName())) && (value.equals(val.getValue()))); } /** * Returns a hash code value for this attribute. * * @return a hash code value for this attribute. */ public int hashCode() { return name.hashCode() ^ (value == null ? 0 : value.hashCode()); } /** * Returns a String object representing this Attribute's value. The format of this * string is not specified, but users can expect that two Attributes return the * same string if and only if they are equal. */ public String toString() { return getName() + " = " + getValue(); } }