class NewsMakerList
extends java.lang.Object
A NewsMakerList
is a list of NewsMaker
objects.
Each NewsMaker
in the list must have a unique name.
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<NewsMaker> |
newsMakers
The list of news makers.
|
Constructor and Description |
---|
NewsMakerList()
The no-argument constructor initializes the list to be an empty
ArrayList of NewsMaker objects. |
Modifier and Type | Method and Description |
---|---|
(package private) void |
add(NewsMaker newsMaker)
The mutator for adding news makers to the list.
|
boolean |
contains(NewsMaker newsMaker)
An accessor method to test whether the list already contains a news
maker.
|
NewsMaker |
get(NewsMaker newsMaker)
An accessor method to get a news maker from the list.
|
private java.util.ArrayList<NewsMaker> newsMakers
NewsMakerList()
ArrayList
of NewsMaker
objects.void add(NewsMaker newsMaker)
By using our own class with its own add
method, rather than
directly using the add
method of ArrayList
, we
can ensure that we don't add multiple NewsMaker
objects with
the same name to our list (thereby keeping the names unique).
newsMaker
- The news maker to add.java.lang.IllegalArgumentException
- if the news maker to add is already in the listpublic boolean contains(NewsMaker newsMaker)
Simply makes use of the contains
method of
ArrayList
.
newsMaker
- The news maker to check for in the list.public NewsMaker get(NewsMaker newsMaker)
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.
newsMaker
- The news maker to get from the list.