class NewsStoryList
extends java.lang.Object
implements java.io.Serializable
A NewsStoryList
is a list of NewsStory
objects.
Modifier and Type | Field and Description |
---|---|
private java.util.List<NewsStory> |
newsStories
The list of newspaper stories.
|
private static long |
serialVersionUID
This is the first serializable version of NewsStoryList, so we select a
serialVersionUID of 1L.
|
Constructor and Description |
---|
NewsStoryList() |
Modifier and Type | Method and Description |
---|---|
void |
add(NewsStory newsStory)
The mutator for adding a newspaper story to the list.
|
NewsStory |
get(int index)
An accessor for getting a story from the list based on its position
(index) in the list.
|
int |
size()
The accessor for determining the number of stories in the list.
|
private static final long serialVersionUID
private java.util.List<NewsStory> newsStories
public void add(NewsStory newsStory)
By using our own class with its own add
method, rather than
directly using the add
method of ArrayList
, we
could ensure that we don't add duplicate NewsStory
objects
to our 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 newspaper story to add.public int size()
Note that this accessor name violates the convention that accessor names should start with "get" (or "is" for booleans). However, "size" is an accepted convention for names serving this particular purpose, so we are following the second convention rather than the first.
public NewsStory get(int index)
index
- The location from which to get the story.java.lang.IllegalArgumentException
- if the index is not valid.