home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-tomcat-addon-1.4.9-installer.exe / jmx.jar / javax / management / Attribute.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-10-28  |  2.3 KB  |  76 lines

  1. package javax.management;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.Serializable;
  6.  
  7. public class Attribute implements Serializable {
  8.    private static final long serialVersionUID = 2484220110589082382L;
  9.    private String name;
  10.    private Object value;
  11.    private transient int m_hash;
  12.  
  13.    public Attribute(String name, Object value) {
  14.       if (name == null) {
  15.          throw new RuntimeOperationsException(new IllegalArgumentException("The name of an attribute cannot be null"));
  16.       } else {
  17.          this.name = name;
  18.          this.value = value;
  19.          this.m_hash = this.computeHash();
  20.       }
  21.    }
  22.  
  23.    public boolean equals(Object obj) {
  24.       if (obj == null) {
  25.          return false;
  26.       } else if (obj == this) {
  27.          return true;
  28.       } else {
  29.          try {
  30.             Attribute other = (Attribute)obj;
  31.             boolean namesEqual = this.name.equals(other.name);
  32.             boolean valuesEqual = false;
  33.             if (this.value == null) {
  34.                valuesEqual = other.value == null;
  35.             } else {
  36.                valuesEqual = this.value.equals(other.value);
  37.             }
  38.  
  39.             return namesEqual && valuesEqual;
  40.          } catch (ClassCastException var5) {
  41.             return false;
  42.          }
  43.       }
  44.    }
  45.  
  46.    public int hashCode() {
  47.       return this.m_hash;
  48.    }
  49.  
  50.    public String getName() {
  51.       return this.name;
  52.    }
  53.  
  54.    public Object getValue() {
  55.       return this.value;
  56.    }
  57.  
  58.    public String toString() {
  59.       return "Attribute's name: " + this.getName() + ", value: " + this.getValue();
  60.    }
  61.  
  62.    private int computeHash() {
  63.       int hash = this.name.hashCode();
  64.       if (this.value != null) {
  65.          hash ^= this.value.hashCode();
  66.       }
  67.  
  68.       return hash;
  69.    }
  70.  
  71.    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  72.       in.defaultReadObject();
  73.       this.m_hash = this.computeHash();
  74.    }
  75. }
  76.