home *** CD-ROM | disk | FTP | other *** search
- package javax.management;
-
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.Serializable;
-
- public class Attribute implements Serializable {
- private static final long serialVersionUID = 2484220110589082382L;
- private String name;
- private Object value;
- private transient int m_hash;
-
- public Attribute(String name, Object value) {
- if (name == null) {
- throw new RuntimeOperationsException(new IllegalArgumentException("The name of an attribute cannot be null"));
- } else {
- this.name = name;
- this.value = value;
- this.m_hash = this.computeHash();
- }
- }
-
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- } else if (obj == this) {
- return true;
- } else {
- try {
- Attribute other = (Attribute)obj;
- boolean namesEqual = this.name.equals(other.name);
- boolean valuesEqual = false;
- if (this.value == null) {
- valuesEqual = other.value == null;
- } else {
- valuesEqual = this.value.equals(other.value);
- }
-
- return namesEqual && valuesEqual;
- } catch (ClassCastException var5) {
- return false;
- }
- }
- }
-
- public int hashCode() {
- return this.m_hash;
- }
-
- public String getName() {
- return this.name;
- }
-
- public Object getValue() {
- return this.value;
- }
-
- public String toString() {
- return "Attribute's name: " + this.getName() + ", value: " + this.getValue();
- }
-
- private int computeHash() {
- int hash = this.name.hashCode();
- if (this.value != null) {
- hash ^= this.value.hashCode();
- }
-
- return hash;
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- this.m_hash = this.computeHash();
- }
- }
-