Package org.grp1.storage
Class Disk
java.lang.Object
org.grp1.storage.Disk
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intRepresents the access count of the diskprivate final Block[]Represents the block inside a diskprivate final intRepresents the block sizeprivate final intRepresents the disk sizeprivate intRepresents the number of record inside this diskprivate final intRepresents the record size -
Constructor Summary
ConstructorsConstructorDescriptionDisk(int diskSize, int blockSize, int recordSize) The construcotr to instantiate the disk -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteRecordsByNumVotes(int numVotes) The function to delete the records by number of votesintThe function to return the number of access count of a diskgetBlock(int index) The function to return the block based on the indexprivate intThe function to return the number of records inside a blockintThe function to return the number of blocks inside a diskintThe function to return the number of records inside a diskintThe function to return the index of an occupied blockgetRecordByPointer(Address pointer) The function to get the record by a pointerThe function to return the records inside the diskgetRecordsByNumVotes(int numVotes) The function to get the records by numVotesgetRecordsByNumVotes(int lower, int upper) The function to get the records by range of number of votesvoidThe function to insert the recordvoidThe function to print the disk information
-
Field Details
-
diskSize
private final int diskSizeRepresents the disk size -
blockSize
private final int blockSizeRepresents the block size -
recordSize
private final int recordSizeRepresents the record size -
blocks
Represents the block inside a disk -
accessCount
private int accessCountRepresents the access count of the disk -
numOfRecord
private int numOfRecordRepresents 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 sizeblockSize- The block sizerecordSize- The record size
-
-
Method Details
-
insertRecord
The function to insert the record- Parameters:
r- The record to be inserted- Throws:
DiskFullException
-
getRecordByPointer
The function to get the record by a pointer- Parameters:
pointer- The pointer of the record- Returns:
- The record corresponding to the address
-
getRecordsByNumVotes
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
The function to get the records by range of number of votes- Parameters:
lower- The lower bound of number of votes for the recordsupper- The upper bound of number of votes for the records
-
deleteRecordsByNumVotes
The function to delete the records by number of votes- Parameters:
numVotes- The number of votes- Throws:
InvalidIndexException
-
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
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
-