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 |
Constructor and Description |
---|
LengthComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(NewsStory newsStory1,
NewsStory newsStory2)
Overridden compare method that looks at the lengths of the news stories
in words.
|
public static final LengthComparator LENGTH_COMPARATOR
public int compare(NewsStory newsStory1, NewsStory newsStory2)
compare
in interface java.util.Comparator<NewsStory>
newsStory1
- The first news story to compare by length.newsStory2
- The second news story to compare by length.