Merge pull request #433 from atheedom/master
Some minor changes for style and to sync with code in article
This commit is contained in:
commit
55c43d5801
|
@ -8,24 +8,24 @@ import java.util.stream.Collectors;
|
||||||
public class Pizza {
|
public class Pizza {
|
||||||
|
|
||||||
private static EnumSet<PizzaStatusEnum> deliveredPizzaStatuses =
|
private static EnumSet<PizzaStatusEnum> deliveredPizzaStatuses =
|
||||||
EnumSet.of(PizzaStatusEnum.DELIVERED);
|
EnumSet.of(PizzaStatusEnum.DELIVERED);
|
||||||
|
|
||||||
private PizzaStatusEnum status;
|
private PizzaStatusEnum status;
|
||||||
|
|
||||||
public enum PizzaStatusEnum {
|
public enum PizzaStatusEnum {
|
||||||
ORDERED (5){
|
ORDERED(5) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isOrdered() {
|
public boolean isOrdered() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
READY (2){
|
READY(2) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DELIVERED (0){
|
DELIVERED(0) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isDelivered() {
|
public boolean isDelivered() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -34,16 +34,23 @@ public class Pizza {
|
||||||
|
|
||||||
private int timeToDelivery;
|
private int timeToDelivery;
|
||||||
|
|
||||||
public boolean isOrdered() {return false;}
|
public boolean isOrdered() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isReady() {return false;}
|
public boolean isReady() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDelivered() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isDelivered(){return false;}
|
|
||||||
public int getTimeToDelivery() {
|
public int getTimeToDelivery() {
|
||||||
return timeToDelivery;
|
return timeToDelivery;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PizzaStatusEnum (int timeToDelivery) {
|
PizzaStatusEnum(int timeToDelivery) {
|
||||||
this.timeToDelivery = timeToDelivery;
|
this.timeToDelivery = timeToDelivery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,10 +76,9 @@ public class Pizza {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumMap<PizzaStatusEnum, List<Pizza>> groupPizzaByStatus(List<Pizza> pzList) {
|
public static EnumMap<PizzaStatusEnum, List<Pizza>> groupPizzaByStatus(List<Pizza> pzList) {
|
||||||
EnumMap<PizzaStatusEnum, List<Pizza>> map = pzList.stream().collect(
|
return pzList.stream().collect(
|
||||||
Collectors.groupingBy(Pizza::getStatus,
|
Collectors.groupingBy(Pizza::getStatus,
|
||||||
() -> new EnumMap<PizzaStatusEnum, List<Pizza>>(PizzaStatusEnum.class), Collectors.toList()));
|
() -> new EnumMap<>(PizzaStatusEnum.class), Collectors.toList()));
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deliver() {
|
public void deliver() {
|
||||||
|
@ -81,4 +87,5 @@ public class Pizza {
|
||||||
this.setStatus(PizzaStatusEnum.DELIVERED);
|
this.setStatus(PizzaStatusEnum.DELIVERED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,9 +2,10 @@ package com.baeldung.enums;
|
||||||
|
|
||||||
|
|
||||||
public enum PizzaDeliverySystemConfiguration {
|
public enum PizzaDeliverySystemConfiguration {
|
||||||
INSTANCE ;
|
INSTANCE;
|
||||||
private PizzaDeliverySystemConfiguration() {
|
|
||||||
//Do the configuration initialization which
|
PizzaDeliverySystemConfiguration() {
|
||||||
|
// Do the configuration initialization which
|
||||||
// involves overriding defaults like delivery strategy
|
// involves overriding defaults like delivery strategy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
|
||||||
public class PizzaTest {
|
public class PizzaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPizaOrder_whenReady_thenDeliverable() {
|
public void givenPizaOrder_whenReady_thenDeliverable() {
|
||||||
Pizza testPz = new Pizza();
|
Pizza testPz = new Pizza();
|
||||||
|
@ -19,7 +20,7 @@ public class PizzaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPizaOrders_whenRetrievingUnDeliveredPzs_thenCorrectlyRetrieved() {
|
public void givenPizaOrders_whenRetrievingUnDeliveredPzs_thenCorrectlyRetrieved() {
|
||||||
List<Pizza> pzList = new ArrayList<Pizza>();
|
List<Pizza> pzList = new ArrayList<>();
|
||||||
Pizza pz1 = new Pizza();
|
Pizza pz1 = new Pizza();
|
||||||
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
|
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ public class PizzaTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenPizaOrders_whenGroupByStatusCalled_thenCorrectlyGrouped() {
|
public void givenPizaOrders_whenGroupByStatusCalled_thenCorrectlyGrouped() {
|
||||||
|
|
||||||
List<Pizza> pzList = new ArrayList<Pizza>();
|
List<Pizza> pzList = new ArrayList<>();
|
||||||
Pizza pz1 = new Pizza();
|
Pizza pz1 = new Pizza();
|
||||||
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
|
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
|
||||||
|
|
||||||
|
@ -75,4 +76,5 @@ public class PizzaTest {
|
||||||
pz.deliver();
|
pz.deliver();
|
||||||
assertTrue(pz.getStatus() == Pizza.PizzaStatusEnum.DELIVERED);
|
assertTrue(pz.getStatus() == Pizza.PizzaStatusEnum.DELIVERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue