final class InventorySet extends java.lang.Object implements Inventory
Data
Modifier and Type | Class and Description |
---|---|
private static class |
InventorySet.RecordObj
Implementation of Record interface.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<Video,Record> |
data |
Constructor and Description |
---|
InventorySet() |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addNumOwned(Video video,
int change)
Add or remove copies of a video from the inventory.
|
(package private) void |
checkIn(Video video)
Check in a video.
|
(package private) void |
checkOut(Video video)
Check out a video.
|
(package private) void |
clear()
Remove all records from the inventory.
|
Record |
get(Video v)
Return the record for a given Video; if not present, return
null . |
java.util.Iterator<Record> |
iterator()
Return an iterator over Records in the Inventory.
|
java.util.Iterator<Record> |
iterator(java.util.Comparator<Record> comparator)
Return an iterator over the Inventory, sorted accoring the
Comparator.
|
int |
size()
Return the number of Records.
|
java.lang.String |
toString()
Returns the inventory as a string; one record per line.
|
InventorySet()
public Record get(Video v)
Inventory
null
.public java.util.Iterator<Record> iterator()
Inventory
The iterator returns objects that implement the Record interface.
Any attempt to remove objects using the iterator should
result in an UnsupportedOperationException
.
The Record order is unspecified
public java.util.Iterator<Record> iterator(java.util.Comparator<Record> comparator)
Inventory
The iterator returns objects that implement the
Record
interface.
Any attempt to remove objects using the iterator should
result in an UnsupportedOperationException
.
The iteration order is determined by the comparator (least first).
The comparator may assume that its arguments implement
Record
.
void addNumOwned(Video video, int change)
numOwned
is
modified using change
.
If change
brings the number of copies to be zero,
the record is removed from the inventory.video
- the video to be added.change
- the number of copies to add (or remove if negative).java.lang.IllegalArgumentException
- if video null, change is zero, if attempting to remove more copies than are owned, or if attempting to remove copies that are checked out.void checkOut(Video video)
video
- the video to be checked out.java.lang.IllegalArgumentException
- if video has no record or numOut
equals numOwned.void checkIn(Video video)
video
- the video to be checked in.java.lang.IllegalArgumentException
- if video has no record or numOut
non-positive.void clear()