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.List<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.
|
NewsMaker |
getExactMatch(java.lang.String newsMakerName)
An accessor method to get a news maker from the list based on the exact
name provided.
|
NewsMaker |
getPartialMatch(java.lang.String newsMakerName)
An accessor method to get a news maker from the list based on the partial
name provided.
|
void |
sort()
The sort method for the class.
|
private java.util.List<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 list.public 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.public NewsMaker getExactMatch(java.lang.String newsMakerName)
Note that this method uses a binary search. A binary search will only work for a sorted list. For Project 3 (Nooz 3.0), this method should check whether the list is sorted before using the binary search. If the list is not sorted, it should send a warning to standard error (""Attempted to conduct binary search on unsorted list.") and use a linear search instead.
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.
newsMakerName
- The exact name for which to search.public NewsMaker getPartialMatch(java.lang.String newsMakerName)
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.
newsMakerName
- The exact name for which to search.public void sort()
It simply calls Collections.sort
on the list of news makers
and lets it use the natural ordering of news makers (as defined by the
compareTo
method of NewsMaker
) to determine the
ordering.