Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A public put method which takes a key parameter ( string ) , then a list of fields parameter ( list of objects ) .
A public put method which takes a key parameter string then a list of fields parameter list of objects
Read all records lines from the flat file into a list of records.
If the degree of the given row doesnt match the size of the header in the list of records split using commas throw an
illegal argument exception. Dont call the degree method.
Create a new record by encoding a new row composed of the key parameter and the list of fields parameter.
Linear search the rows decoded from the list of records to find an old row with the given key, skipping the header.
On a hit, remove the old record from its index within the list of records, prepend the new record to the list of records but
still after the header, write the modified list of records to the flat file, then return the old list of fields.
On a miss, prepend the new record to the list of records but still after the header, write the modified list of records to the
flat file, then return null.
The steps above implement the movetofront heuristic.
N A public get method which takes a key parameter.
Read all records lines from the flat file into a list of records.
Linear search the rows decoded from the list of records to find an old row with the given key, skipping the header.
On a hit, remove the old record from its index within the list of records, prepend the old record to the list of records but
still after the header, write the modified list of records to the flat file, then return the old list of fields.
On a miss, return null.
The steps above implement the movetofront heuristic.
O A public remove method which takes a key parameter.
Read all records lines from the flat file into a list of records.
Linear search the rows decoded from the list of records to find an old row with the given key, skipping the header.
On a hit, remove the old record from its index within the list of records, write the modified list of records to the flat file,
then return the old list of fields.
On a miss, return null.
page
TH QUARTER: ITERATOR, FACTORY METHOD
P A public iterator method which returns an iterator of rows.
Create a list of the rows decoded from all records in the flat file, excluding the header.
Call iterator on that list and return the corresponding iterator.
Dont implement a new iterator using an anonymous class unlike in previous modules
Q A public toString method.
Return a sorted view of the table by calling toTabularView.
R A public static factory method fromText which takes a name parameter string then a text parameter string
Create the base directories, if needed.
Create a path to a new file by resolving the given name plus the csv extension relative to the base directories.
If the new file doesnt exist at the resolved path, create it
Write the given text to the new file. The text is a multiline string containing a CSV header and records.
Return a new CSV table by calling the ary constructor and passing it the given name.
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