home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / commlet / scheduler / userschedule.java < prev   
Encoding:
Java Source  |  1996-08-14  |  2.0 KB  |  102 lines

  1. package como.commlet.scheduler;
  2.  
  3. import como.sys.*;
  4. import como.io.*;
  5. import como.util.*;
  6. import java.io.*;
  7.  
  8. public class UserSchedule implements Saveable {
  9.     static final int WEEK_DAYS = 7;
  10.     static final int MIN_HOUR = 8;
  11.     static final int MAX_HOUR = 22;
  12.     static final int NR_HOURS = MAX_HOUR - MIN_HOUR + 1;
  13.  
  14.     static final byte ME_OK = 1;
  15.     static final byte ME_WHYNOT = 0;
  16.     static final byte ME_NO = -1;
  17.  
  18.     static final int BAD_FITNESS = -2;
  19.  
  20.     byte schedule[][];
  21.  
  22.     public UserSchedule() {
  23.         // make the board a one bigger in each direction
  24.         // needed, because of the scalas.
  25.         schedule = new byte[WEEK_DAYS+1][NR_HOURS+1];
  26.         clear();
  27.     }
  28.  
  29.     public void clear() {
  30.         set( ME_WHYNOT );
  31.     }
  32.  
  33.     public void clickThrough( int x, int y ) {
  34.         byte how = get( x, y );
  35.  
  36.         how++;
  37.  
  38.         if( how > ME_OK )
  39.             how = ME_NO;
  40.  
  41.         set( x, y, how );
  42.     }
  43.  
  44.     public void set( byte how ) {
  45.         for( int x = 0; x <= WEEK_DAYS; x++ ) {
  46.             for( int y = 0; y <= NR_HOURS; y++ ) {
  47.                 set( x, y, how );
  48.             }
  49.         }
  50.     }
  51.  
  52.     synchronized public void setCol( int x, byte how ) {
  53.         for( int y = 0; y <= NR_HOURS; y++ ) {
  54.             set( x, y, how );
  55.         }
  56.     }
  57.  
  58.     synchronized public void setRow( int y, byte how ) {
  59.         for( int x = 0; x <= WEEK_DAYS; x++ ) {
  60.             set( x, y, how );
  61.         }
  62.     }
  63.  
  64.     synchronized public void set( int x, int y, byte how ) {
  65.         schedule[x][y] = how;
  66.     }
  67.  
  68.     synchronized public byte get( int x, int y ) {
  69.         return schedule[x][y];
  70.     }
  71.  
  72.     int fitness( int x, int y ) {
  73.         switch( get( x, y ) )
  74.         {
  75.             case ME_NO:
  76.                 return BAD_FITNESS;
  77.  
  78.             default:
  79.                 return (int)get( x, y );
  80.         }
  81.     }
  82.  
  83.     int getMaxFitness() {
  84.         return (int)ME_OK;
  85.     }
  86.  
  87.     synchronized public void save( ObjectOutputStream s ) throws IOException {
  88.         for( int x = 0; x <= WEEK_DAYS; x++ )
  89.             s.writeObject( schedule[x] );
  90.     }
  91.  
  92.     synchronized public void load( ObjectInputStream s ) throws IOException {
  93.         for( int x = 0; x <= WEEK_DAYS; x++ )
  94.         {
  95.             schedule[x] = (byte[])s.readObject();
  96.  
  97.             if( schedule[x].length != NR_HOURS+1 )
  98.                 Debug.msg( 80, "UserSchedule.load(): schedule loaded has wrong size." );
  99.         }
  100.     }
  101. }
  102.