home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 25 / IOPROG_25.ISO / SOFT / JavaS / javastar-eval.exe / data1.cab / Program_Files / examples / namedb3 / RoloEntry.java < prev    next >
Encoding:
Java Source  |  1999-02-11  |  3.5 KB  |  130 lines

  1. /* ****************************************************************
  2. ** @(#)RoloEntry.java    1.2 97/02/24
  3. **
  4. ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
  5. **
  6. ** ****************************************************************
  7. */
  8.  
  9. import java.util.*;
  10. import java.io.*;
  11.  
  12. /* RoloEntry contains data structure for NameDB application
  13. ** stores name,address1,address2,phone,email,other
  14. */
  15.  
  16. public class RoloEntry implements Listable {
  17.    public String name;
  18.    public String address1;
  19.    public String address2;
  20.    public String phone;
  21.    public String email;
  22.    public String other;
  23.  
  24.   public static RoloEntry roloobj = new RoloEntry();
  25.  
  26.   public RoloEntry(String name,String address1,String address2,String phone,
  27.            String email,String other) {
  28.     this.name=name;
  29.     this.address1=address1;
  30.     this.address2=address2;
  31.     this.phone=phone;
  32.     this.email=email;
  33.     this.other=other;
  34.   }
  35.   public RoloEntry() {
  36.      this("","","","","","");
  37.    }
  38.  
  39.    public Listable read_from_file(DataInputStream din) {
  40.  
  41.       // Read one rolo entry from file passed in. 
  42.       // We assume file pointer is at beginning of record in file.
  43.       // Populate object member vars with values read in.
  44.       // Assume one line per field.
  45.       RoloEntry re = new RoloEntry();
  46.       String s = new String("");
  47.  
  48.       try {
  49.      s = din.readLine(); 
  50.          if (s!=null)
  51.         re.name = new String(s); 
  52.  
  53.      s = din.readLine(); 
  54.          if (s!=null)   re.address1    = new String(s);
  55.  
  56.      s = din.readLine(); 
  57.      if (s!=null)   re.address2 = new String(s); 
  58.  
  59.      s = din.readLine(); 
  60.          if (s!=null)   re.phone = new String(s); 
  61.  
  62.      s = din.readLine(); 
  63.          if (s!=null)   re.email = new String(s); 
  64.  
  65.      s = din.readLine(); 
  66.          if (s!=null)   re.other = new String(s); 
  67.      if (s==null) return null;
  68.       }
  69.  
  70.       catch (IOException e) {
  71.          System.out.println("msg" + e.getMessage());
  72.       }
  73.  
  74.       return re;
  75.    }
  76.  
  77.    public void write_to_file(PrintStream pout){
  78.       // Write one rolo entry to file passed in.
  79.       // We assume file pointer is correctly positioned
  80.       // Write out one object member var per line
  81.          pout.println(name);
  82.          pout.println(address1);
  83.          pout.println(address2);
  84.          pout.println(phone);
  85.          pout.println(email);
  86.          pout.println(other);
  87.    }
  88.  
  89.    public String getKey() {
  90.       return name;
  91.    }
  92.  
  93.    public boolean equals(RoloEntry other_rolo) {
  94.       // Returns true if key values match, false otherwise.
  95.  
  96.       return name.equals(other_rolo.getKey());
  97.    }
  98.  
  99.    public void print() {
  100.       System.out.println(name);
  101.       System.out.println(address1);
  102.       System.out.println(address2);
  103.       System.out.println(phone);
  104.       System.out.println(email);
  105.       System.out.println(other);
  106.    }
  107.  
  108.    public Object clone() {
  109.       // Return a clone of the current object
  110.  
  111.       RoloEntry theClone = new RoloEntry();
  112.       theClone.name       = new String(name);
  113.       theClone.address1   = new String(address1);
  114.       theClone.address2   = new String(address2);
  115.       theClone.phone      = new String(phone);
  116.       theClone.email      = new String(email);
  117.       theClone.other      = new String(other);
  118.       return (Object)theClone;
  119.    }
  120.  
  121.    public void clear() {
  122.       name = new String("");
  123.       address1 = new String("");
  124.       address2 = new String("");
  125.       phone    = new String("");
  126.       email    = new String("");
  127.       other    = new String("");
  128.    }
  129. }
  130.