Answered step by step
Verified Expert Solution
Link Copied!

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).
1 Read all records (lines) from the flat file into a list of records.
2 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.
3 Create a new record by encoding a new row composed of the key parameter and the list of fields parameter.
4 Linear search the rows decoded from the list of records to find an old row with the given key, skipping the header.
5 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.
6 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.
7 The steps above implement the move-to-front heuristic.
N A public get method which takes a key parameter.
1 Read all records (lines) from the flat file into a list of records.
2 Linear search the rows decoded from the list of records to find an old row with the given key, skipping the header.
3 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.
4 On a miss, return null.
5 The steps above implement the move-to-front heuristic.
O A public remove method which takes a key parameter.
1 Read all records (lines) from the flat file into a list of records.
2 Linear search the rows decoded from the list of records to find an old row with the given key, skipping the header.
3 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.
4 On a miss, return null.
page 3/3
4TH QUARTER: ITERATOR, FACTORY METHOD
P A public iterator method which returns an iterator of rows.
1 Create a list of the rows decoded from all records in the flat file, excluding the header.
2 Call iterator on that list and return the corresponding iterator.
3 Dont implement a new iterator using an anonymous class (unlike in previous modules).
Q A public toString method.
1 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).
1 Create the base directories, if needed.
2 Create a path to a new file by resolving the given name plus the .csv extension relative to the base directories.
3 If the new file doesnt exist at the resolved path, create it.
4 Write the given text to the new file. The text is a multiline string containing a CSV header and records.
5 Return a new CSV table by calling the 1-ary constructor and passing it the given name.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions