codes.derive.foldem.board.AbstractBoard Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of foldem Show documentation
Show all versions of foldem Show documentation
A Texas Hold 'em Poker Analysis Framework for Java.
/*
* This file is part of Fold'em, a Java library for Texas Hold 'em Poker.
*
* Fold'em is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fold'em is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Fold'em. If not, see .
*/
package codes.derive.foldem.board;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import codes.derive.foldem.Card;
/**
* An abstract board that provides a basic {@link Board#cards()} implementation,
* using an {@link java.util.ArrayList } for backing.
*/
public abstract class AbstractBoard implements Board {
/* A list containing the cards on this board. */
private final List cards = new ArrayList<>();
/**
* Constructs a new board with the specified cards.
*
* @param cards
* The cards.
*/
public AbstractBoard(Card... cards) {
this.cards.addAll(Arrays.asList(cards));
}
@Override
public Collection cards() {
return Collections.unmodifiableCollection(cards);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cards == null) ? 0 : cards.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;
Board other = (Board) obj;
if (!cards.containsAll(other.cards()))
return false;
return true;
}
}