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. B The following private fields: 1 A static
For all files and paths, use the Files and Paths APIs from the java.nio.file package when possible.
B The following private fields:
A static constant path for the base directories, which are db sub tables relative to the project directory.
A path for the flat file, which is the table file structure in CSV format.
No fields for the degree, size, fingerprint, or any other fields unlike in previous modules
C A ary constructor which takes a name parameter string and a columns parameter list of strings
Create the base directories, if needed.
Initialize the path field by resolving the given name plus the csv extension relative to the base directories.
If the flat file doesnt exist at the path field, create it
Join the columns parameter into a header record line using commas Dont use quotation marks.
Create a list of records list of lines with the header as its only record.
Write the list of records to the flat file.
D A ary constructor which takes a name parameter string only.
Initialize the path field by resolving the given name plus the csv extension relative to the base directories.
If the flat file doesnt exist at the path field, throw an illegal argument exception.
E A public clear method.
Read all records lines from the flat file into a list of records.
Clear all records from the list of records, retaining only the header.
Write the modified list of records to the flat file.
F Public methods for the following properties:
The name method which returns the name of the flat file, excluding the base directories and the csv extension.
The columns method which returns the columns stored in the header of the flat file split using commas
The degree method which returns the size of the list of columns which is returned by the columns method.
The size method which returns the number of records lines in the flat file, excluding the header.
The equals method which returns true if the parameter is any table with the same fingerprint as in previous modules
Dont implement capacity or loadFactor, because this is a FileTable, not a DataTable.
ND QUARTER: CSV DESERIALIZATION
G For testing and debugging purposes, the static methods in steps H to K below can be public instead of private.
H A private static encodeField method which takes an object parameter and encodes it as a field string
If the given object is a null reference, return a string containing the literal word null.
If it is a string, return it between literal quotation marks thus characters longer.
If it is a boolean, integer, or floating point number double return it converted to a string.
Otherwise, throw an illegal argument exception and pass it the message that the given object is unsupported.
This step H is the functional inverse of step I below.
I A private static decodeField method which takes a field parameter string and decodes it as an object.
If the given field is the literal word null or any case variant, return a null reference.
If it starts and ends with literal quotation marks return the substring between the marks, thus characters shorter.
If it is the literal word true or false or any case variant, return the corresponding boolean true or false.
If it can be parsed as an integer, return the corresponding integer.
If it can be parsed as a floating point number double return the corresponding number.
Otherwise, throw an illegal argument exception and pass it the message that the given field is unrecognized.
This step I is the functional inverse of step H above.
page
J A private static encodeRow method which takes a row parameter and encodes it as a record string
Create a string joiner with a comma as its delimiter.
Encode the key of the given row as a field using encodeField, and add it to the string joiner.
For each field in the list of fields of the given row in order, encode it using encodeField, and add it to the string joiner.
Return the string joiner converted to a string.
This step J is the functional inverse of step K below.
K A private static decodeRow method which takes a record parameter string and decodes it as a row.
Split the record on commas into a sequence of fields.
Strip the first field of whitespace and decode it as a key using decodeField.
Create a new list of fields. For each remaining field in the sequence, strip it decode it using decodeField, and add it to
the list of fields.
Return a new row composed of the key and list of fields.
This step K is the functional inverse of step J above.
L Public methods for the following properties:
The hashCode method fingerprint which returns the sum of the hash codes of the rows decoded from the records in
the flat file, excluding the header.
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