Search code examples
javastrutsconcurrenthashmap

Understanding code specific functional concepts


I am relatively new to struts and java. I have been trying to understand the following piece of code.

 List<LabelValueBean> dbList = getCardProductList();

    ConcurrentMap<Integer, ProductItem> ret = new ConcurrentHashMap<Integer, ProductItem>();
    for (LabelValueBean lb : dbList) {
        ProductItem pi = new ProductItem();
        pi.setId(Integer.valueOf(lb.getId()));
        pi.setCode(lb.getCode());
        pi.setName(lb.getDescription());

        LabelValueBeanAuxCol[] aux = lb.getLabelvaluebeanauxcol();
        pi.setTypeProduct(Boolean.TRUE);

        if (null != aux) {
            for (LabelValueBeanAuxCol element : aux) {
                if (null != element
                        && "PRDCT_SVC_IND".equals(element.getName())) {
                    pi.setTypeProduct(Boolean.valueOf("Y".equals(element
                            .getValue())));
                }
            }
        }
        pi.setNeedSetup(Boolean.TRUE);
        ret.put(pi.getId(), pi);
    }
    return Himms2LookupUtil
            .<ConcurrentMap<Integer, ProductItem>> setValueInCache(
                    Himms2Names.CARD_SERVICE_PRODUCT_LIST, ret);
}

With repect to the code block around "PRDCT_SVC_IND", how would a name of the column be mapped to the labelvaluebean?
Though I have an idea on the concurrent map and the key value pair functionality, I am pretty unsure about most of the concepts here and have tried searching on the internet without much luck. I would want a more clearer overview of what the above lines actually mean(in general ofcourse), in terms of the concepts used here like the concurrenthashmap, list(labelvaluebean) etc. Any inputs would be greatly appreciated.


Solution

  • Code is doing following things :-

    1) Getting CardProductList in first line and storing reference in a dbList object as

    List<LabelValueBean> dbList = getCardProductList();`
    

    2) Creating ConcurrentMap of key value .

    3) Start iterating CardProductList and perform following operations on each CardProductList object -

    a) Crates ProductItem object.
    b) setting CardProduct object values (id, code, name) into ProductItem object.
    d) setting ProductItem.typeProduct to TRUE.
    c) getting Labelvaluebeanauxcol and store it in a LabelValueBeanAuxCol[] array instance called aux.
    d) now check if aux is not null then iterates aux array and checks if(elemet is not null  AND element name IS EQUAL TO "PRDCT_SVC_IND"
        THEN
            set ProductItem.TypeProduct to True if element.value = Y
            ELSE
            set ProductItem.TypeProduct to FALE
    e) set ProductItem.NeddSetup = TRUE
    f) set ProductItem.id and ProductItem into ConcurrentMap.
    

    4) Store ConcurrentMap in cache