Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA For testing and debugging purposes, the static methods in steps H to K below can be public instead of private. H A private

IN JAVA 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.
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.
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

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

2. Identify conflict triggers in yourself and others

Answered: 1 week ago