×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Jonathan Vila López
Added: Jun 18, 2014 12:06 PM
Views: 1805
Tags: no tags
  1. public class AgregadorEventos {
  2.     private static final Logger log = org.slf4j.LoggerFactory.getLogger(AgregadorEventos.class);
  3.    
  4.     private HotelSvc hotelService;
  5.  
  6.     public void setHotelService(HotelSvc hotelService) {
  7.         this.hotelService = hotelService;
  8.     }
  9.  
  10.     public Map<Hoteles, List<EventoPrecio>> agregaEventoPrecio(Map<Hoteles, List<EventoPrecio>> lista, List<EventoPrecio> eventoList) {
  11.         if (lista == null) {
  12.             lista = new HashMap<>();
  13.         }
  14.  
  15.         for (EventoPrecio evento : eventoList) {
  16.             // search for the hotel entity using the hotel external code in the event
  17.             Hoteles hotel = hotelService.getHotelesByCodExt(evento.getCodsubcanal().getCodsubcanal(), evento.getCodigohot());
  18.             Hoteles hotelElement = hotel;
  19.  
  20.             // we search in the Group for the hotel, using the hotel code
  21.             if (lista.size() > 0) {
  22.                 for (Hoteles hotelItem : lista.keySet()) {
  23.                     if (hotelItem.getCodigohot().equals(hotel.getCodigohot())) {
  24.                         hotelElement = hotelItem;
  25.                     }
  26.                 }
  27.             }
  28.  
  29.             // get the List of events of that Hotel
  30.             List<EventoPrecio> listaEventos = lista.get(hotelElement);
  31.  
  32.             // if that hotel is not yet in the list
  33.             if (listaEventos == null) {
  34.                 lista.put(hotelElement, new ArrayList<EventoPrecio>());
  35.             }
  36.  
  37.             // adding the event to the hotel's list
  38.             lista.get(hotelElement).add(evento);
  39.         }
  40.         log.debug("Salida de Aggregador Eventos : " + lista);
  41.         return lista;
  42.     }
  43.  
  44. }