Link to home
Start Free TrialLog in
Avatar of kullyN
kullyN

asked on

mapping data into a collection or data structure (easy)

i have data like below:

licNo                 cusRef          cusName
1                         "005"             "gdgd"
2                         "006"             "llkm"
3                          "007"               "lkjlk"

i need to map this data into a structure where i can access each element data through the licNo
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kullyN
kullyN

ASKER

I have a java class Customer already but this does not include the licNo attribute - the LicNo belongs to Licences class (table in  DB)
In the Object Relational Mapping the Licences are linked to the Customer through the attribute cusRef

im making a copy of data from the DB and then testing a function which retrieves customer via parsing in the licNo.

thus i need this testData structure to check the values retrived from the test
OK - just omit the key from the class then. My code will still work - it's just that you won't hold the licNo in the class itself
Avatar of kullyN

ASKER

how will i be able to map the licNo to the newly created Customer in the map.

at runtime i will run a test which will retrun a set of customer with licNo's
i then need to do a quick check to see which of the licNo match with the data i have and then from there retrieve the results map linked to the licNo

does this make sense?
Avatar of kullyN

ASKER

what i have so far

                     Map testData = new HashMap();
                Address add1 = new Address(80005023, "UK");
                Customer cus1 = new Customer("0044234", "academics", 9905504, "N", "CNV", add1, null);
Not sure what you're posting now kullyN - that's just creating two different objects that don't seem to be related
Avatar of kullyN

ASKER

is this any better?                  

  Map testData = new HashMap();
               
                Object[] cus1 = {"81","0044234", "academics", "9905504", "N", "CNV", null, null};      // customer 1
                Object[] cus2 = {"1","0044234", "academics", "9905504", "N", "CNV", null, null};        // customer 2
               
                Collection coll = new ArrayList();
                coll.add(cus1);
                coll.add(cus2);
               
                testData.put(CommonConstants.PARAM_RESULTS, coll);
Your customer should be represented by its own abstraction (class)
 testData.put(cus1licNo, cus1);
  testData.put(cus2licNo, cus2);