kullyN
asked on
How can I retrieve data from a collection which is within a map?
This function makes a call to listCustomerbyRef which then returns a map which includes 1) param 2) collection of customer details. i need to access these customer details from the collection and have the correct commands (commented out below at bottom of code) - but i cant retrieve these values
public void testListCustomersByRef() {
try{
TestableCustomerManager cm = new TestableCustomerManager();
Collection cusRef = new ArrayList();
Map result;
cusRef.add("0000564");
result = cm.listCustomersByRef(cusR ef,1);
//code missing to go here
/* cust.setRef((String) result.get("ref"));
cust.setName((String) result.get("name"));
cust.setRulesRow((Long) result.get("rules_row"));
cust.setLftCode((String) result.get("lftCode"));
cust.setLunCode((String) result.get("lunCode"));
System.out.println(cust.ge tName());
CustContact custContact = new CustContact();
custContact.setTitle((Stri ng) result.get("title"));
custContact.setForename((S tring) result.get("forename"));
custContact.setSurname((St ring) result.get("surname"));
custContact.setTelNo((Stri ng) result.get("telNo"));
custContact.setFaxNumber(( String) result.get("faxNumber"));
System.out.println(custCon tact.getFo rename());
Address address = new Address();
address.setAddLine1((Strin g) result.get("addLine1"));
address.setAddLine2((Strin g) result.get("addLine2"));
address.setAddLine3((Strin g) result.get("addLine3"));
address.setAddLine4((Strin g) result.get("addLine4"));
address.setAddLine5((Strin g) result.get("addLine5"));
address.setPostTown((Strin g) result.get("postTown"));
address.setPostcode((Strin g) result.get("postcode"));
address.setCountry((String ) result.get("country"));
custContact.setAddress(add ress);
//cust.setCustContacts((Se t)custCont act);
System.out.println(cust.ge tName());
System.out.println("Tested listCustomersByRef method");*/
}
catch(ReadException e){
System.out.println(e.getMe ssage());
}
catch(Exception e){
System.out.println(e.getMe ssage());
}
}
public void testListCustomersByRef() {
try{
TestableCustomerManager cm = new TestableCustomerManager();
Collection cusRef = new ArrayList();
Map result;
cusRef.add("0000564");
result = cm.listCustomersByRef(cusR
//code missing to go here
/* cust.setRef((String) result.get("ref"));
cust.setName((String) result.get("name"));
cust.setRulesRow((Long) result.get("rules_row"));
cust.setLftCode((String) result.get("lftCode"));
cust.setLunCode((String) result.get("lunCode"));
System.out.println(cust.ge
CustContact custContact = new CustContact();
custContact.setTitle((Stri
custContact.setForename((S
custContact.setSurname((St
custContact.setTelNo((Stri
custContact.setFaxNumber((
System.out.println(custCon
Address address = new Address();
address.setAddLine1((Strin
address.setAddLine2((Strin
address.setAddLine3((Strin
address.setAddLine4((Strin
address.setAddLine5((Strin
address.setPostTown((Strin
address.setPostcode((Strin
address.setCountry((String
custContact.setAddress(add
//cust.setCustContacts((Se
System.out.println(cust.ge
System.out.println("Tested
}
catch(ReadException e){
System.out.println(e.getMe
}
catch(Exception e){
System.out.println(e.getMe
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, then this is how you retrieve that collection:
Collection coll = (Collection) result.get(CommonConstants .PARAM_RES ULTS);
Collection coll = (Collection) result.get(CommonConstants
And afterwards:
Iterator it = coll.iterator();
while (it.hasNext()) {
ItemType item = (ItemType) it.next(); // ItemType being the type of the items in the collection
}
Iterator it = coll.iterator();
while (it.hasNext()) {
ItemType item = (ItemType) it.next(); // ItemType being the type of the items in the collection
}
But Collection is just an interface
These are the classes that implement that interface:
AbstractCollection, AbstractList, AbstractSet, ArrayList, BeanContextServicesSupport , BeanContextSupport, HashSet, LinkedHashSet, LinkedList, TreeSet, Vector
It would be handy if you knew which one it was...
These are the classes that implement that interface:
AbstractCollection, AbstractList, AbstractSet, ArrayList, BeanContextServicesSupport
It would be handy if you knew which one it was...
ASKER
none of these have worked, sorry
>> none of these have worked
What do you get?
Does
result.containsKey(CommonC onstants.P ARAM_RESUL TS)
return true?
If not, the collection simply isn't available in the map.
What do you get?
Does
result.containsKey(CommonC
return true?
If not, the collection simply isn't available in the map.
ASKER
i get null print statements
TestableCustomerManager cm = new TestableCustomerManager();
Collection cusRef = new ArrayList();
Map result;
cusRef.add("0000564");
result = cm.listCustomersByRef(cusR ef,1);
Collection customers = (Collection)result.get(Com monConstan ts.PARAM_R ESULTS);
Iterator it = customers.iterator();
while (it.hasNext()) {
String item = (String) it.next(); // ItemType being the type of the items in the collection
System.out.println(item);
}
TestableCustomerManager cm = new TestableCustomerManager();
Collection cusRef = new ArrayList();
Map result;
cusRef.add("0000564");
result = cm.listCustomersByRef(cusR
Collection customers = (Collection)result.get(Com
Iterator it = customers.iterator();
while (it.hasNext()) {
String item = (String) it.next(); // ItemType being the type of the items in the collection
System.out.println(item);
}
What can I say?
If null's are coming out, that means that null's were added.
Time to critically investigate the working of
result = cm.listCustomersByRef(cusR ef,1);
If null's are coming out, that means that null's were added.
Time to critically investigate the working of
result = cm.listCustomersByRef(cusR
ASKER
Collection coll = getCollectionFromSql(sQuer
HashMap result = new HashMap(2);
result.put(CommonConstants