Skip to content

Commit 356db48

Browse files
committed
fix: clean-architecture logging deps and spotless formatting
1 parent ee699af commit 356db48

17 files changed

+90
-116
lines changed

Diff for: clean-architecture/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
<artifactId>junit-jupiter-engine</artifactId>
4040
<scope>test</scope>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.slf4j</groupId>
44+
<artifactId>slf4j-api</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>ch.qos.logback</groupId>
48+
<artifactId>logback-classic</artifactId>
49+
</dependency>
4250
</dependencies>
4351
<build>
4452
<plugins>

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/App.java

+10-15
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
import lombok.extern.slf4j.Slf4j;
44

55
/**
6-
* Clean Architecture ensures separation of concerns by organizing code,
7-
* into layers and making it scalable and maintainable.
6+
* Clean Architecture ensures separation of concerns by organizing code, into layers and making it
7+
* scalable and maintainable.
88
*
9-
* <p>In the example there are Entities (Core Models) – Product, Cart,
10-
* Order handle business logic.
11-
* Use Cases (Application Logic) – ShoppingCartService manages
12-
* operations like adding items and checkout.
13-
* Interfaces & Adapters – Repositories (CartRepository, OrderRepository)
14-
* abstract data handling,
15-
* while controllers (CartController, OrderController) manage interactions.
9+
* <p>In the example there are Entities (Core Models) – Product, Cart, Order handle business logic.
10+
* Use Cases (Application Logic) – ShoppingCartService manages operations like adding items and
11+
* checkout. Interfaces & Adapters – Repositories (CartRepository, OrderRepository) abstract data
12+
* handling, while controllers (CartController, OrderController) manage interactions.
1613
*/
1714
@Slf4j
1815
public final class App {
@@ -31,10 +28,8 @@ public static void main(final String[] args) {
3128
CartRepository cartRepository = new InMemoryCartRepository();
3229
OrderRepository orderRepository = new InMemoryOrderRepository();
3330

34-
ShoppingCartService
35-
shoppingCartUseCase =
36-
new ShoppingCartService(
37-
productRepository, cartRepository, orderRepository);
31+
ShoppingCartService shoppingCartUseCase =
32+
new ShoppingCartService(productRepository, cartRepository, orderRepository);
3833

3934
CartController cartController = new CartController(shoppingCartUseCase);
4035
OrderController orderController = new OrderController(shoppingCartUseCase);
@@ -46,7 +41,7 @@ public static void main(final String[] args) {
4641
Order order = orderController.checkout(userId);
4742
LOGGER.info("Total: ${}" + cartController.calculateTotal(userId));
4843

49-
LOGGER.info("Order placed! Order ID: {}, Total: ${}",
50-
order.getOrderId(), order.getTotalPrice());
44+
LOGGER.info(
45+
"Order placed! Order ID: {}, Total: ${}", order.getOrderId(), order.getTotalPrice());
5146
}
5247
}

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Cart.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@
2929
import lombok.Getter;
3030

3131
/**
32-
* Represents a shopping cart containing a product and its quantity.
33-
* This class calculates the total price of the product based on its price and quantity.
32+
* Represents a shopping cart containing a product and its quantity. This class calculates the total
33+
* price of the product based on its price and quantity.
3434
*/
3535
@Getter
3636
public class Cart {
37-
/**
38-
* The product in the cart.
39-
* It holds the product details such as name, price, and description.
40-
*/
37+
/** The product in the cart. It holds the product details such as name, price, and description. */
4138
private final Product product;
4239

4340
/**
44-
* The quantity of the product in the cart.
45-
* It represents how many units of the product are added to the cart.
41+
* The quantity of the product in the cart. It represents how many units of the product are added
42+
* to the cart.
4643
*/
4744
private final int quantity;
4845

@@ -58,13 +55,12 @@ public Cart(final Product prod, final int qty) {
5855
}
5956

6057
/**
61-
* Calculates the total price of the products in the cart.
62-
* The total price is the product's price multiplied by the quantity.
58+
* Calculates the total price of the products in the cart. The total price is the product's price
59+
* multiplied by the quantity.
6360
*
6461
* @return the total price of the products in the cart.
6562
*/
6663
public double getTotalPrice() {
6764
return product.getPrice() * quantity;
6865
}
69-
7066
}

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartController.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
/**
3131
* Controller class for handling shopping cart operations.
3232
*
33-
* <p>This class provides methods to add, remove, and calculate the
34-
* total price of items in a user's shopping cart.</p>
33+
* <p>This class provides methods to add, remove, and calculate the total price of items in a user's
34+
* shopping cart.
3535
*/
3636
public class CartController {
3737

38-
3938
/** Service layer responsible for cart operations. */
4039
private final ShoppingCartService shoppingCartUseCase;
4140

@@ -55,8 +54,7 @@ public CartController(final ShoppingCartService shoppingCart) {
5554
* @param productId The ID of the product to be added.
5655
* @param quantity The quantity of the product.
5756
*/
58-
public void addItemToCart(
59-
final String userId, final String productId, final int quantity) {
57+
public void addItemToCart(final String userId, final String productId, final int quantity) {
6058
shoppingCartUseCase.addItemToCart(userId, productId, quantity);
6159
}
6260

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartRepository.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828

2929
import java.util.List;
3030

31-
/**
32-
* CartRepository.
33-
*/
31+
/** CartRepository. */
3432
public interface CartRepository {
3533
/**
3634
* Adds an item to the user's cart.
@@ -40,27 +38,31 @@ public interface CartRepository {
4038
* @param quantity The quantity of the product.
4139
*/
4240
void addItemToCart(String userId, Product product, int quantity);
41+
4342
/**
4443
* Removes an item from the user's cart.
4544
*
4645
* @param userId The ID of the user.
4746
* @param productId The ID of the product to be removed.
4847
*/
4948
void removeItemFromCart(String userId, String productId);
49+
5050
/**
5151
* Retrieves the list of items in the user's cart.
5252
*
5353
* @param userId The ID of the user.
5454
* @return A list of items in the cart.
5555
*/
5656
List<Cart> getItemsInCart(String userId);
57+
5758
/**
5859
* Calculates the total price of the items in the user's cart.
5960
*
6061
* @param userId The ID of the user.
6162
* @return The total price of all items in the cart.
6263
*/
6364
double calculateTotal(String userId);
65+
6466
/**
6567
* Clears all items from the user's cart.
6668
*

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryCartRepository.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,21 @@
3434
/**
3535
* Implementation of {@link CartRepository} that stores cart items in memory.
3636
*
37-
* <p>This class maintains a map of user carts where each user has a
38-
* list of cart items.</p>
37+
* <p>This class maintains a map of user carts where each user has a list of cart items.
3938
*/
4039
public class InMemoryCartRepository implements CartRepository {
41-
/**
42-
* A map storing user carts with their respective cart items.
43-
*/
40+
/** A map storing user carts with their respective cart items. */
4441
private final Map<String, List<Cart>> userCarts = new HashMap<>();
4542

4643
/**
4744
* Adds an item to the user's cart.
4845
*
49-
* @param userId The ID of the user.
46+
* @param userId The ID of the user.
5047
* @param product The product to be added.
5148
* @param quantity The quantity of the product.
5249
*/
5350
@Override
54-
public void addItemToCart(
55-
final String userId, final Product product, final int quantity) {
51+
public void addItemToCart(final String userId, final Product product, final int quantity) {
5652
List<Cart> cart = userCarts.getOrDefault(userId, new ArrayList<>());
5753
cart.add(new Cart(product, quantity));
5854
userCarts.put(userId, cart);
@@ -91,8 +87,7 @@ public List<Cart> getItemsInCart(final String userId) {
9187
*/
9288
@Override
9389
public double calculateTotal(final String userId) {
94-
return userCarts.getOrDefault(userId, new ArrayList<>())
95-
.stream()
90+
return userCarts.getOrDefault(userId, new ArrayList<>()).stream()
9691
.mapToDouble(Cart::getTotalPrice)
9792
.sum();
9893
}

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryOrderRepository.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
/**
3333
* An in-memory implementation of the {@link OrderRepository}.
3434
*
35-
* <p>This class stores orders in a list, allowing orders to be saved
36-
* but not persisted beyond the application's runtime.</p>
35+
* <p>This class stores orders in a list, allowing orders to be saved but not persisted beyond the
36+
* application's runtime.
3737
*/
3838
public class InMemoryOrderRepository implements OrderRepository {
3939
/** A list to store orders in memory. */

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryProductRepository.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,28 @@
3232
/**
3333
* In-memory implementation of the {@link ProductRepository} interface.
3434
*
35-
* <p>This repository stores products in memory
36-
* allowing retrieval by product ID.</p>
35+
* <p>This repository stores products in memory allowing retrieval by product ID.
3736
*/
3837
public class InMemoryProductRepository implements ProductRepository {
39-
/**
40-
* A map to store products by their unique product ID.
41-
*/
38+
/** A map to store products by their unique product ID. */
4239
private final Map<String, Product> products = new HashMap<>();
40+
4341
/**
4442
* The price of the Laptop in USD.
45-
* <p>Used in the in-memory product repository
46-
* to define the cost of a Laptop.</p>
43+
*
44+
* <p>Used in the in-memory product repository to define the cost of a Laptop.
4745
*/
4846
private static final double LAPTOP_PRICE = 1000.0;
4947

5048
/**
5149
* The price of the Smartphone in USD.
52-
* <p>Used in the in-memory product repository
53-
* to define the cost of a Smartphone.</p>
50+
*
51+
* <p>Used in the in-memory product repository to define the cost of a Smartphone.
5452
*/
5553
private static final double SMARTPHONE_PRICE = 500.0;
5654

57-
5855
/**
59-
* Constructs an {@code InMemoryProductRepository} and
60-
* initializes it with some example products.
56+
* Constructs an {@code InMemoryProductRepository} and initializes it with some example products.
6157
*/
6258
public InMemoryProductRepository() {
6359
products.put("1", new Product("1", "Laptop", LAPTOP_PRICE));
@@ -68,8 +64,7 @@ public InMemoryProductRepository() {
6864
* Retrieves a product by its unique ID.
6965
*
7066
* @param productId The ID of the product to retrieve.
71-
* @return The {@link Product} corresponding to the given ID
72-
* {@code null} if not found.
67+
* @return The {@link Product} corresponding to the given ID {@code null} if not found.
7368
*/
7469
@Override
7570
public Product getProductById(final String productId) {

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Order.java

+10-16
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,27 @@
3030
import lombok.Getter;
3131

3232
/**
33-
* Represents an order placed by a user containing
34-
* the ordered items and total price.
33+
* Represents an order placed by a user containing the ordered items and total price.
3534
*
36-
* <p>An order includes a unique order ID, a list of cart items
37-
* and the total price of the order.</p>
35+
* <p>An order includes a unique order ID, a list of cart items and the total price of the order.
3836
*/
3937
@Getter
4038
public class Order {
41-
/**
42-
* The unique identifier for this order.
43-
*/
39+
/** The unique identifier for this order. */
4440
private final String orderId;
45-
/**
46-
* The list of items included in this order.
47-
*/
41+
42+
/** The list of items included in this order. */
4843
private final List<Cart> items;
49-
/**
50-
* The list of items included in this order.
51-
*/
44+
45+
/** The list of items included in this order. */
5246
private final double totalPrice;
5347

5448
/**
55-
* Constructs an {@code Order} with the given order ID and list of cart items.
56-
* The total price is based on the individual item prices in the cart.
49+
* Constructs an {@code Order} with the given order ID and list of cart items. The total price is
50+
* based on the individual item prices in the cart.
5751
*
5852
* @param id The unique identifier for the order.
59-
* @param item The list of cart items included in the order.
53+
* @param item The list of cart items included in the order.
6054
*/
6155
public Order(final String id, final List<Cart> item) {
6256
this.orderId = id;

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderController.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@
2929
/**
3030
* Controller for handling order-related operations.
3131
*
32-
* <p>This class provides an endpoint for users to checkout their cart
33-
* and place an order.</p>
32+
* <p>This class provides an endpoint for users to checkout their cart and place an order.
3433
*/
3534
public class OrderController {
36-
/**
37-
* Service for managing shopping cart operations.
38-
*/
35+
/** Service for managing shopping cart operations. */
3936
private final ShoppingCartService shoppingCartUseCase;
4037

41-
4238
/**
4339
* Constructs an {@code OrderController} with the given shopping cart service.
4440
*

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderRepository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Repository interface for managing order persistence.
3131
*
32-
* <p>This interface defines the contract for storing orders in the system.</p>
32+
* <p>This interface defines the contract for storing orders in the system.
3333
*/
3434
public interface OrderRepository {
3535
/**

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Product.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828

2929
import lombok.Getter;
3030

31-
/**
32-
* Represents a product in the system.
33-
*/
31+
/** Represents a product in the system. */
3432
@Getter
3533
public class Product {
3634
/** The unique identifier for the product. */

Diff for: clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ProductRepository.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
*/
2727
package com.iluwatar.cleanarchitecture;
2828

29-
/**
30-
* Repository interface for handling product-related operations.
31-
*/
29+
/** Repository interface for handling product-related operations. */
3230
public interface ProductRepository {
3331
/**
3432
* Retrieves a product by its unique identifier.

0 commit comments

Comments
 (0)