final class InventorySet extends java.lang.Object
HashMap<Video,Record>
.
Keys are Videos; Values are Records.
Class Type: Mutable Collection of Records
Object Invariant:
Every key and value in the map is non-null
.
Object Invariant:
Each valuer
is stored under key r.video
.Modifier and Type | Field and Description |
---|---|
private java.util.Map<VideoObj,Record> |
data
Invariant:
_data != null |
Constructor and Description |
---|
InventorySet() |
Modifier and Type | Method and Description |
---|---|
void |
addNumOwned(VideoObj video,
int change)
Add or remove copies of a video from the inventory.
|
void |
checkIn(VideoObj video)
Check in a video.
|
void |
checkOut(VideoObj video)
Check out a video.
|
void |
clear()
Remove all records from the inventory.
|
Record |
get(VideoObj v)
Return a copy of the record for a given Video; if not present, return
null . |
int |
size()
Return the number of Records.
|
java.util.Collection<Record> |
toCollection()
Return a copy of the records as a collection.
|
java.lang.String |
toString()
Return the contents of the inventory as a string.
|
InventorySet()
public int size()
public Record get(VideoObj v)
null
.public java.util.Collection<Record> toCollection()
public void addNumOwned(VideoObj 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.
Postcondition: changes the record for the video
public void checkOut(VideoObj video)
video
- the video to be checked out.java.lang.IllegalArgumentException
- if video has no record or numOut
equals numOwned.
Postcondition: changes the record for the video
public void checkIn(VideoObj video)
video
- the video to be checked in.java.lang.IllegalArgumentException
- if video has no record or numOut
non-positive.
Postcondition: changes the record for the video
public void clear()
Postcondition: size() == 0
public java.lang.String toString()
toString
in class java.lang.Object