001package myhw2.data;
002
003import myhw2.command.Command;
004
005/**
006 * A static class for accessing data objects.
007 */
008public class Data {
009        private Data() {}
010        /**
011         * Returns a new Inventory.
012         */
013        static public final Inventory newInventory() {
014                return new InventorySet();
015        }
016
017        /**
018         * Factory method for Video objects.
019         * Title and director are "trimmed" to remove leading and final space.
020         * @throws IllegalArgumentException if Video invariant violated.
021         */
022        static public Video newVideo(String title, int year, String director) {
023                // TODO
024                return null;
025        }
026
027        /**
028         * Returns a command to add or remove copies of a video from the inventory.
029         * <p>The returned command has the following behavior:</p>
030         * <ul>
031         * <li>If a video record is not already present (and change is
032         * positive), a record is created.</li>
033         * <li>If a record is already present, <code>numOwned</code> is
034         * modified using <code>change</code>.</li>
035         * <li>If <code>change</code> brings the number of copies to be less
036         * than one, the record is removed from the inventory.</li>
037         * </ul>
038         * @param video the video to be added.
039         * @param change the number of copies to add (or remove if negative).
040         * @throws IllegalArgumentException if <code>inventory</code> not created by a call to <code>newInventory</code>.
041         */
042        static public Command newAddCmd(Inventory inventory, Video video, int change) {
043                if (!(inventory instanceof InventorySet))
044                        throw new IllegalArgumentException();
045                return new CmdAdd((InventorySet) inventory, video, change);
046        }
047
048        /**
049         * Returns a command to check out a video.
050         * @param video the video to be checked out.
051         * @throws IllegalArgumentException if <code>inventory<code> not created by a call to <code>newInventory</code>.
052         */
053        static public Command newOutCmd(Inventory inventory, Video video) {
054                // TODO
055                return null;
056        }
057
058        /**
059         * Returns a command to check in a video.
060         * @param video the video to be checked in.
061         * @throws IllegalArgumentException if <code>inventory<code> not created by a call to <code>newInventory</code>.
062         */
063        static public Command newInCmd(Inventory inventory, Video video) {
064                // TODO
065                return null;
066        }
067
068        /**
069         * Returns a command to remove all records from the inventory.
070         * @throws IllegalArgumentException if <code>inventory<code> not created by a call to <code>newInventory</code>.
071         */
072        static public Command newClearCmd(Inventory inventory) {
073                if (!(inventory instanceof InventorySet))
074                        throw new IllegalArgumentException();
075                return new CmdClear((InventorySet) inventory);
076        }
077}