FileDocCategorySizeDatePackage
Customer.javaAPI DocExample6844Sun Dec 14 22:47:40 GMT 2003oreilly.hcj.collections

Customer

public class Customer extends Object implements Serializable
Demonstration of set functionality in beans.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.3 $

Fields Summary
private static final long
serialVersionUID
Use serialVersionUID for interoperability.
private PropertyChangeSupport
propertyChangeSupport
Provides support for property change events.
private Set
purchases
Holds value of property purchases.
private Set
purchases2
Holds value of property purchases2.
private Set
purchases3
Holds value of property purchases3.
private String
name
Name of the customer.
private VetoableChangeSupport
vetoableChangeSupport
Utility field used by constrained properties.
Constructors Summary
public Customer()
Creates new Customer


	    	 
	  
	
Methods Summary
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)

see
java.beans.PropertyChangeListener

		propertyChangeSupport.addPropertyChangeListener(l);
	
public voidaddVetoableChangeListener(java.beans.VetoableChangeListener l)

see
java.beans.VetoableChangeListener

		vetoableChangeSupport.addVetoableChangeListener(l);
	
public java.lang.StringgetName()
Getter for the property name.

return
The current value of the property name.

		return this.name;
	
public java.util.SetgetPurchases()
Getter for property purchases.Note that this doesn't protect the sets as they are given out to the callers of this method.

return
Value of property purchases.

		return this.purchases;
	
public java.util.SetgetPurchases2()
Getter for property purchases2. Note that you will have to check for null in the return value.

return
Value of property purchases2.

		if (this.purchases2 == null) {
			return null;
		}
		return Collections.unmodifiableSet(this.purchases2);
	
public java.util.SetgetPurchases3()
Getter for property purchases3.Returns the value of the property. Since the property can never be null, the user has the ability to use the return value without checking for null.

return
Value of property purchases3; Note that this will never be null.

		return Collections.unmodifiableSet(this.purchases3);
	
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)

see
java.beans.PropertyChangeListener

		propertyChangeSupport.removePropertyChangeListener(l);
	
public voidremoveVetoableChangeListener(java.beans.VetoableChangeListener l)

see
java.beans.VetoableChangeListener

		vetoableChangeSupport.removeVetoableChangeListener(l);
	
public voidsetName(java.lang.String name)
Setter for the property name.

param
name The new value for the property name.
throws
PropertyVetoException If the change is vetoed.

		final String oldName = this.name;
		vetoableChangeSupport.fireVetoableChange("name", oldName, this.name);
		this.name = name;
		propertyChangeSupport.firePropertyChange("name", oldName, this.name);
	
public voidsetPurchases(java.util.Set purchases)
Setter for property purchases. Note that this doesn't protect the sets as they are given out to the PropertyChangeListener and PropertyVetoListener objects.

param
purchases New value of property purchases.
throws
PropertyVetoException If the change is vetoed.

		Set oldPurchases = this.purchases;
		vetoableChangeSupport.fireVetoableChange("purchases", oldPurchases, this.purchases);
		this.purchases = purchases;
		propertyChangeSupport.firePropertyChange("purchases", oldPurchases, this.purchases);
	
public voidsetPurchases2(java.util.Set purchases2)
Setter for property purchases2.This method fully protects the incomming set so that the vetoable change listener, and the propertyChangeListener cant change it.

param
purchases2 New value of property purchases2.
throws
PropertyVetoException If the change is vetoed.

		final Set newPurchases2;
		if (purchases2 != null) {
			newPurchases2 = Collections.unmodifiableSet(purchases2);
		} else {
			newPurchases2 = null;
		}

		final Set oldpurchases2 = this.getPurchases2();
		vetoableChangeSupport.fireVetoableChange("purchases2", oldpurchases2,
		                                         newPurchases2);
		this.purchases2 = new HashSet(purchases2);
		propertyChangeSupport.firePropertyChange("purchases2", oldpurchases2,
		                                         getPurchases2());
	
public voidsetPurchases3(java.util.Set purchases3)
Setter for property purchases3. This method fully protects the incomming set so that the vetoable change listener, and the propertyChangeListener cant change it. In addition, since the property can never be null, you dont have to worry about checking for null.

param
purchases3 New value of property purchases3.
throws
PropertyVetoException If the change is vetoed.
throws
NullPointerException If null is passed for purchases3.

		if (purchases3 == null) {
			throw new NullPointerException();
		}
		final Set oldPurchases3 = this.getPurchases3();
		final Set newPurchases3 = Collections.unmodifiableSet(purchases3);
		vetoableChangeSupport.fireVetoableChange("purchases3", oldPurchases3,
		                                         newPurchases3);
		this.purchases3 = new HashSet(purchases3);
		propertyChangeSupport.firePropertyChange("purchases3", oldPurchases3,
		                                         getPurchases3());