Advertisement
Mateus_Costa

Untitled

Apr 27th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.     private Set<Long> criaRepositorio() {
  2.         Set<Long> repositorio = new HashSet();
  3.        
  4.         Random r = new Random();
  5.         do {
  6.             repositorio.add(r.nextLong());
  7.         } while(repositorio.size() < this.nRepositorio);
  8.         return repositorio;
  9.     }
  10.  
  11.     @Override
  12.     public void adicionaColecao(Collection c) {
  13.         if(!this.colecoes.add(c)) {
  14.             throw new ColecaoRepetidaException("Colecao repetida!");
  15.         }
  16.     }
  17.  
  18.     @Override
  19.     public void setNumeroElementos(long n) {
  20.         this.nRepositorio = n;
  21.     }
  22.  
  23.     @Override
  24.     public void medeDesempenhoOperacaoBusca()
  25.             throws ColecaoNaoAdicionadaException {
  26.        
  27.         if(this.colecoes.size() == 0) {
  28.             throw new ColecaoNaoAdicionadaException("Colecao nao adicionada!");
  29.         }
  30.        
  31.         Set<Long> repositorio = this.criaRepositorio();
  32.         long tempoInicial, tempoFinal;
  33.        
  34.         for(Collection c : this.colecoes) {
  35.             c.addAll(repositorio);
  36.            
  37.             tempoInicial = System.currentTimeMillis();
  38.             for(Long valor : repositorio) {
  39.                 c.contains(valor);
  40.             }
  41.             tempoFinal = System.currentTimeMillis();
  42.             this.addResultado(c, "Busca", tempoInicial, tempoFinal);
  43.         }
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement