Created
July 27, 2018 17:19
-
-
Save dieegorenan/40aadb32fd4f93a0ee012a07cfa8dd51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.atentatecnologia.mercado; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
public class MercadoEficiente implements Mercado { | |
private Map<String, PosicaoVendedor> mapaFonte = new HashMap<>(); | |
private Set<PosicaoVendedor> melhoresTaxas = new TreeSet<>((o1, o2) -> Double.compare(o2.getTaxa(), o1.getTaxa())); | |
@Override | |
public void atualizar(PosicaoVendedor pos) { | |
PosicaoVendedor posAnterior = mapaFonte.put(pos.getFonte(), pos); | |
if (posAnterior != null) { | |
melhoresTaxas.remove(posAnterior); | |
} | |
melhoresTaxas.add(pos); | |
} | |
@Override | |
public List<PosicaoVendedor> melhoresPosicoes(int quantidadePosicoesEsperada) { | |
return melhoresTaxas.stream().limit(quantidadePosicoesEsperada).collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment