package colecoes;

import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class Carta implements Comparable{
	private String naipe;
	private String numero;
	
	public Carta(String numero, String naipe){
		super();
		this.numero=numero;
		this.naipe=naipe;
	}
	
	public static void main(String[] args){
		Carta asDePaus=new Carta("A","U+2663");
		Carta asDePaus2=new Carta("A","U+2663");
		Carta seteDeCopas=new Carta("7","U+2661");
		Carta doisDeEspadas=new Carta("2","U+2663");
		
		
		Set<Carta> deck1=new HashSet<Carta>();
		deck1.add(asDePaus);
		deck1.add(doisDeEspadas);
		
		Set<Carta> deck2=new HashSet<Carta>();
		deck2.add(seteDeCopas);
		deck2.add(doisDeEspadas);
		
		System.out.println(deck1.contains(asDePaus2));
		System.out.println(deck2.contains(doisDeEspadas));
		
		deck2.retainAll(deck1);
		System.out.println(deck1.contains(seteDeCopas));
	}
	
	@Override
	public String toString() {
		return "Carta [naipe=" + naipe + ", numero=" + numero + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((naipe == null) ? 0 : naipe.hashCode());
		result = prime * result + ((numero == null) ? 0 : numero.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Carta other = (Carta) obj;
		if (naipe == null) {
			if (other.naipe != null)
				return false;
		} else if (!naipe.equals(other.naipe))
			return false;
		if (numero == null) {
			if (other.numero != null)
				return false;
		} else if (!numero.equals(other.numero))
			return false;
		return true;
	}

	
	@Override
	public int compareTo(Carta o) {
		int comp= this.numero.compareTo(o.numero);
		if(comp==0){
			Map<String, Integer> pesosNaipes= new HashMap<String, Integer>();
			pesosNaipes.put("♢", 1);
			pesosNaipes.put("♠", 2);
			pesosNaipes.put("♡", 3);
			pesosNaipes.put("♣", 4);
			Integer pesoDessaCarta= pesosNaipes.get(this.naipe);
			Integer pesoOutraCarta = pesosNaipes.get(o.naipe);
			return pesoDessaCarta.compareTo(pesoOutraCarta);
			
		}else{
			return comp;
		}
	}

 
}

@@ -149,16 +149,25 @@
 mparable
+%3CBaralho%3E
 %7B%0A%09priva
@@ -1741,29 +1741,16 @@
 ue;%0A%09%7D%0A%0A
-%09%0A%09@Override%0A
 %09public 
@@ -1774,16 +1774,17 @@
 ta o) %7B%0A
+%09
 %09%09int co
@@ -1820,16 +1820,17 @@
 umero);%0A
+%09
 %09%09if(com
@@ -1839,16 +1839,17 @@
 =0)%7B%0A%09%09%09
+%09
 Map%3CStri
@@ -1913,293 +1913,108 @@
 %0A%09%09%09
-pesosNaipes.put(%22%E2%99%A2%22, 1);%0A%09%09%09pesosNaipes.put(%22%E2%99%A0%22, 2);%0A%09%09%09pesosNaipes.put(%22%E2%99%A1%22, 3);%0A%09%09%09pesosNaipes.put(%22%E2%99%A3%22, 4);%0A%09%09%09Integer pesoDessaCarta= pesosNaipes.get(this.naipe);%0A%09%09%09Integer pesoOutraCarta = pesosNaipes.get(o.naipe);%0A%09%09%09return pesoDessaCarta.compareTo(pesoOutraCarta);%0A%09%09%09%0A%09%09%7Delse
+%09%0A%09%09%09%7Delse%7B%0A%09%09%09%09return comp;%0A%09%09%09%7D%0A%09%09%09return comp;%0A%09%7D%0A%0A%09@Override%0A%09public int compareTo(Baralho o) 
 %7B%0A
-%09
 %09%09re
@@ -2022,22 +2022,14 @@
 urn 
-comp
+0
 ;%0A
-%09
 %09%7D%0A%09
-%7D%0A%0A 
 %0A%7D%0A

Update Carta.java