Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/10/2013, 06:28
jmm87
 
Fecha de Ingreso: octubre-2012
Mensajes: 202
Antigüedad: 11 años, 6 meses
Puntos: 0
HashMap agregar items

Alguien me podria explicar la logita de esto???

Código Java:
Ver original
  1. public void agregarItem(ShoppingCartItem item)
  2.     {
  3.         //Por lo visto containsKey controla que alla algo en el HashMap
  4.         // pero no entiendo porque crea un entero y porque trae el Id
  5.        // trayendo el producto ya no tengo el Id?
  6.         if( items.containsKey( new Integer(item.getProducto().getId()) ) )
  7.         {
  8.          //aca lo mismo. crea un Integer. porque?
  9.             ShoppingCartItem cartItem = (ShoppingCartItem) items.get( new Integer(item.getProducto().getId()) );
  10.             cartItem.setCantidad( cartItem.getCantidad() + item.getCantidad() );
  11.         }
  12.         // Si el producto no esta, lo agrega
  13.         else
  14.         {
  15.             items.put( new Integer(item.getProducto().getId()), item );
  16.         }