Skip to content

Commit 8ecdee4

Browse files
committed
iluwatar#1021 Checkstyle fixes for Layers
1 parent 47ae477 commit 8ecdee4

15 files changed

+69
-92
lines changed

layers/src/main/java/com/iluwatar/layers/App.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@
2626
import java.util.List;
2727

2828
/**
29-
*
30-
* Layers is an architectural style where software responsibilities are divided among the different layers of the
31-
* application.
32-
* <p>
33-
* This example demonstrates a traditional 3-layer architecture consisting of data access layer, business layer and
34-
* presentation layer.
35-
* <p>
36-
* The data access layer is formed of Spring Data repositories <code>CakeDao</code>, <code>CakeToppingDao</code> and
37-
* <code>CakeLayerDao</code>. The repositories can be used for CRUD operations on cakes, cake toppings and cake layers
38-
* respectively.
39-
* <p>
40-
* The business layer is built on top of the data access layer. <code>CakeBakingService</code> offers methods to
41-
* retrieve available cake toppings and cake layers and baked cakes. Also the service is used to create new cakes out of
42-
* cake toppings and cake layers.
43-
* <p>
44-
* The presentation layer is built on the business layer and in this example it simply lists the cakes that have been
45-
* baked.
46-
* <p>
47-
* We have applied so called strict layering which means that the layers can only access the classes directly beneath
48-
* them. This leads the solution to create an additional set of DTOs ( <code>CakeInfo</code>,
49-
* <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) to translate data between layers. In other words,
50-
* <code>CakeBakingService</code> cannot return entities ( <code>Cake</code>, <code>CakeTopping</code>,
51-
* <code>CakeLayer</code>) directly since these reside on data access layer but instead translates these into business
52-
* layer DTOs (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) and returns them
53-
* instead. This way the presentation layer does not have any knowledge of other layers than the business layer and thus
54-
* is not affected by changes to them.
29+
* Layers is an architectural style where software responsibilities are divided among the
30+
* different layers of the application.
31+
*
32+
* <p>This example demonstrates a traditional 3-layer architecture consisting of data access
33+
* layer, business layer and presentation layer.
34+
*
35+
* <p>The data access layer is formed of Spring Data repositories <code>CakeDao</code>,
36+
* <code>CakeToppingDao</code> and <code>CakeLayerDao</code>. The repositories can be used
37+
* for CRUD operations on cakes, cake toppings and cake layers respectively.
38+
*
39+
* <p>The business layer is built on top of the data access layer. <code>CakeBakingService</code>
40+
* offers methods to retrieve available cake toppings and cake layers and baked cakes. Also the
41+
* service is used to create new cakes out of cake toppings and cake layers.
42+
*
43+
* <p>The presentation layer is built on the business layer and in this example it simply lists
44+
* the cakes that have been baked.
45+
*
46+
* <p>We have applied so called strict layering which means that the layers can only access the
47+
* classes directly beneath them. This leads the solution to create an additional set of DTOs
48+
* ( <code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) to translate
49+
* data between layers. In other words, <code>CakeBakingService</code> cannot return entities
50+
* ( <code>Cake</code>, <code>CakeTopping</code>, <code>CakeLayer</code>) directly since these
51+
* reside on data access layer but instead translates these into business layer DTOs
52+
* (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) and returns
53+
* them instead. This way the presentation layer does not have any knowledge of other layers than
54+
* the business layer and thus is not affected by changes to them.
5555
*
5656
* @see Cake
5757
* @see CakeTopping
@@ -70,7 +70,7 @@ public class App {
7070
private static CakeBakingService cakeBakingService = new CakeBakingServiceImpl();
7171

7272
/**
73-
* Application entry point
73+
* Application entry point.
7474
*
7575
* @param args Command line parameters
7676
*/
@@ -85,7 +85,7 @@ public static void main(String[] args) {
8585
}
8686

8787
/**
88-
* Initializes the example data
88+
* Initializes the example data.
8989
*/
9090
private static void initializeData(CakeBakingService cakeBakingService) {
9191
cakeBakingService.saveNewLayer(new CakeLayerInfo("chocolate", 1200));
@@ -108,10 +108,10 @@ private static void initializeData(CakeBakingService cakeBakingService) {
108108
} catch (CakeBakingException e) {
109109
e.printStackTrace();
110110
}
111-
CakeInfo cake2 =
112-
new CakeInfo(new CakeToppingInfo("cherry", 0), List.of(
113-
new CakeLayerInfo("vanilla", 0), new CakeLayerInfo("lemon", 0), new CakeLayerInfo(
114-
"strawberry", 0)));
111+
CakeInfo cake2 = new CakeInfo(new CakeToppingInfo("cherry", 0), List.of(
112+
new CakeLayerInfo("vanilla", 0),
113+
new CakeLayerInfo("lemon", 0),
114+
new CakeLayerInfo("strawberry", 0)));
115115
try {
116116
cakeBakingService.bakeNewCake(cake2);
117117
} catch (CakeBakingException e) {

layers/src/main/java/com/iluwatar/layers/Cake.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
import javax.persistence.OneToOne;
3636

3737
/**
38-
*
39-
* Cake entity
40-
*
38+
* Cake entity.
4139
*/
4240
@Entity
4341
public class Cake {

layers/src/main/java/com/iluwatar/layers/CakeBakingException.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
package com.iluwatar.layers;
2525

2626
/**
27-
*
28-
* Custom exception used in cake baking
29-
*
27+
* Custom exception used in cake baking.
3028
*/
3129
public class CakeBakingException extends Exception {
3230

3331
private static final long serialVersionUID = 1L;
3432

35-
public CakeBakingException() {}
33+
public CakeBakingException() {
34+
}
3635

3736
public CakeBakingException(String message) {
3837
super(message);

layers/src/main/java/com/iluwatar/layers/CakeBakingService.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,37 @@
2626
import java.util.List;
2727

2828
/**
29-
*
30-
* Service for cake baking operations
31-
*
29+
* Service for cake baking operations.
3230
*/
3331
public interface CakeBakingService {
3432

3533
/**
36-
* Bakes new cake according to parameters
34+
* Bakes new cake according to parameters.
3735
*/
3836
void bakeNewCake(CakeInfo cakeInfo) throws CakeBakingException;
3937

4038
/**
41-
* Get all cakes
39+
* Get all cakes.
4240
*/
4341
List<CakeInfo> getAllCakes();
4442

4543
/**
46-
* Store new cake topping
44+
* Store new cake topping.
4745
*/
4846
void saveNewTopping(CakeToppingInfo toppingInfo);
4947

5048
/**
51-
* Get available cake toppings
49+
* Get available cake toppings.
5250
*/
5351
List<CakeToppingInfo> getAvailableToppings();
5452

5553
/**
56-
* Add new cake layer
54+
* Add new cake layer.
5755
*/
5856
void saveNewLayer(CakeLayerInfo layerInfo);
5957

6058
/**
61-
* Get available cake layers
59+
* Get available cake layers.
6260
*/
6361
List<CakeLayerInfo> getAvailableLayers();
6462
}

layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
import org.springframework.transaction.annotation.Transactional;
3838

3939
/**
40-
*
41-
* Implementation of CakeBakingService
42-
*
40+
* Implementation of CakeBakingService.
4341
*/
4442
@Service
4543
@Transactional
@@ -73,7 +71,8 @@ public void bakeNewCake(CakeInfo cakeInfo) throws CakeBakingException {
7371
}
7472
}
7573
CakeToppingDao toppingBean = context.getBean(CakeToppingDao.class);
76-
Optional<CakeTopping> topping = toppingBean.findById(matchingToppings.iterator().next().getId());
74+
Optional<CakeTopping> topping = toppingBean.findById(
75+
matchingToppings.iterator().next().getId());
7776
CakeDao cakeBean = context.getBean(CakeDao.class);
7877
if (topping.isPresent()) {
7978
Cake cake = new Cake();

layers/src/main/java/com/iluwatar/layers/CakeDao.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.springframework.stereotype.Repository;
2828

2929
/**
30-
*
31-
* CRUD repository for cakes
32-
*
30+
* CRUD repository for cakes.
3331
*/
3432
@Repository
3533
public interface CakeDao extends CrudRepository<Cake, Long> {

layers/src/main/java/com/iluwatar/layers/CakeInfo.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import java.util.Optional;
2828

2929
/**
30-
*
31-
* DTO for cakes
32-
*
30+
* DTO for cakes.
3331
*/
3432
public class CakeInfo {
3533

@@ -38,7 +36,7 @@ public class CakeInfo {
3836
public final List<CakeLayerInfo> cakeLayerInfos;
3937

4038
/**
41-
* Constructor
39+
* Constructor.
4240
*/
4341
public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
4442
this.id = Optional.of(id);
@@ -47,7 +45,7 @@ public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> ca
4745
}
4846

4947
/**
50-
* Constructor
48+
* Constructor.
5149
*/
5250
public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
5351
this.id = Optional.empty();
@@ -56,7 +54,7 @@ public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerIn
5654
}
5755

5856
/**
59-
* Calculate calories
57+
* Calculate calories.
6058
*/
6159
public int calculateTotalCalories() {
6260
int total = cakeToppingInfo != null ? cakeToppingInfo.calories : 0;

layers/src/main/java/com/iluwatar/layers/CakeLayer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import javax.persistence.ManyToOne;
3131

3232
/**
33-
*
34-
* CakeLayer entity
35-
*
33+
* CakeLayer entity.
3634
*/
3735
@Entity
3836
public class CakeLayer {
@@ -48,7 +46,8 @@ public class CakeLayer {
4846
@ManyToOne(cascade = CascadeType.ALL)
4947
private Cake cake;
5048

51-
public CakeLayer() {}
49+
public CakeLayer() {
50+
}
5251

5352
public CakeLayer(String name, int calories) {
5453
this.setName(name);

layers/src/main/java/com/iluwatar/layers/CakeLayerDao.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.springframework.stereotype.Repository;
2828

2929
/**
30-
*
31-
* CRUD repository for cake layers
32-
*
30+
* CRUD repository for cake layers.
3331
*/
3432
@Repository
3533
public interface CakeLayerDao extends CrudRepository<CakeLayer, Long> {

layers/src/main/java/com/iluwatar/layers/CakeLayerInfo.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import java.util.Optional;
2727

2828
/**
29-
*
30-
* DTO for cake layers
31-
*
29+
* DTO for cake layers.
3230
*/
3331
public class CakeLayerInfo {
3432

@@ -37,7 +35,7 @@ public class CakeLayerInfo {
3735
public final int calories;
3836

3937
/**
40-
* Constructor
38+
* Constructor.
4139
*/
4240
public CakeLayerInfo(Long id, String name, int calories) {
4341
this.id = Optional.of(id);
@@ -46,7 +44,7 @@ public CakeLayerInfo(Long id, String name, int calories) {
4644
}
4745

4846
/**
49-
* Constructor
47+
* Constructor.
5048
*/
5149
public CakeLayerInfo(String name, int calories) {
5250
this.id = Optional.empty();

layers/src/main/java/com/iluwatar/layers/CakeTopping.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import javax.persistence.OneToOne;
3131

3232
/**
33-
*
34-
* CakeTopping entity
35-
*
33+
* CakeTopping entity.
3634
*/
3735
@Entity
3836
public class CakeTopping {
@@ -48,7 +46,8 @@ public class CakeTopping {
4846
@OneToOne(cascade = CascadeType.ALL)
4947
private Cake cake;
5048

51-
public CakeTopping() {}
49+
public CakeTopping() {
50+
}
5251

5352
public CakeTopping(String name, int calories) {
5453
this.setName(name);

layers/src/main/java/com/iluwatar/layers/CakeToppingDao.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.springframework.stereotype.Repository;
2828

2929
/**
30-
*
31-
* CRUD repository cake toppings
32-
*
30+
* CRUD repository cake toppings.
3331
*/
3432
@Repository
3533
public interface CakeToppingDao extends CrudRepository<CakeTopping, Long> {

layers/src/main/java/com/iluwatar/layers/CakeToppingInfo.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import java.util.Optional;
2727

2828
/**
29-
*
30-
* DTO for cake toppings
31-
*
29+
* DTO for cake toppings.
3230
*/
3331
public class CakeToppingInfo {
3432

@@ -37,7 +35,7 @@ public class CakeToppingInfo {
3735
public final int calories;
3836

3937
/**
40-
* Constructor
38+
* Constructor.
4139
*/
4240
public CakeToppingInfo(Long id, String name, int calories) {
4341
this.id = Optional.of(id);
@@ -46,7 +44,7 @@ public CakeToppingInfo(Long id, String name, int calories) {
4644
}
4745

4846
/**
49-
* Constructor
47+
* Constructor.
5048
*/
5149
public CakeToppingInfo(String name, int calories) {
5250
this.id = Optional.empty();
@@ -56,6 +54,7 @@ public CakeToppingInfo(String name, int calories) {
5654

5755
@Override
5856
public String toString() {
59-
return String.format("CakeToppingInfo id=%d name=%s calories=%d", id.orElse(-1L), name, calories);
57+
return String.format("CakeToppingInfo id=%d name=%s calories=%d",
58+
id.orElse(-1L), name, calories);
6059
}
6160
}

layers/src/main/java/com/iluwatar/layers/CakeViewImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
31-
* View implementation for displaying cakes
32-
*
30+
* View implementation for displaying cakes.
3331
*/
3432
public class CakeViewImpl implements View {
3533

layers/src/main/java/com/iluwatar/layers/View.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.layers;
2525

2626
/**
27-
*
28-
* View interface
29-
*
27+
* View interface.
3028
*/
3129
public interface View {
3230

0 commit comments

Comments
 (0)