Class Order

Object
  extended by Order

public class Order
extends Object

An order.
CS 537, Spring 2007, Project 3.
A mapping from Grain types to integers (number of bushels).


Field Summary
private  Map<Grain,Integer> amt
          The actual mapping.
private static int VERSION
          Source version number.
 
Constructor Summary
Order()
          Creates a new Order with all amounts zero.
 
Method Summary
 void change(Grain g, int diff)
          Changes the mount of "g" by "diff".
 void change(Order incr)
          Changes the amount of each grain g by incr.get(g).
 Order copy()
          Returns a copy of this Order.
 int get(Grain g)
          Gets the amount of "g" in this order.
 void set(Grain g, int n)
          Sets the amount of "g" to "n".
 void set(int n)
          Sets the amounts of all grains to "n".
 String toString()
          Returns a readable version of this order.
 int total()
          Returns the total amount of grain in this order.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

private static final int VERSION
Source version number.

See Also:
Constant Field Values

amt

private Map<Grain,Integer> amt
The actual mapping.

Constructor Detail

Order

public Order()
Creates a new Order with all amounts zero.

Method Detail

toString

public String toString()
Returns a readable version of this order.

Overrides:
toString in class Object
Returns:
a readable version of this order.

get

public int get(Grain g)
Gets the amount of "g" in this order.

Parameters:
g - the grain
Returns:
the amount of grain g

set

public void set(Grain g,
                int n)
Sets the amount of "g" to "n".

Parameters:
g - a grain
n - the amount of grain g

set

public void set(int n)
Sets the amounts of all grains to "n".

Parameters:
n - the amount to set.

total

public int total()
Returns the total amount of grain in this order.

Returns:
the total.

change

public void change(Grain g,
                   int diff)
Changes the mount of "g" by "diff".

Parameters:
g - a grain
diff - the change in the amount of grain g

change

public void change(Order incr)
Changes the amount of each grain g by incr.get(g).

Parameters:
incr - the amount to increment by.

copy

public Order copy()
Returns a copy of this Order.

Returns:
a copy of this Order.