hmmm, can't seem to get keyset working

Working solution:

public void checkMatch(){
		boolean stop = true;
		for(CardHolder h: holders){
			System.out.println("Checking stack");
			
			if(topCards.size() > 2){ //means can never be a match
				stop = true;
			}
			else if(topCards.containsKey(h.topCard())){ //else no match add card(if contained update)
				Integer i = (Integer) topCards.get(h.topCard());
				int it = i.intValue();
				it++;
				Integer p = new Integer(it);
				topCards.put(h.topCard(),p);
				System.out.println("update existing card");
				System.out.println(""+topCards.get(h.topCard()));
				stop = false;
			}
			
			else{									//first time card added, add and put value as 1
				topCards.put(h.topCard(), 1);
				System.out.println("adding new card");
				stop = false;
			}
		}
		
		if(!stop){
			for(CardHolder h: holders){
				System.out.println("hello");
				Cards c = h.topCard();
				Integer i = (Integer) topCards.get(c);
				int in = i.intValue();
				if (in == (n-1)){
					player.add(h.takeTopCard()); 
					System.out.println("Matcha!");   	  
				}
			}
		}
		System.out.println("clearing hashtable");
		topCards.clear();
}

Glad to hear that it's working :)

At a glance I just found one thing that you can change to a nicer format:

int it = i.intValue();
it++;
Integer p = new Integer(it);
topCards.put(h.topCard(),p);

To

Integer p = new Integer(++i.intValue());
topCards.put(h.topCard(),p);

But it is not necessary. Glad we could help you :) please mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.