Java 2 Programming and Auto Complete Task
I’m working on a java question and need guidance to help me understand better.
Is about autocomplete, 3 small classes need to be done
Class 1
public
class
Term
implements
Comparable<Term>
{
/**
* Initialize a term with the given query and weight.
* This method throws a NullPointerException if query is null,
* and an IllegalArgumentException if weight is negative.
*/public
Term(String
query
,
long
weight
)
{
}
/**
* Compares the two terms in descending order of weight.
*/public
static
Comparator<Term>
byDescendingWeightOrder()
{
}
/**
* Compares the two terms in ascending lexicographic order of query,
* but using only the first length characters of query. This method
* throws an IllegalArgumentException if length is less than or equal
* to zero.
*/public
static
Comparator<Term>
byPrefixOrder(int
length
)
{
}
/**
* Compares this term with the other term in ascending lexicographic order
* of query.
*/@Override
public
int
compareTo(Term
other
)
{
}
/**
* Returns a string representation of this term in the following format:
* query followed by a tab followed by weight
*/@Override
public
String
toString(){
}
}
Class 2
public
class
BinarySearch
{
/**
* Returns the index of the first key in a[] that equals the search key,
* or -1 if no such key exists. This method throws a NullPointerException
* if any parameter is null.
*/public
static
<Key>
int
firstIndexOf(Key[]
a
,
Key
key
,
Comparator<Key>
comparator
)
{
}
/**
* Returns the index of the last key in a[] that equals the search key,
* or -1 if no such key exists. This method throws a NullPointerException
* if any parameter is null.
*/public
static
<Key>
int
lastIndexOf(Key[]
a
,
Key
key
,
Comparator<Key>
comparator
)
{
}
Class 3
public
class
Autocomplete
{
/**
* Initializes a data structure from the given array of terms.
* This method throws a NullPointerException if terms is null.
*/public
Autocomplete(Term[]
terms
)
{
}
/**
* Returns all terms that start with the given prefix, in descending order of weight.
* This method throws a NullPointerException if prefix is null.
*/public
Term[]
allMatches(String
prefix
)
{
}
}