home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / sys / user.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  3.1 KB  |  117 lines

  1. /*
  2. * @(#)User.java    1.0 95/11/09 Ulrich Gall & Jan Kautz
  3. *
  4. * Copyright (c) 1996 Ulrich Gall & Jan Kautz 
  5. * uhgall@cip.informatik.uni-erlangen.de
  6. * Hofmannstr. 48, D-91052 Erlangen, Germany, Fax: +49-9131-201358
  7. *
  8. * Permission to use, copy, and distribute this software
  9. * and its documentation for NON-COMMERCIAL purposes and without
  10. * fee is hereby granted provided that this copyright notice
  11. * appears in all copies. Please contact us for  further copyright 
  12. * and licensing information.
  13. *
  14. * WE MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15. * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WE SHALL NOT BE LIABLE FOR
  18. * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19. * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20. */
  21.  
  22. package como.sys;
  23.  
  24. import como.io.*;
  25. import java.util.*;
  26. import java.io.IOException;
  27.  
  28. /**
  29.  * This class stores information about users. You can put anything in it;
  30.  * As keys, either use sufficiently large Integers or any other class; the safest
  31.  * way is to use instances of one of your own classes as keys.
  32.  * 
  33.  * A number of standard keys are declared.
  34.  */
  35.  
  36. public class User extends Hashtable implements Saveable
  37. {
  38.     public static Integer ID=new Integer(0);
  39.     public static Integer NAME=new Integer(1);
  40.     public static Integer FACE=new Integer(2);
  41.     public static Integer ADDRESS=new Integer(3);
  42.     public static Integer EMAIL=new Integer(4);
  43.     public static Integer NOTES=new Integer(5);
  44.     public static Integer PRIMHOST=new Integer(6);
  45.     public static Integer SOCKET=new Integer(7);
  46.     public static Integer NICK=new Integer(8);
  47.     public static Integer COLOR=new Integer(9);
  48.     public static Integer COMOUSER=new Integer(10);
  49.     public static Integer COMMENT=new Integer(11);
  50.     public static Integer LOCATION=new Integer(12);
  51.     public static Integer SCORE=new Integer(13);
  52.  
  53.     /**
  54.      * Contructor for User.
  55.      */
  56.     public User() {
  57.     }
  58.  
  59.     /**
  60.      * Contructor for User.
  61.      * @param id the user's ID.
  62.      * @param name the user's name.
  63.      */
  64.     public User(int id,String name)
  65.     {
  66.         put(ID,new Integer(id));
  67.         put(NAME,name);
  68.     }
  69.  
  70.     /**
  71.      * Return the user's ID.
  72.      * @return ID
  73.      */
  74.     public int getID() {
  75.         if (containsKey(ID)) return ((Integer)get(ID)).intValue();
  76.         else return -1;
  77.     }
  78.  
  79.     /**
  80.      * Return the user's name.
  81.      * @return the name.
  82.      */
  83.     public String getName() {
  84.         if (containsKey(NAME)) return (String)get(NAME);
  85.         else return "Unknown User #"+getID();
  86.     }
  87.  
  88.     /**
  89.      * Saves this Object to the ObjectOutputStream s.
  90.      * @param s the ObjectOutputStream.
  91.      */
  92.     public void save(ObjectOutputStream s) throws IOException{
  93.         Hashtable h = new Hashtable();
  94.         Enumeration e = keys();
  95.         while (e.hasMoreElements()) {
  96.             Object k = e.nextElement();
  97.             h.put(k,get(k));
  98.         }
  99.  
  100.         s.writeObject(h);
  101.     }
  102.  
  103.     /**
  104.      * Load this Object from the ObjectInputStream s.
  105.      * @param s the ObjectOutputStream.
  106.      */
  107.     public void load(ObjectInputStream s) throws IOException{
  108.         clear();
  109.         Hashtable h = (Hashtable)s.readObject();
  110.         Enumeration e = h.keys();
  111.         while (e.hasMoreElements()) {
  112.             Object k = e.nextElement();
  113.             put(k,h.get(k));
  114.         }
  115.     }
  116. }
  117.