View Javadoc

1   package simpledb.file;
2   
3   /**
4    * A reference to a disk block.
5    * A Block object consists of a filename and a block number.
6    * It does not hold the contents of the block;
7    * instead, that is the job of a {@link Page} object.
8    * @author Edward Sciore
9    */
10  public class Block {
11     private String filename;
12     private int blknum;
13     
14     /**
15      * Constructs a block reference 
16      * for the specified filename and block number.
17      * @param filename the name of the file
18      * @param blknum the block number
19      */
20     public Block(String filename, int blknum) {
21        this.filename = filename;
22        this.blknum   = blknum;
23     }
24     
25     /**
26      * Returns the name of the file where the block lives.
27      * @return the filename
28      */
29     public String fileName() {
30        return filename;
31     }
32     
33     /**
34      * Returns the location of the block within the file.
35      * @return the block number
36      */
37     public int number() {
38        return blknum;
39     }
40     
41     public boolean equals(Object obj) {
42        Block blk = (Block) obj;
43        return filename.equals(blk.filename) && blknum == blk.blknum;
44     }
45     
46     public String toString() {
47        return "[file " + filename + ", block " + blknum + "]";
48     }
49     
50     public int hashCode() {
51        return toString().hashCode();
52     }
53  }