
package de.ivu.elect.business.geodata.boundary;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.inject.Inject;

import de.ivu.elect.business.geodata.control.GeodataOrtByNamenComparator;
import de.ivu.elect.business.geodata.entity.GeodataOrt;
import de.ivu.elect.business.geodata.entity.GeodataPlz;

public class GeodataPlzSearch implements Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private GeodataPlzDAO geodataPlzDao;

  public GeodataPlzSearch() {
    super();
  }

  public Map<String, List<GeodataOrt>> findAllMapped() {
    return streamAllGeodataPlz().collect(Collectors.toConcurrentMap(entity -> entity.getPlz(), entity -> {
      List<GeodataOrt> values = new ArrayList<>(entity.getGeodataOrte());

      Collections.sort(values, new GeodataOrtByNamenComparator());

      return values;
    }));
  }

  protected Stream<GeodataPlz> streamAllGeodataPlz() {
    return geodataPlzDao.findByAll().stream();
  }
}
