-
-
Save Corical/2511cdc6d9d4ca55301ff906a786790c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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