Class Disk

java.lang.Object
org.grp1.storage.Disk

public class Disk extends Object
  • Field Details

    • diskSize

      private final int diskSize
      Represents the disk size
    • blockSize

      private final int blockSize
      Represents the block size
    • recordSize

      private final int recordSize
      Represents the record size
    • blocks

      private final Block[] blocks
      Represents the block inside a disk
    • accessCount

      private int accessCount
      Represents the access count of the disk
    • numOfRecord

      private int numOfRecord
      Represents the number of record inside this disk
  • Constructor Details

    • Disk

      public Disk(int diskSize, int blockSize, int recordSize)
      The construcotr to instantiate the disk
      Parameters:
      diskSize - The disk size
      blockSize - The block size
      recordSize - The record size
  • Method Details

    • insertRecord

      public void insertRecord(Record r) throws DiskFullException
      The function to insert the record
      Parameters:
      r - The record to be inserted
      Throws:
      DiskFullException
    • getRecordByPointer

      public Record getRecordByPointer(Address pointer)
      The function to get the record by a pointer
      Parameters:
      pointer - The pointer of the record
      Returns:
      The record corresponding to the address
    • getRecordsByNumVotes

      public List<Record> getRecordsByNumVotes(int numVotes)
      The function to get the records by numVotes
      Parameters:
      numVotes - The number of votes for the records
      Returns:
      The records that match this number of votes
    • getRecordsByNumVotes

      public List<Record> getRecordsByNumVotes(int lower, int upper)
      The function to get the records by range of number of votes
      Parameters:
      lower - The lower bound of number of votes for the records
      upper - The upper bound of number of votes for the records
    • deleteRecordsByNumVotes

      public void deleteRecordsByNumVotes(int numVotes) throws InvalidIndexException
      The function to delete the records by number of votes
      Parameters:
      numVotes - The number of votes
      Throws:
      InvalidIndexException
    • getRecords

      public List<Record> getRecords()
      The function to return the records inside the disk
      Returns:
      The records inside the disk
    • getMaxNumberOfRecordsInBlock

      private int getMaxNumberOfRecordsInBlock()
      The function to return the number of records inside a block
      Returns:
      The number of records inside a block
    • printDiskInformation

      public void printDiskInformation()
      The function to print the disk information
    • getNumberOfRecords

      public int getNumberOfRecords()
      The function to return the number of records inside a disk
      Returns:
      The number of records inside a disk
    • getNumberOfBlocks

      public int getNumberOfBlocks()
      The function to return the number of blocks inside a disk
      Returns:
      The number of blocks inside a disk
    • getBlock

      public Block getBlock(int index)
      The function to return the block based on the index
      Parameters:
      index - The index of a block
      Returns:
      The block corresponding to the index
    • getOccupiedBlock

      public int getOccupiedBlock()
      The function to return the index of an occupied block
      Returns:
      The index of an occupied block
    • getAccessCount

      public int getAccessCount()
      The function to return the number of access count of a disk
      Returns:
      The access count of a disk