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 |
private CommandHistory |
history |
Constructor and Description |
---|
InventorySet() |
Modifier and Type | Method and Description |
---|---|
(package private) Record |
addNumOwned(Video video,
int change)
Add or remove copies of a video from the inventory.
|
(package private) Record |
checkIn(Video video)
Check in a video.
|
(package private) Record |
checkOut(Video video)
Check out a video.
|
(package private) java.util.Map<Video,Record> |
clear()
Remove all records from the inventory.
|
Record |
get(Video v)
Return the record for a given Video; if not present, return
null . |
(package private) CommandHistory |
getHistory()
Return a reference to the history.
|
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.
|
boolean |
redo()
Undo the last successful UndoableCommand.
|
(package private) void |
replaceEntry(Video video,
Record record)
If
record is null, then delete record for video ;
otherwise replace record for video . |
(package private) void |
replaceMap(java.util.Map<Video,Record> data)
Overwrite the map.
|
int |
size()
Return the number of Records.
|
java.lang.String |
toString()
Returns the inventory as a string; one record per line.
|
boolean |
undo()
Undo the last successful UndoableCommand.
|
private final CommandHistory history
InventorySet()
void replaceEntry(Video video, Record record)
record
is null, then delete record for video
;
otherwise replace record for video
.void replaceMap(java.util.Map<Video,Record> data)
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 boolean undo()
Inventory
public boolean redo()
Inventory
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
.
Record 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.Record checkOut(Video video)
video
- the video to be checked out.java.lang.IllegalArgumentException
- if video has no record or numOut
equals numOwned.Record checkIn(Video video)
video
- the video to be checked in.java.lang.IllegalArgumentException
- if video has no record or numOut
non-positive.java.util.Map<Video,Record> clear()
CommandHistory getHistory()