class NewsMaker extends java.lang.Object implements java.lang.Comparable<NewsMaker>
A NewsMaker
is the subject of a NewsStory
. A
NewsMaker
may be a person or an organization. A
NewsMaker
consists of a name and a collection of news stories
that feature that NewsMaker
. There is a special
NewsMaker
with the name "None" that is used for news stories
that don't have at least two named NewsMakers
.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
name
The name of the news maker.
|
private NewsStoryList |
newsStories
The list of news stories in which the news maker is featured
|
Constructor and Description |
---|
NewsMaker()
The no-argument constructor for the class.
|
NewsMaker(java.lang.String name)
The general constructor for the class which takes the name of the news
maker (generally the only thing we know about a news maker when the
constructor is called) as an argument.
|
Modifier and Type | Method and Description |
---|---|
void |
addNewsStory(NewsStory newsStory)
The mutator that adds a news story to a news maker's list of stories.
|
int |
compareTo(NewsMaker newsMaker)
The overridden compareTo method for news makers, which looks just at
name.
|
boolean |
equals(java.lang.Object o)
An overridden
equals method. |
java.lang.String |
getName()
The accessor for the name field.
|
NewsStoryList |
getNewsStories()
The accessor for the list of news stories.
|
private java.lang.String name
private NewsStoryList newsStories
NewsMaker()
public NewsMaker(java.lang.String name)
name
- The name of the news maker.public java.lang.String getName()
Note that String
objects are immutable, so it is fine to
return the field itself.
public NewsStoryList getNewsStories()
Note that NewsStoryList
objects are mutable, so this really
should return a copy of the list instead. However, we haven't studied
that yet, so returning the list itself is acceptable for now.
public void addNewsStory(NewsStory newsStory)
Note that since this list should contain only stories in which the news
maker is featured, we should have this method verify that the
NewsMaker
object is referenced in the NewsStory
object before the story is added to the list. 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.
newsStory
- The news story to add.public boolean equals(java.lang.Object o)
equals
method.
A NewsMaker
should be equal to another object if that object
is also a NewsMaker
object and they have the same name.
(Since equals
is a method in the Object
class
that we are overriding, the parameter needs to be an
Object
.)
equals
in class java.lang.Object
o
- The Object to which to compare this.