abstract class NewsStory extends java.lang.Object implements java.lang.Comparable<NewsStory>, java.io.Serializable
A NewsStory
is composed of the date the story was published, the
name of the source (such as newspaper or TV news program) where the story was
published, the length the story (in words for written stories; in seconds for
spoken news), the broad topic for the story, the specific subject matter of
the story, and two lead news makers in the story.
Modifier and Type | Field and Description |
---|---|
private java.time.LocalDate |
date
The date the story was published/broadcast as a
java.time.LocalDate . |
private int |
length
The length of the story.
|
private NewsMaker |
newsMaker1
The first news maker featured in the story.
|
private NewsMaker |
newsMaker2
The second news maker featured in the story.
|
private static long |
serialVersionUID
This is the first serializable version of NewsStory, so we select a
serialVersionUID of 1L.
|
private java.lang.String |
source
The name of the source in which the story was published.
|
private java.lang.String |
subject
The specific subject matter of the story.
|
private java.lang.String |
topic
The broad topic of the story.
|
Modifier | Constructor and Description |
---|---|
protected |
NewsStory(java.time.LocalDate date,
java.lang.String source,
int length,
java.lang.String topic,
java.lang.String subject,
NewsMaker newsMaker1,
NewsMaker newsMaker2)
The constructor for the class which takes objects of appropriate types to
initialize all of the fields.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(NewsStory newsStory)
Overridden
compareTo method to allow for sorting. |
boolean |
equals(java.lang.Object o)
Overridden
equals method considers equality of contents
rather than memory locations. |
java.time.LocalDate |
getDate()
The accessor for the date field.
|
int |
getLength()
The accessor for the length field.
|
abstract int |
getLengthInWords()
The accessor for length equivalent in words.
|
NewsMaker |
getNewsMaker1()
The accessor for the first news maker field.
|
NewsMaker |
getNewsMaker2()
The accessor for the second news maker field.
|
java.lang.String |
getSource()
The accessor for the source name field.
|
java.lang.String |
getSubject()
The accessor for the subject field.
|
java.lang.String |
getTopic()
The accessor for the topic field.
|
private static final long serialVersionUID
private java.time.LocalDate date
java.time.LocalDate
.private java.lang.String source
private int length
private java.lang.String topic
private java.lang.String subject
private NewsMaker newsMaker1
private NewsMaker newsMaker2
protected NewsStory(java.time.LocalDate date, java.lang.String source, int length, java.lang.String topic, java.lang.String subject, NewsMaker newsMaker1, NewsMaker newsMaker2)
Note that in the length a story cannot be negative, so our class should model that fact. However, to keep the project relatively simple, this requirement was not made in the project description and this check doesn't need to be made yet.
date
- The date the story was published as a java.time.LocalDate.source
- The name of the source in which the story was published.length
- The length of the story.topic
- The broad topic of the story.subject
- The specific subject matter of the story.newsMaker1
- The first news maker featured in the story.newsMaker2
- The second news maker featured in the story.public java.time.LocalDate getDate()
Note that LocalDate
objects are immutable, so it is fine to
return the field itself.
public java.lang.String getSource()
Note that String
objects are immutable, so it is fine to
return the field itself.
public int getLength()
Note that int
s are passed by value, so it is fine to return
the field itself.
public abstract int getLengthInWords()
This accessor for length allows both newspaper stories and TV news stories to be compared on the same basis: words. Since newspaper stories already have their length measured in words, for newspaper stories, we can simply return their length. For TV news stories, though, the measured value is duration in minutes, so we need to convert this to an approximate number of words before returning it.
Note that the description above assumes we only have two subclasses, one for newspaper stories and one for TV news stories. However, this class should be flexible enough to allow for other types of news stories to be created as subclasses.
public java.lang.String getTopic()
Note that String
objects are immutable, so it is fine to
return the field itself.
public java.lang.String getSubject()
Note that String
objects are immutable, so it is fine to
return the field itself.
public NewsMaker getNewsMaker1()
Note that NewsMaker
objects are mutable, so this really
should return a copy of the news maker instead. However, we haven't
studied that yet, so returning the news maker itself is acceptable for
now.
public NewsMaker getNewsMaker2()
Note that NewsMaker
objects are mutable, so this really
should return a copy of the news maker instead. However, we haven't
studied that yet, so returning the news maker itself is acceptable for
now.
public boolean equals(java.lang.Object o)
equals
method considers equality of contents
rather than memory locations.
Note that we compare all fields of news story but that
equals
for the news makers themselves does not compare their
news story lists.
equals
in class java.lang.Object
o
- The object to which to compare this.