BigRedEO
BigRedEO

Reputation: 837

Get values from hashmap in Eclipse

I am adding to a project done in Eclipse that displays data pulled from various databases to a webpage. I am trying to figure out how to use a hashmap. I have a variable/column called "description" that will show a description based on the value of the column just before it. The descriptions are in my hashmap. I just don't know how to pull the "description" value.

Here is part of the DtoBuilder -

private HashMap<String,String> itemDescrMap = null;

public VersionsDto build(Versions oneVersion){

    VersionsDto result = null;
    if(itemDescrMap==null){
        itemDescrMap = loadItemDescrMap();
    }

    // Create instance of versions object and build it.
    if(oneVersion != null){
        result = new VersionsDto();
        result.setStore(oneVersion.getStore());
        result.setUpdatePackage(oneVersion.getUpdatePackage());
        result.setDescription(oneVersion.getDescription());

and here is part of the hashmap -

private static HashMap<String,String> loadItemDescrMap(){
    HashMap<String,String> map = new HashMap<String,String>();

    map.put("CDSA", "Color Match");
    map.put("CDSB", "New Formula Book");
    map.put("CDSC", "Base Assignments");
    map.put("CDSD", "Product Formulation");
    map.put("CDSE", "Old TAC");
    map.put("CDSF", "Colorant Systems");
    map.put("CDSG", "Miscellaneous");
    map.put("CDSH", "AFCD");

Initially, I was just grabbing the same data for "description" as I was for "updatePackage", just to test that it would populate all the fields and display it to the webpage. So now I need to know how to set the "description" value based on the hash map, where the first values (CDSD, CDSE, etc) are all the possible values in the "updatePackage" column and the second value is the corresponding "description" that I need.

Upvotes: 1

Views: 900

Answers (1)

user6106573
user6106573

Reputation: 191

Look at the javadoc https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html

I think itemDescrMap.get(oneVersion.getUpdatePackage()) should do the job

Upvotes: 2

Related Questions