I am creating a game of set and in the game I have an object called cards which takes in the attributes of each card. After each card is created I am sending it to an ArrayList which is then put into a LinkedHashSet, the ArrayList is then cleared and then the LinkedHashSet is added back into the ArrayList. After the for loop is done, I add each index of the ArrayList to a queue. I was under the impression that a LinkedHashSet doesn't allow duplicates however I am still getting them. I have tried many different ways using two queues, or two ArrayLists, or a queue and an ArrayList. The most recent way I tried was with the LinkedHashSet and now I am really puzzeled. Attached is my for loop that determines each card attribute and the Cards class which creates each card. Any help would be greatly appreciated.
For loop to make card Attributes
for(int i = queue.size(); i < 81; i++) {
randomColor = ThreadLocalRandom.current().nextInt(0, 2+1);
randomNum = ThreadLocalRandom.current().nextInt(0, 2+1);
randomPattern = ThreadLocalRandom.current().nextInt(0, 2+1);
randomShape = ThreadLocalRandom.current().nextInt(0, 2+1);
cardColor = color[randomColor];
cardShape = shape[randomShape];
num = number[randomNum];
cardPattern = pattern[randomPattern];
cardInfo[0] = num;
cardInfo[1] = cardColor;
cardInfo[2] = cardPattern;
cardInfo[3] = cardShape;
info = new Cards(num, cardColor, cardPattern, cardShape);
cardHolder.add(info);
hashSet.addAll(cardHolder);
cardHolder.clear();
cardHolder.addAll(hashSet);
}
Cards Class:
public class Cards {
private int number;
private String color;
private String pattern;
private String shape;
public Cards(int number, String color, String pattern, String shape) {
this.number = number;
this.color = color;
this.pattern = pattern;
this.shape = shape;
}
public int getNumber() {
return number;
}
public String getShape() {
return shape;
}
public String getColor() {
return color;
}
public String getPattern() {
return pattern;
}
public void setNumber(int number) {
this.number = number;
}
public void setColor(String color) {
this.color = color;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
public void setShape(String shape) {
this.shape = shape;
}
public String toString() {
return number + "," + color + "," + pattern + "," + shape;
}
}