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

  1. package como.irc;
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.IOException;
  6. import como.io.*;
  7.  
  8. public class IrcChan implements Saveable {
  9.     String channel; // mit como234252_
  10.     String commletname;
  11.     String topic;
  12.  
  13.     public IrcChan() {
  14.         channel = commletname = topic = "Unknown";
  15.     }
  16.  
  17.     public IrcChan( String ch, String co, String to  ) {
  18.         channel = ch;
  19.         commletname = co;
  20.         topic = to;
  21.     }
  22.     
  23.     public IrcChan( String comname, String t ) {
  24.         // Create a new unused channel-name.
  25.         // TODO: 
  26.         // attention two users may creat the same channel
  27.         // if they click at the very same time!!!
  28.         // But is this really realistic???
  29.         // Even if yes, it should work quand meme.
  30.         
  31.         channel = "como"+(new Date()).getTime();
  32.         commletname = comname;
  33.  
  34.         topic = t; 
  35.     }
  36.  
  37.     public String ircName() {
  38.        return channel+"~"+commletname;
  39.     }
  40.     
  41.     public String toString() {
  42.        return channel+"~"+commletname+"~"+topic;
  43.     }
  44.  
  45.     public void save( ObjectOutputStream o ) throws IOException {
  46.         o.writeString( channel );
  47.         o.writeString( commletname );
  48.         o.writeString( topic );
  49.     }
  50.  
  51.     public void load( ObjectInputStream i ) throws IOException {
  52.         channel     = i.readString();
  53.         commletname = i.readString();
  54.         topic       = i.readString();
  55.     }
  56.     
  57.     public void fromString( String s ) {
  58.         StringTokenizer st = new StringTokenizer( s, "~" );
  59.         
  60.         try {
  61.             channel = st.nextToken();
  62.             commletname = st.nextToken();
  63.             topic = st.nextToken();
  64.         } catch( NoSuchElementException e ) {
  65.             // means no topic was set!
  66.             // -> keep cool here.
  67.             topic = "Unkown";
  68.         }
  69.     }
  70. }
  71.