Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

Are the investments going to be supported by the stakeholders?

Answered: 1 week ago