orderprocessing
Class Customer

java.lang.Object
  extended byorderprocessing.Customer
All Implemented Interfaces:
java.io.Serializable

public class Customer
extends java.lang.Object
implements java.io.Serializable

This class maintains information about a single customer

Note that any changes to the public part of this class or any change in the fields will require versioning. This is because these objects are stored in the object database for this application.

This class can serve as a model for other classes that need versioning. Be sure to add versioning infrastructure to them before you include them in the database for the first time.

Note that Addresses are already implicitly included in the database since they are written whenever a Customer is written.

Additionally, this class maintains a collection of all customers.

See Also:
Serialized Form

Constructor Summary
Customer(java.lang.String name, Address billingAddress)
          create a customer object with default values for ship address and terms
Customer(java.lang.String name, Address billingAddress, Address shipAddress)
          Create a customer object with default terms.
Customer(java.lang.String name, Address billingAddress, Address shipAddress, BillingTerms billingTerms)
          create a customer object with all options specified.
 
Method Summary
 Address billingAddress()
          Retrieve the customer's billing address
 BillingTerms billingTerms()
          Retrieve this customer's default billing terms
 void billingTerms(BillingTerms terms)
          Set new billing terms for this customer
static void close(java.io.ObjectOutputStream out)
          Write all of the customer data for all customers to an output stream
static java.util.Iterator customers()
          Provide an iteration service over all known customers.
 void display()
          Display this customer info on standard output
static void dump()
          Display all of the customers on standard output.
 boolean equals(java.lang.Object other)
           
static Customer get(java.lang.String customerNumber)
          Get a particular customer object from its customer number.
 int hashcode()
           
 boolean isActive()
          Tell if a customer is active.
 java.lang.String key()
          Retrieve the customer number
static java.util.Iterator keys()
          Provide an iterator over the customer numbers.
 java.lang.String name()
          Retrieve the customer name
 void name(java.lang.String name)
          Change the name of this customer
static void open(java.io.ObjectInputStream in)
          Read all customer data for all customers into the program at the beginning of a run
static void remove(java.lang.String key)
          Make a customer inactive.
 Address shippingAddress()
          Retrieve the customer's ship address
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Customer

public Customer(java.lang.String name,
                Address billingAddress)
create a customer object with default values for ship address and terms


Customer

public Customer(java.lang.String name,
                Address billingAddress,
                Address shipAddress)
Create a customer object with default terms.


Customer

public Customer(java.lang.String name,
                Address billingAddress,
                Address shipAddress,
                BillingTerms billingTerms)
create a customer object with all options specified.

Parameters:
name - the customer name.
billingAddress - the customer billing address
shipAddress - the ship address if not specified on an order
billingTerms - the billing terms if not specified on an order. Note: As with ALL constructors in ALL classes, the verification of the data must occur BEFORE you call the constructor. Only call a constructor when the data is correct to create a fully usable object that maintains all of its invariants. Never create a partially complete object unless you take foolproof steps to complete the process of creation.
Method Detail

key

public java.lang.String key()
Retrieve the customer number

Returns:
the customer number

name

public java.lang.String name()
Retrieve the customer name

Returns:
the customer's name

billingAddress

public Address billingAddress()
Retrieve the customer's billing address

Returns:
the customer's billing address

shippingAddress

public Address shippingAddress()
Retrieve the customer's ship address

Returns:
the customer's shipping address

billingTerms

public BillingTerms billingTerms()
Retrieve this customer's default billing terms

Returns:
the billing terms

billingTerms

public void billingTerms(BillingTerms terms)
Set new billing terms for this customer

Parameters:
terms - the new billing terms

name

public void name(java.lang.String name)
Change the name of this customer

Parameters:
name - the new customer name

display

public void display()
Display this customer info on standard output


equals

public boolean equals(java.lang.Object other)

hashcode

public int hashcode()

toString

public java.lang.String toString()

close

public static final void close(java.io.ObjectOutputStream out)
                        throws java.io.IOException
Write all of the customer data for all customers to an output stream

Parameters:
out - the Object stream to write to
Throws:
java.io.IOException

isActive

public boolean isActive()
Tell if a customer is active. A customer is active until "removed."

Returns:
true if the customer is active.

open

public static final void open(java.io.ObjectInputStream in)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Read all customer data for all customers into the program at the beginning of a run

Parameters:
in - the Object stream to read from
Throws:
java.io.IOException
java.lang.ClassNotFoundException

customers

public static java.util.Iterator customers()
Provide an iteration service over all known customers. The iterator will return customer objects. There is no implied ordering.

Returns:
an Iterator over the customer part of the database

keys

public static java.util.Iterator keys()
Provide an iterator over the customer numbers. The iterator will return just the customer numbers as Strings. There is no implied ordering.

Returns:
an iterator over the customer numbers (strings).

dump

public static void dump()
Display all of the customers on standard output. No order implied.


get

public static Customer get(java.lang.String customerNumber)
Get a particular customer object from its customer number.

Parameters:
customerNumber - the customer's number
Returns:
the customer object or null if none

remove

public static void remove(java.lang.String key)
Make a customer inactive.

Parameters:
key - the customer to "remove"