FileDocCategorySizeDatePackage
Identity.javaAPI DocExample2220Mon Oct 05 22:20:46 BST 1998jdc.util

Identity

public class Identity extends Object implements Serializable
A representation of an agent identity, for general use in distributed computing contexts. This base class is a simple wrapper around a property list, with an equality method implemented to compare the name and id of two Identities, for purposes of correlating messages from the same agent. Subclasses can extend the interface to provide additional properties or certification tokens. Source code from "Java Distributed Computing", 2nd ed., Jim Farley. Class: Identity Example: ?? Description: Representation of an agent identity.

Fields Summary
protected Hashtable
props
Constructors Summary
public Identity()


    
public Identity(int id)

 props.put("idnum", new Integer(id)); 
Methods Summary
public booleanequals(java.lang.Object o)
Check the equality of two identities. In the default case, equality is based on a comparison of the name and id of the two Identities.

    boolean same = true;
    if (o != null && o.getClass() == this.getClass()) {
      Identity oi = (Identity)o;
      Hashtable oProps = oi.props;
      Enumeration keys = this.props.keys();
      while (keys.hasMoreElements()) {
	Object key = keys.nextElement();
	Object prop = this.props.get(key);
	Object oProp = oProps.get(key);
	if ((prop == null && oProp == null) ||
	    (prop != null && oProp != null &&
	     prop.equals(oProp))) {
	  // Do nothing, still equal as far as we know
	}
	else {
	  // Found a non-equal property pair.  Quit here.
	  same = false;
	  break;
	}
      }
    }
    return same;
  
public intgetId()

    Integer idNum = (Integer)props.get("idnum");
    if (idNum != null) {
      return idNum.intValue();
    }
    else {
      return -1;
    }
  
public java.lang.StringgetName()

 return (String)props.get("name"); 
public java.lang.ObjectgetProperty(java.lang.Object key)

    return props.get(key);
  
public voidsetName(java.lang.String n)

 props.put("name", n); 
public voidsetProperty(java.lang.Object key, java.lang.Object val)

    props.put(key, val);