Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For all files and paths, use the Files and Paths APIs from the java.nio.file package when possible. A public clear method. 1 Walk the data
For all files and paths, use the Files and Paths APIs from the java.nio.file package when possible. A public clear method.
Walk the data directory by streaming as follows:
i Skip the first path in the stream, which is itself being walked and shouldnt be deleted.
ii Sort the stream in reverse order, which streams from the lowest files to the highest directories.
iii For each path in the stream, delete the corresponding file or directory.
Call writeInt to the size file under the metadata directory.
Call writeInt to the fingerprint file under the metadata directory.
N Public methods for the following statistics and predicates:
The name method which returns the name of the table root, excluding the base directories without an extension
The columns method which returns the lines list of strings read from the columns file under the metadata directory.
The degree method which returns the size of the list of columns which is returned by the columns method.
The size method which returns readInt from the size file under the metadata directory.
The hashCode method which returns readInt from the fingerprint file under the metadata directory.
Dont implement capacity or loadFactor, because this is a FileTable, not a DataTable.
The equals method which returns true if the parameter is any table with the same fingerprint as in previous modules
O A public put method which takes a key parameter string then a list of fields parameter list of objects
If the degree of the given row doesnt match the result of calling the degree method, throw an illegal argument exception.
Find the path of the digest of the given key calling steps K and L in order
Create a new row composed of the key parameter and the list of fields parameter.
Check if a file exists at the path of the digest to determine a hit or a miss.
On a hit, readRow from the path of the old row, writeRow to the path with the new row, writeInt to the fingerprint
path under the metadata directory to update it like in previous modules and return the old list of fields.
On a miss, writeRow to the path with the new row, writeInt to the size and fingerprint paths under the metadata
directory to update them like in previous modules and return null.
P A public get method which takes a key parameter.
Find the path of the digest of the key equal to the given object calling steps K and L in order
Check if a file exists at the path of the digest to determine a hit or a miss.
On a hit, readRow from the path of the old row, and return the old list of fields.
On a miss, return null.
Q A public remove method which takes a key parameter.
Find the path of the digest of the key equal to the given object calling steps K and L in order
Check if a file exists at the path of the digest to determine a hit or a miss.
On a hit, readRow from the path of the old row, deleteRow at the same path, writeInt to the size and fingerprint
paths under the metadata directory to update them like in previous modules and return the old list of fields.
On a miss, return null.
R A public iterator method which returns an iterator of rows.
Walk the data directory by streaming as follows:
i Filter the stream to include only files which arent directories.
ii Map each path in the stream to the row stored there using readRow.
Return the iterator from the stream.
S A public toString method.
Return an unsorted view of the table by calling toTabularView.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started