Solved

mapping data into a collection or data structure (easy)

Posted on 2004-10-14
12
147 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:kullyN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
12 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 12306798
Map m = new HashMap();
CustomerData cd = new CustomerData("005", "gdgd", 1);
m.put(cd.getLicenceNumber(), cd);


...


CustomerData x = (CustomerData)m.get(new Integer(1));
// 'x' now holds 'cd'




............


class CustomerData {
      private String reference;
      private String name;
      private Integer licenceNumber;
      
      public CustomerData(String reference, String name, int licenceNumber) {
            this.reference = reference;
            this.name = name;
            this.licenceNumber = new Integer(licenceNumber);
      }

      public void setLicenceNumber(Integer licenceNumber) {
            this.licenceNumber = licenceNumber;
      }

      public Integer getLicenceNumber() {
            return licenceNumber;
      }


      public void setReference(String reference) {
            this.reference = reference;
      }

      public String getReference() {
            return reference;
      }

      public void setName(String name) {
            this.name = name;
      }

      public String getName() {
            return name;
      }

}
0
 

Author Comment

by:kullyN
ID: 12306907
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12306941
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kullyN
ID: 12307117
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?
0
 

Author Comment

by:kullyN
ID: 12307128
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);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12307207
Not sure what you're posting now kullyN - that's just creating two different objects that don't seem to be related
0
 

Author Comment

by:kullyN
ID: 12307257
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);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12310889
Your customer should be represented by its own abstraction (class)
0
 
LVL 92

Expert Comment

by:objects
ID: 12313557
 testData.put(cus1licNo, cus1);
  testData.put(cus2licNo, cus2);
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 52
Print Rhino Java Array in Javascript 1 31
glassfish admin console 1 18
restrict decimal places for double datatype 10 29
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question