Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Corical/2511cdc6d9d4ca55301ff906a786790c to your computer and use it in GitHub Desktop.
Save Corical/2511cdc6d9d4ca55301ff906a786790c to your computer and use it in GitHub Desktop.
public class LottoService {
private static final int LOTTO_NUMBERS_SIZE = 6;
public void createLottoNumber() {
List<Long> lottoNumbers = createNonDuplicateNumbers();
validateSize(lottoNumbers);
validateDuplicate(lottoNumbers);
}
public void validateSize(List<Long> lottoNumbers) {
if (lottoNumbers.size() != LOTTO_NUMBERS_SIZE) {
throw new IllegalArgumentException("Only Six Numbers Allowed");
}
}
private void validateDuplicate(List<Long> lottoNumbers) {
Set<Long> nonDuplicateNumbers = new HashSet<>(lottoNumbers);
if (nonDuplicateNumbers.size() != LOTTO_NUMBERS_SIZE) {
throw new IllegalArgumentException("Numbers cannot be duplicate");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment