Merge pull request #433 from atheedom/master

Some minor changes for style and to sync with code in article
This commit is contained in:
Alex Theedom 2016-06-01 00:04:40 +03:00
commit 55c43d5801
3 changed files with 27 additions and 17 deletions

View File

@ -8,24 +8,24 @@ import java.util.stream.Collectors;
public class Pizza {
private static EnumSet<PizzaStatusEnum> deliveredPizzaStatuses =
EnumSet.of(PizzaStatusEnum.DELIVERED);
EnumSet.of(PizzaStatusEnum.DELIVERED);
private PizzaStatusEnum status;
public enum PizzaStatusEnum {
ORDERED (5){
ORDERED(5) {
@Override
public boolean isOrdered() {
return true;
}
},
READY (2){
READY(2) {
@Override
public boolean isReady() {
return true;
}
},
DELIVERED (0){
DELIVERED(0) {
@Override
public boolean isDelivered() {
return true;
@ -34,16 +34,23 @@ public class Pizza {
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() {
return timeToDelivery;
}
private PizzaStatusEnum (int timeToDelivery) {
PizzaStatusEnum(int timeToDelivery) {
this.timeToDelivery = timeToDelivery;
}
}
@ -69,10 +76,9 @@ public class Pizza {
}
public static EnumMap<PizzaStatusEnum, List<Pizza>> groupPizzaByStatus(List<Pizza> pzList) {
EnumMap<PizzaStatusEnum, List<Pizza>> map = pzList.stream().collect(
Collectors.groupingBy(Pizza::getStatus,
() -> new EnumMap<PizzaStatusEnum, List<Pizza>>(PizzaStatusEnum.class), Collectors.toList()));
return map;
return pzList.stream().collect(
Collectors.groupingBy(Pizza::getStatus,
() -> new EnumMap<>(PizzaStatusEnum.class), Collectors.toList()));
}
public void deliver() {
@ -81,4 +87,5 @@ public class Pizza {
this.setStatus(PizzaStatusEnum.DELIVERED);
}
}
}

View File

@ -2,9 +2,10 @@ package com.baeldung.enums;
public enum PizzaDeliverySystemConfiguration {
INSTANCE ;
private PizzaDeliverySystemConfiguration() {
//Do the configuration initialization which
INSTANCE;
PizzaDeliverySystemConfiguration() {
// Do the configuration initialization which
// involves overriding defaults like delivery strategy
}

View File

@ -10,6 +10,7 @@ import java.util.List;
import static junit.framework.TestCase.assertTrue;
public class PizzaTest {
@Test
public void givenPizaOrder_whenReady_thenDeliverable() {
Pizza testPz = new Pizza();
@ -19,7 +20,7 @@ public class PizzaTest {
@Test
public void givenPizaOrders_whenRetrievingUnDeliveredPzs_thenCorrectlyRetrieved() {
List<Pizza> pzList = new ArrayList<Pizza>();
List<Pizza> pzList = new ArrayList<>();
Pizza pz1 = new Pizza();
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
@ -44,7 +45,7 @@ public class PizzaTest {
@Test
public void givenPizaOrders_whenGroupByStatusCalled_thenCorrectlyGrouped() {
List<Pizza> pzList = new ArrayList<Pizza>();
List<Pizza> pzList = new ArrayList<>();
Pizza pz1 = new Pizza();
pz1.setStatus(Pizza.PizzaStatusEnum.DELIVERED);
@ -75,4 +76,5 @@ public class PizzaTest {
pz.deliver();
assertTrue(pz.getStatus() == Pizza.PizzaStatusEnum.DELIVERED);
}
}