Articles Index
Using Vector Components
by Rob Reesor, with John Papageorge
Doing commerce on the Web is the ultimate object-oriented problem," says
Virtual Vineyards Java programmer Rob Reesor. "We deal with real
asynchronous parallel processes such as credit card authorization, and
shipment of tangible products in a multicompany, multiprotocol
environment. Reesor offers this method, which takes a vector of components and
returns a vector of the part numbers needed to make up those components.
/*
* For example, one component may be Widget 4 and
* another may be Widget 5. The parts needed for
* Widget 4 may be parts 1, 3, 7, 8, 13 and the
* parts needed for Widget 5 may be 2, 5, 7, 8, 12.
* The part numbers needed for both
* are 1, 2, 3, 5, 7, 8, 12, 13.
*
* This parts list could be used to notify vendors to
* gear up production.
*/
private Vector partsList(Vector components)
{
// We need an Enumeration of the elements of
// components, a Hashtable to make it easy to
// avoid duplication, and a Vector to return.
Enumeration enum = components.elements();
Hashtable partsHash = new Hashtable();
Vector partsList = new Vector();
// HandyInfo is an object that is created when the
// server starts up and contains a cache of handy
// information about components.
nc.gendatabase.HandyInfo hi =
new nc.gendatabase.HandyInfo(self);
// We loop through the components getting the int
// value for each. We use HandyInfo to get the
// information about the components so we can get
// a Vector of it's parts list.
while (enum.hasMoreElements())
{
int comp =
((Integer)enum.nextElement()).intValue();
Vector parts = null;
hi.getInfoForComponent(comp);
parts = hi.getParts(comp);
// We create an Enumeration of the parst of
// this component. We loop through the enumeration
// using each part number as a Hashtable key.
// Since components may share part numbers, we
// can't just return a Vector of all part numbers
// of all components. Keying into a Hashtable will
// result in no duplication.
Enumeration partsEnum = parts.elements();
while (partsEnum.hasMoreElements())
{
charsHash.put(
(Integer)partsEnum.nextElement(), "1");
}
}
// Finally, we loop over the keys of the Hashtable to
// create the Vector of part numbers to return.
enum = partsHash.keys();
while (enum.hasMoreElements())
{
partsList.addElement((Integer)enum.nextElement());
}
return partsList;
}
Release No Website Before Its Time--an Interview with Rob Reesor and Ed Videki of Virtual Vineyards
What do asynchronous, parallel processes, and selling wine have in common? Read this
article for the answer.