-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGottaSnatchEmAll.java
More file actions
52 lines (42 loc) · 1.56 KB
/
Copy pathGottaSnatchEmAll.java
File metadata and controls
52 lines (42 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
class GottaSnatchEmAll {
static Set<String> newCollection(List<String> cards) {
return new HashSet<>(cards);
}
static boolean addCard(String card, Set<String> collection) {
return collection.add(card);
}
static boolean canTrade(Set<String> myCollection, Set<String> theirCollection) {
boolean TradeBool = false;
for (String theirCard : theirCollection){
for (String myCard : myCollection){
if (!myCollection.contains(theirCard) && !theirCollection.contains(myCard)){
TradeBool = true;
break;
}
}
}
return TradeBool && !myCollection.isEmpty() && !theirCollection.isEmpty();
}
static Set<String> commonCards(List<Set<String>> collections) {
Set<String> commonCardsSet = new HashSet();
if (!collections.isEmpty()){
Iterator<Set<String>> collectionsIterator = collections.iterator();
commonCardsSet.addAll(collectionsIterator.next());
while (collectionsIterator.hasNext()){
commonCardsSet.retainAll(collectionsIterator.next());
}
}
return commonCardsSet;
}
static Set<String> allCards(List<Set<String>> collections) {
Set<String> allCardsSet = new HashSet();
for ( Set<String> collection : collections){
allCardsSet.addAll(collection);
}
return allCardsSet;
}
}