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
class Day { | |
public final static Day MONDAY = new Day(); | |
public final static Day TUESDAY = new Day(); | |
public final static Day WEDNESDAY = new Day(); | |
} | |
class Month { | |
public final static Month JANUARY = new Month(); | |
public final static Month FEBRUARY = new Month(); | |
public final static Month MARCH = new Month(); |
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
interface Day { | |
int MONDAY = 1; | |
int TUESDAY = 2; | |
int WEDNESDAY = 3; | |
int THURSDAY = 4; | |
int FRIDAY = 5; | |
int SATURDAY = 6; | |
int SUNDAY = 7; | |
} |
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 EnumExample2 { | |
private final static int MONDAY = 1; | |
private final static int TUESDAY = 2; | |
private final static int WEDNESDAY = 3; | |
private final static int THURSDAY = 4; | |
private final static int FRIDAY = 5; | |
private final static int SATURDAY = 6; | |
private final static int SUNDAY = 7; |
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 EnumExample1 { | |
public static void main(String[] args) { | |
/* | |
* Monday == 1 | |
* Tuesday == 2 | |
* Wednesday == 3 | |
* Thursday == 4 | |
* ... | |
* Sunday == 7 | |
* */ |
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 PayGroups { | |
private List<Pay> pays; | |
public PayGroups(List<Pay> pays) { | |
this.pays = pays; | |
} | |
public Long getPayPalSum() return getTotalSum(pay -> PayType.isPayPal(pay.getPayType())); | |
public Long getVisaSum() return getTatalSum(pay -> PayType.isVisa(pay.getPayType())); |
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 void managingStateAndAction() { | |
List<Pay> pays = Arrays.asList( | |
new Pay(PAYPAL, 1000), | |
new Pay(VISA, 2000), | |
new Pay(MASTER_CARD, 3000), | |
new Pay(UNION_CARD, 5000) | |
); | |
Long totalSum = pays.stream().filter(pay -> pay.getPayType().equals(VISA)).mapToLong(Pay::getAmount).sum(); |
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 Orders { | |
private final List<Order> orders; | |
public Orders(List<Order> orders) { | |
this.orders = orders; | |
} | |
public long getAmountSum() { | |
return orders.stream() | |
.mapToLong(Order::getAmount) |
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 LottoTicket { | |
private static final int LOTTO_NUMBERS_SIZE = 6; | |
public LottoTicket(List<Long> lottoNumbers) { | |
List<Long> lottoNumbers = createNonDuplicateNumbers(); | |
validateSize(lottoNumbers); | |
validateDuplicate(lottoNumbers); | |
} | |
public void validateSize(List<Long> lottoNumbers) { |
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) { |
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) { |
NewerOlder