public class LengthComparator extends java.lang.Object implements java.util.Comparator<NewsStory>
The LengthComparator compares the lengths of two news stories. Since different types of news stories may use different units to measure their lengths, we compare by converting the lengths to a common unit (words).
Note that the constructor has nothing to do, so it is omitted.
Modifier and Type | Field and Description |
---|---|
static LengthComparator |
LENGTH_COMPARATOR
We create a single comparator object for the class and make a public
final field that references that object.
|
Constructor and Description |
---|
LengthComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(NewsStory newsStory1,
NewsStory newsStory2)
The required
compare method for implementing
Comparator . |
public static final LengthComparator LENGTH_COMPARATOR
public int compare(NewsStory newsStory1, NewsStory newsStory2)
compare
method for implementing
Comparator
.compare
in interface java.util.Comparator<NewsStory>
newsStory1
- The first news story to compare based on length.newsStory2
- The second news story to compare based on length.