public void salvarCondutor(Condutor cond)
      throws ExcecaoCPFExistente, ExcecaoIdadeImpropriaParaCondutor {
    Condutor condutor = banco.getCondutorComCpf(cond.getCPF());

    if (condutor != null) throw new ExcecaoCPFExistente();

    if (ManipuladorData.calculeDiferencaDeAnos(new Date(), cond.getDataNasc()) < 18)
      throw new ExcecaoIdadeImpropriaParaCondutor();

    banco.addCondutor(cond);
  }
  public Object[] monteDadosInf(Infracao inf) {
    Object[] s = new Object[5];
    Condutor cond = banco.getCondutorComCpf(banco.getVeiculoComPlaca(inf.getPlaca()).getCpfDono());

    s[0] = (inf.getNumInfracao());
    s[1] = FormataPlaca.coloqueMascara(inf.getPlaca());
    s[2] = ManipuladorData.format(inf.getDataInf());
    s[3] = FormataCPF.formatCpf(cond.getCPF());
    s[4] = cond.getNome();

    return s;
  }
  public void salvarVeiculo(Veiculo veic) throws ExcecaoVeiculoExistente, ExcecaoCPFInexistente {
    Veiculo veiculo = banco.getVeiculoComPlaca(veic.getPlaca());

    if (veiculo != null) {
      throw new ExcecaoVeiculoExistente();
    }

    if (this.getCondutorComCpf(veic.getCpfDono()) == null) {
      throw new ExcecaoCPFInexistente();
    }

    banco.addVeiculo(veic);
  }
  public List<Infracao> getInfracoesComNomeCondutor(String nome) {
    List<Infracao> infs = new LinkedList<Infracao>(getInfracoes());

    Condutor cond = null;

    List<Infracao> infracoes = new LinkedList<Infracao>();

    for (Infracao inf : infs) {
      cond = banco.getCondutorComCpf(banco.getVeiculoComPlaca(inf.getPlaca()).getCpfDono());

      if (cond.getNome().toUpperCase().contains(nome.toUpperCase())) infracoes.add(inf);
    }

    return infracoes;
  }
  public int retorneProxNInf() throws ExcecaoNumInfracaoMaximo {
    int ret = banco.getNInf() + 1;

    if (ret > 999999999) throw new ExcecaoNumInfracaoMaximo();

    return ret;
  }
  public int retorneAnoFabVei(String placa) throws ExcecaoPlacaInexistente {
    Veiculo vei = banco.getVeiculoComPlaca(placa);

    if (vei == null) throw new ExcecaoPlacaInexistente();

    return vei.getAno();
  }
  public void salvarInfracao(Infracao inf)
      throws ExcecaoPlacaInexistente, ExcecaoDataInfCondIdadeImpropria,
          ExcecaoDataInfMenorAnoFabVei {

    if (banco.getVeiculoComPlaca(inf.getPlaca()) == null) throw new ExcecaoPlacaInexistente();

    if (ManipuladorData.calculeDiferencaDeAnos(
            inf.getDataInf(),
            this.getCondutorComCpf(this.getVeiculoComPlaca(inf.getPlaca()).getCpfDono())
                .getDataNasc())
        < 18) throw new ExcecaoDataInfCondIdadeImpropria();

    int anoFabVeiculo = this.retorneAnoFabVei(inf.getPlaca());
    int anoInf = ManipuladorData.getAnoDeData(inf.getDataInf());

    if (anoFabVeiculo > anoInf) throw new ExcecaoDataInfMenorAnoFabVei();

    banco.addInfracao(inf);
  }
  public Collection<Infracao> getInfracoes(long cpf) {

    ArrayList<Infracao> infracoes = new ArrayList<Infracao>(banco.getInfracoes());
    ArrayList<Veiculo> veiculos = new ArrayList<Veiculo>(banco.getVeiculos());

    ArrayList<Infracao> infracoesCPF = new ArrayList<Infracao>();

    for (Veiculo v : veiculos) {
      if (String.valueOf(v.getCpfDono())
          .toUpperCase()
          .contains(String.valueOf(cpf).toUpperCase())) {
        for (Infracao i : infracoes) {
          if (i.getPlaca().equals(v.getPlaca())) infracoesCPF.add(i);
        }
      }
    }

    return infracoesCPF;
  }
  public Map<Long, Integer> getTopInfratores() {
    List<Infracao> listaInf = new ArrayList<Infracao>(getInfracoes());
    Iterator<Infracao> ite = listaInf.iterator();

    Map<Long, Integer> infConds = new HashMap<Long, Integer>();

    Condutor c;
    int cont = 0;

    while (ite.hasNext()) {
      c = banco.getCondutorComCpf(getVeiculoComPlaca(ite.next().getPlaca()).getCpfDono());
      cont = 1;

      if (infConds.get(c.getCPF()) != null) {
        cont = (infConds.get(c.getCPF()) + 1);
      }

      infConds.put(c.getCPF(), cont);
    }

    return MapUtil.ordenePorValor(infConds);
  }
 public Veiculo getVeiculoComPlaca(String placa) {
   return banco.getVeiculoComPlaca(placa);
 }
 public int getNVei() {
   return banco.getNVei();
 }
 public int getNInf() {
   return banco.getNInf();
 }
 public void addNInf() {
   banco.addNInf();
 }
 public Collection<String> getPlacas() {
   return banco.getPlacas();
 }
 public Collection<Long> getCpfs() {
   return banco.getCpfs();
 }
 public long getNCond() {
   return banco.getNCond();
 }
 public Infracao getInfracaoComNum(int numero) {
   return banco.getInfracaoComNumInf(numero);
 }
 public void salvarInfracoesAutomatico(Map<Integer, Infracao> mapa) {
   banco.addInfracoes(mapa);
 }
 public void salvarCondutoresAutomatico(Map<Long, Condutor> mapa) {
   banco.addCondutores(mapa);
 }
 public Condutor getCondutorComCpf(long cpf) {
   return banco.getCondutorComCpf(cpf);
 }
 public Collection<Condutor> getCondutores() {
   return banco.getCondutores();
 }
 public String[] retorneBancoSobreNomes() {
   return banco.getBancoDeSobreNomes();
 }
 public void salvarVeiculosAutomatico(Map<String, Veiculo> mapa) {
   banco.addVeiculos(mapa);
 }
 public Collection<Infracao> getInfracoes() {
   return banco.getInfracoes();
 }
 public boolean existeCondutores() {
   return !banco.getCondutores().isEmpty();
 }
 public boolean existeVeiculos() {
   return !banco.getVeiculos().isEmpty();
 }