omplete hat represents veight. 1ou must impi which supports comparing terms by three different orders: lexicographic order á by query string (the natural order); in descending order by weight (an alternate order); and lexicographic order by query string but using only the first r characters (a family of alternate orderings). The last order may seem a bit odd, but you will use it in Part 3 t (of length r). find all query strings that start with a given prefix

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Part 1: autocomplete term. Write an immutable data type Term.java that represents an autocomplete term-a query string and an associated integer weight. You must implement the following API,
which supports comparing terms by three different orders: lexicographic order by query string (the natural order); in descending order by weight (an alternate order); and lexicographic order by
query string but using only the first r characters (a family of alternate orderings). The last order may seem a bit odd, but you will use it in Part 3 to find all query strings that start with a given prefix
(of length r).
public class Term implements Comparable<Term> {
// Initializes a term with the given query string and weight.
public Term (String query, long weight)
// Compares the two terms in descending order by weight.
public static Comparator<Term> byReverseWeight0rder ()
// Compares the two terms in lexicographic order,
// but using only the first r characters of each query.
public static Comparator<Term> byPrefixOrder (int r)
// Compares the two terms in lexicographic order by query.
public int compareTo(Term that)
// Returns a string representation of this term in the following format:
// the weight, followed by a tab, followed by the query.
public String tostring ()
// unit testing (required)
public static void main (String[] args)
}
Corner cases. Throw an 1llegalArgumentException in the constructor if either query is null or weight is negative. Throw an 1llegalArgumentException in byPrefixOrder () if r is negative.
Unit testing. Your main () method must call each public constructor and method directly and help verify that they work as prescribed (e.g., by printing results to standard output).
Performance requirements. The string comparison functions must take time proportional to the number of characters needed to resolve the comparison.
Transcribed Image Text:Part 1: autocomplete term. Write an immutable data type Term.java that represents an autocomplete term-a query string and an associated integer weight. You must implement the following API, which supports comparing terms by three different orders: lexicographic order by query string (the natural order); in descending order by weight (an alternate order); and lexicographic order by query string but using only the first r characters (a family of alternate orderings). The last order may seem a bit odd, but you will use it in Part 3 to find all query strings that start with a given prefix (of length r). public class Term implements Comparable<Term> { // Initializes a term with the given query string and weight. public Term (String query, long weight) // Compares the two terms in descending order by weight. public static Comparator<Term> byReverseWeight0rder () // Compares the two terms in lexicographic order, // but using only the first r characters of each query. public static Comparator<Term> byPrefixOrder (int r) // Compares the two terms in lexicographic order by query. public int compareTo(Term that) // Returns a string representation of this term in the following format: // the weight, followed by a tab, followed by the query. public String tostring () // unit testing (required) public static void main (String[] args) } Corner cases. Throw an 1llegalArgumentException in the constructor if either query is null or weight is negative. Throw an 1llegalArgumentException in byPrefixOrder () if r is negative. Unit testing. Your main () method must call each public constructor and method directly and help verify that they work as prescribed (e.g., by printing results to standard output). Performance requirements. The string comparison functions must take time proportional to the number of characters needed to resolve the comparison.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education