Created
September 5, 2021 02:45
-
-
Save wkdalsgh192/a5caa361b14281809c46ef3b2fed0e38 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