/* 
   David Tate

	Authorization token class.
	Provides getter methods for parts of token
		so that the identity of a user can be
		verified with their token.
	toString hides some details but provides 
		basic information about the token.
*/

import java.net.*;
import java.io.*;

public class Token implements Serializable {
	private long value;		//value of token to system
	private InetAddress address;
	private long port;
	private long time;		//time issued

   private String name;		//name of owner

   public Token (InetAddress a, int p, long t, String n) {
   	this.address = a;
      this.port = p;
      this.time = t;
      this.name= n;

      this.value = n.hashCode() + time;
   }

   public String getName() {
   	return name;
   }

   public long getValue() {
   	return value;
   }

   public InetAddress getAddress() {
      return address;
   }

   public long getPort() {
   	return port;
   }

   public long getTime() {
      return time;
	}

	public String toString() {
		return name + time;
	}

	public boolean equals (Object other) {
		try {
			Token otherTok = (Token) other;
			return this.value == otherTok.value;
		}
		catch (Exception e) {
			return false;
		}
	}
} //end Token

