Created
May 12, 2014 17:49
-
-
Save lucaspolo/b182726940a5d52bbe91 to your computer and use it in GitHub Desktop.
This file contains 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.alura.loja.dao; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.concurrent.atomic.AtomicLong; | |
import br.com.alura.loja.modelo.Carrinho; | |
import br.com.alura.loja.modelo.Produto; | |
public class CarrinhoDAO { | |
private static Map<Long, Carrinho> banco = new HashMap<Long, Carrinho>(); | |
private static AtomicLong contador = new AtomicLong(1); | |
static { | |
Produto videogame = new Produto(6237, "Videogame 4", 4000, 1); | |
Produto esporte = new Produto(3467, "Jogo de esporte", 60, 2); | |
Carrinho carrinho = new Carrinho() | |
.adiciona(videogame) | |
.adiciona(esporte) | |
.para("Rua Vergueiro 3185, 8 andar", "S�o Paulo") | |
.setId(1l); | |
banco.put(1l, carrinho); | |
} | |
public void adiciona(Carrinho carrinho) { | |
long id = contador.incrementAndGet(); | |
carrinho.setId(id); | |
banco.put(id, carrinho); | |
} | |
public Carrinho busca(Long id) { | |
return banco.get(id); | |
} | |
public Carrinho remove(long id) { | |
return banco.remove(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment