Skip to content

Commit

Permalink
convert shoppingList as static field and improve the get method to av…
Browse files Browse the repository at this point in the history
…oid lazily initialization
  • Loading branch information
jcarranzan committed Nov 15, 2023
1 parent ddf9024 commit eb0c75b
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
@Produces(MediaType.APPLICATION_JSON)
public class ShopResource {

private List<ShoppingList> shoppingList;
private static List<ShoppingList> shoppingList = createSampleProductList();

private List<ShoppingList> createSampleProductList() {
private static List<ShoppingList> createSampleProductList() {
shoppingList = new ArrayList<>();
shoppingList.add(new ShoppingList(UUID.randomUUID(), "ListName1", 25,
new ArrayList<>(Arrays.asList("Carrots", "Water", "Cheese", "Beer"))));
Expand All @@ -27,9 +27,6 @@ private List<ShoppingList> createSampleProductList() {

@GET
public List<ShoppingList> get() {
if (shoppingList == null) {
createSampleProductList();
}
return shoppingList;
}

Expand Down

0 comments on commit eb0c75b

Please sign in to comment.