Skip to content

Commit c9e0ae2

Browse files
mivekCopilot
andcommitted
refactor(entities): extract AbstractWeatherLayer to eliminate Icing/Turbulence duplication
- Create new abstract class AbstractWeatherLayer in model package - Fields: baseHeight (int), depth (int), unit (LengthUnit) with final getters/setters - Final toString() calling abstract appendIntensity() hook for subclass customization - Icing and Turbulence now extend AbstractWeatherLayer - Remove duplicated fields/getters/setters/toString from Icing and Turbulence - Implement protected void appendIntensity() in each subclass for intensity field - Reduces code duplication from 60% to 0% in these classes Fixes SonarCloud duplicated_lines_density quality gate failure on PR #796. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c99d57c commit c9e0ae2

3 files changed

Lines changed: 111 additions & 118 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package io.github.mivek.model;
2+
3+
import io.github.mivek.enums.LengthUnit;
4+
import io.github.mivek.internationalization.Messages;
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
7+
/**
8+
* Abstract base class for weather layers with height-based properties (icing, turbulence).
9+
* Defines common fields and behavior for layers characterized by base height, depth, and measurement unit.
10+
*
11+
* @author Jean-Kevin KPADEY
12+
*/
13+
public abstract class AbstractWeatherLayer {
14+
15+
/** The base limit of the layer. */
16+
private int baseHeight;
17+
/** The layer depth. */
18+
private int depth;
19+
/** The unit of the layer heights. */
20+
private LengthUnit unit;
21+
22+
/**
23+
* Returns the base height of the layer.
24+
*
25+
* @return the base height.
26+
*/
27+
public final int getBaseHeight() {
28+
return baseHeight;
29+
}
30+
31+
/**
32+
* Sets the base height of the layer.
33+
*
34+
* @param baseHeight the base height to set.
35+
*/
36+
public final void setBaseHeight(final int baseHeight) {
37+
this.baseHeight = baseHeight;
38+
}
39+
40+
/**
41+
* Returns the depth of the layer.
42+
* Add this to the baseHeight to determine the top limit of the layer conditions.
43+
*
44+
* @return the layer depth.
45+
*/
46+
public final int getDepth() {
47+
return depth;
48+
}
49+
50+
/**
51+
* Sets the depth of the layer.
52+
*
53+
* @param depth the depth to set.
54+
*/
55+
public final void setDepth(final int depth) {
56+
this.depth = depth;
57+
}
58+
59+
/**
60+
* Returns the unit of the layer heights.
61+
*
62+
* @return the unit of the heights.
63+
*/
64+
public final LengthUnit getUnit() {
65+
return unit;
66+
}
67+
68+
/**
69+
* Sets the unit of the layer heights.
70+
*
71+
* @param unit the unit to set.
72+
*/
73+
public final void setUnit(final LengthUnit unit) {
74+
this.unit = unit;
75+
}
76+
77+
/**
78+
* Appends intensity-specific information to the toString builder.
79+
* Implemented by subclasses to add their intensity field.
80+
*
81+
* @param builder the ToStringBuilder to append to.
82+
*/
83+
protected abstract void appendIntensity(final ToStringBuilder builder);
84+
85+
@Override
86+
public final String toString() {
87+
ToStringBuilder builder = new ToStringBuilder(this);
88+
appendIntensity(builder);
89+
return builder.
90+
append(Messages.getInstance().getString("ToString.baseHeight"), baseHeight).
91+
append(Messages.getInstance().getString("ToString.depth"), depth).
92+
append(Messages.getInstance().getString("ToString.height.unit"), unit).
93+
toString();
94+
}
95+
}
Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,38 @@
11
package io.github.mivek.model;
22

33
import io.github.mivek.enums.IcingIntensity;
4-
import io.github.mivek.enums.LengthUnit;
54
import io.github.mivek.internationalization.Messages;
65
import org.apache.commons.lang3.builder.ToStringBuilder;
76

87
/**
98
* Represents the icing of a TAF.
9+
*
1010
* @author Jean-Kevin KPADEY
1111
*/
12-
public final class Icing {
12+
public final class Icing extends AbstractWeatherLayer {
1313
/** The intensity of the icing. */
1414
private IcingIntensity intensity;
15-
/** The base of the icing layer. */
16-
private int baseHeight;
17-
/** The icing layer depth. */
18-
private int depth;
19-
/** The unit of the icing heights. */
20-
private LengthUnit unit;
2115

2216
/**
2317
* Returns the icing intensity.
18+
*
2419
* @return the icing intensity.
2520
*/
2621
public IcingIntensity getIntensity() {
2722
return intensity;
2823
}
2924

3025
/**
26+
* Sets the icing intensity.
27+
*
3128
* @param intensity The intensity to set.
3229
*/
3330
public void setIntensity(final IcingIntensity intensity) {
3431
this.intensity = intensity;
3532
}
3633

37-
/**
38-
* Returns the base of the icing layer.
39-
* @return the base of the icing layer.
40-
*/
41-
public int getBaseHeight() {
42-
return baseHeight;
43-
}
44-
45-
/**
46-
* @param baseHeight The base height to set.
47-
*/
48-
public void setBaseHeight(final int baseHeight) {
49-
this.baseHeight = baseHeight;
50-
}
51-
52-
/**
53-
* @return the icing layer depth.
54-
* Add this to the baseHeight to determine the top limit of the icing conditions.
55-
*/
56-
public int getDepth() {
57-
return depth;
58-
}
59-
60-
/**
61-
* @param depth The depth to set.
62-
*/
63-
public void setDepth(final int depth) {
64-
this.depth = depth;
65-
}
66-
67-
/**
68-
* @return the unit of the icing heights.
69-
*/
70-
public LengthUnit getUnit() {
71-
return unit;
72-
}
73-
74-
/**
75-
* @param unit The unit of the icing heights to set.
76-
*/
77-
public void setUnit(final LengthUnit unit) {
78-
this.unit = unit;
79-
}
80-
8134
@Override
82-
public String toString() {
83-
return new ToStringBuilder(this).
84-
append(Messages.getInstance().getString("ToString.intensity"), intensity).
85-
append(Messages.getInstance().getString("ToString.baseHeight"), baseHeight).
86-
append(Messages.getInstance().getString("ToString.depth"), depth).
87-
append(Messages.getInstance().getString("ToString.height.unit"), unit).
88-
toString();
35+
protected void appendIntensity(final ToStringBuilder builder) {
36+
builder.append(Messages.getInstance().getString("ToString.intensity"), intensity);
8937
}
9038
}
Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,38 @@
11
package io.github.mivek.model;
22

3-
import io.github.mivek.enums.LengthUnit;
43
import io.github.mivek.enums.TurbulenceIntensity;
54
import io.github.mivek.internationalization.Messages;
65
import org.apache.commons.lang3.builder.ToStringBuilder;
76

87
/**
98
* This class represents the Turbulence of a TAF.
10-
* @author Jean-Kevin KPADEY
9+
*
10+
* @author mivek
1111
*/
12-
public final class Turbulence {
12+
public final class Turbulence extends AbstractWeatherLayer {
1313
/** The intensity of the turbulence. */
1414
private TurbulenceIntensity intensity;
15-
/** The base limit of the turbulence layer. */
16-
private int baseHeight;
17-
/** The turbulence layer depth. */
18-
private int depth;
19-
/** The unit of the turbulence heights. */
20-
private LengthUnit unit;
2115

2216
/**
17+
* Returns the intensity of the turbulence.
18+
*
2319
* @return the intensity of the turbulence.
2420
*/
2521
public TurbulenceIntensity getIntensity() {
2622
return intensity;
2723
}
2824

2925
/**
26+
* Sets the intensity of the turbulence.
27+
*
3028
* @param intensity The intensity to set.
3129
*/
3230
public void setIntensity(final TurbulenceIntensity intensity) {
3331
this.intensity = intensity;
3432
}
3533

36-
/**
37-
* @return The base height of the turbulence layer.
38-
*/
39-
public int getBaseHeight() {
40-
return baseHeight;
41-
}
42-
43-
/**
44-
* @param baseHeight The base height to set.
45-
*/
46-
public void setBaseHeight(final int baseHeight) {
47-
this.baseHeight = baseHeight;
48-
}
49-
50-
/**
51-
* @return the turbulence layer depth.
52-
* Add it to the base height to determine the top limit of the turbulence conditions.
53-
*/
54-
public int getDepth() {
55-
return depth;
56-
}
57-
58-
/**
59-
* @param depth The turbulence layer depth to set.
60-
*/
61-
public void setDepth(final int depth) {
62-
this.depth = depth;
63-
}
64-
65-
/**
66-
* @return the unit of the turbulence heights.
67-
*/
68-
public LengthUnit getUnit() {
69-
return unit;
70-
}
71-
72-
/**
73-
* @param unit The unit of the turbulence heights to set.
74-
*/
75-
public void setUnit(final LengthUnit unit) {
76-
this.unit = unit;
77-
}
78-
7934
@Override
80-
public String toString() {
81-
return new ToStringBuilder(this).
82-
append(Messages.getInstance().getString("ToString.intensity"), intensity).
83-
append(Messages.getInstance().getString("ToString.baseHeight"), baseHeight).
84-
append(Messages.getInstance().getString("ToString.depth"), depth).
85-
append(Messages.getInstance().getString("ToString.height.unit"), unit).
86-
toString();
35+
protected void appendIntensity(final ToStringBuilder builder) {
36+
builder.append(Messages.getInstance().getString("ToString.intensity"), intensity);
8737
}
8838
}

0 commit comments

Comments
 (0)