Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tok-chef
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Antoine HAZEBROUCK
tok-chef
Commits
46d9a61d
Commit
46d9a61d
authored
Sep 13, 2024
by
Antoine Hazebrouck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor ingredients
parent
fa03581c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
79 additions
and
150 deletions
+79
-150
Application.java
src/main/java/imt/Application.java
+1
-0
Autre.java
src/main/java/imt/ingredients/Autre.java
+9
-26
Epice.java
src/main/java/imt/ingredients/Epice.java
+9
-16
Ingredient.java
src/main/java/imt/ingredients/Ingredient.java
+10
-52
Legume.java
src/main/java/imt/ingredients/Legume.java
+11
-26
ViandePoisson.java
src/main/java/imt/ingredients/ViandePoisson.java
+13
-30
IngredientTest.java
src/test/java/imt/ingredients/IngredientTest.java
+26
-0
No files found.
src/main/java/imt/Application.java
View file @
46d9a61d
...
@@ -3,6 +3,7 @@ package imt;
...
@@ -3,6 +3,7 @@ package imt;
import
imt.ingredients.Consigne
;
import
imt.ingredients.Consigne
;
import
imt.ingredients.Ingredient
;
import
imt.ingredients.Ingredient
;
import
imt.ingredients.Legume
;
import
imt.ingredients.Legume
;
import
imt.ingredients.Plat
;
import
imt.ingredients.ViandePoisson
;
import
imt.ingredients.ViandePoisson
;
public
class
Application
{
public
class
Application
{
...
...
src/main/java/imt/ingredients/Autre.java
View file @
46d9a61d
package
imt
.
ingredients
;
package
imt
.
ingredients
;
public
class
Autre
extends
Ingredient
{
import
lombok.Data
;
private
int
calories
;
import
lombok.EqualsAndHashCode
;
private
boolean
bio
;
public
Autre
(
int
idIngredient
,
String
nomIngredient
,
int
calories
,
boolean
bio
)
{
super
(
idIngredient
,
nomIngredient
);
this
.
calories
=
calories
;
this
.
bio
=
bio
;
}
public
int
getCalories
()
{
return
calories
;
}
public
void
setCalories
(
int
calories
)
{
@EqualsAndHashCode
(
callSuper
=
true
)
this
.
calories
=
calories
;
@Data
}
public
class
Autre
extends
Ingredient
{
public
boolean
getBio
()
{
return
bio
;
}
public
void
setBio
(
boolean
bio
)
{
public
Autre
(
int
idIngredient
,
String
nomIngredient
,
int
quantit
é
,
int
calories
,
boolean
bio
,
this
.
bio
=
bio
;
Consigne
[]
consignes
)
{
}
super
(
idIngredient
,
nomIngredient
,
quantit
é
,
calories
,
bio
,
consignes
);
}
public
String
toString
()
{
return
super
.
toString
()
+
" Autre [calories="
+
calories
+
", bio="
+
bio
+
"]"
;
}
}
}
src/main/java/imt/ingredients/Epice.java
View file @
46d9a61d
package
imt
.
ingredients
;
package
imt
.
ingredients
;
public
class
Epice
extends
Ingredient
{
import
lombok.Data
;
private
Boolean
bio
;
import
lombok.EqualsAndHashCode
;
public
Epice
(
int
idIngredient
,
String
nomIngredient
,
Boolean
bio
)
{
@EqualsAndHashCode
(
callSuper
=
true
)
super
(
idIngredient
,
nomIngredient
);
@Data
this
.
bio
=
bio
;
public
class
Epice
extends
Ingredient
{
}
public
Boolean
getBio
()
{
public
Epice
(
int
idIngredient
,
String
nomIngredient
,
int
quantit
é
,
int
calories
,
boolean
bio
,
return
bio
;
Consigne
[]
consignes
)
{
}
super
(
idIngredient
,
nomIngredient
,
quantit
é
,
0
,
bio
,
consignes
);
}
public
void
setBio
(
Boolean
bio
)
{
this
.
bio
=
bio
;
}
public
String
toString
()
{
return
super
.
toString
()
+
" Epice [bio="
+
bio
+
"]"
;
}
}
}
src/main/java/imt/ingredients/Ingredient.java
View file @
46d9a61d
package
imt
.
ingredients
;
package
imt
.
ingredients
;
public
class
Ingredient
{
import
lombok.Data
;
private
int
idIngredient
;
private
String
nomIngredient
;
@Data
private
int
quantit
é
;
public
abstract
class
Ingredient
{
private
Consigne
[]
consignes
;
private
final
int
idIngredient
;
private
final
String
nomIngredient
;
public
Ingredient
(
int
idIngredient
,
String
nomIngredient
)
{
private
final
int
quantit
é
;
this
.
idIngredient
=
idIngredient
;
private
final
int
calories
;
this
.
nomIngredient
=
nomIngredient
;
private
final
boolean
bio
;
this
.
quantit
é
=
0
;
private
final
Consigne
[]
consignes
;
this
.
consignes
=
null
;
}
public
int
getIdIngredient
()
{
return
idIngredient
;
}
public
void
setIdIngredient
(
int
idIngredient
)
{
this
.
idIngredient
=
idIngredient
;
}
public
String
getNomIngredient
()
{
return
nomIngredient
;
}
public
void
setNomIngredient
(
String
nomIngredient
)
{
this
.
nomIngredient
=
nomIngredient
;
}
public
int
getQuantit
é
()
{
return
quantit
é
;
}
public
void
setQuantit
é
(
int
quantit
é
)
{
this
.
quantit
é
=
quantit
é
;
}
public
Consigne
[]
getConsignes
()
{
return
consignes
;
}
public
void
setConsignes
(
Consigne
[]
consignes
)
{
this
.
consignes
=
consignes
;
}
public
String
toString
()
{
String
strConsigne
=
""
;
for
(
int
i
=
0
;
i
<
consignes
.
length
;
i
++)
{
strConsigne
+=
consignes
[
i
].
toString
()+
", "
;
}
return
"Ingredient [idIngredient="
+
idIngredient
+
", nomIngredient="
+
nomIngredient
+
", Consignes="
+
strConsigne
+
"]"
;
}
}
}
src/main/java/imt/ingredients/Legume.java
View file @
46d9a61d
package
imt
.
ingredients
;
package
imt
.
ingredients
;
public
class
Legume
extends
Ingredient
{
import
lombok.Data
;
private
int
calories
;
import
lombok.EqualsAndHashCode
;
private
boolean
bio
;
public
Legume
(
int
idIngredient
,
String
nomIngredient
,
int
calories
,
boolean
bio
)
{
@EqualsAndHashCode
(
callSuper
=
true
)
super
(
idIngredient
,
nomIngredient
);
@Data
this
.
calories
=
calories
;
public
class
Legume
extends
Ingredient
{
this
.
bio
=
bio
;
private
final
int
fibres
;
}
public
int
getCalories
()
{
public
Legume
(
int
idIngredient
,
String
nomIngredient
,
int
quantit
é
,
int
calories
,
boolean
bio
,
return
calories
;
Consigne
[]
consignes
,
int
fibres
)
{
}
super
(
idIngredient
,
nomIngredient
,
quantit
é
,
calories
,
bio
,
consignes
);
this
.
fibres
=
fibres
;
}
public
void
setCalories
(
int
calories
)
{
this
.
calories
=
calories
;
}
public
boolean
getBio
()
{
return
bio
;
}
public
void
setBio
(
boolean
bio
)
{
this
.
bio
=
bio
;
}
public
String
toString
()
{
return
super
.
toString
()
+
" Legume [calories="
+
calories
+
", bio="
+
bio
+
"]"
;
}
}
}
src/main/java/imt/ingredients/ViandePoisson.java
View file @
46d9a61d
package
imt
.
ingredients
;
package
imt
.
ingredients
;
public
class
ViandePoisson
extends
Ingredient
{
import
lombok.Data
;
private
int
calories
;
import
lombok.EqualsAndHashCode
;
private
int
gras
;
@EqualsAndHashCode
(
callSuper
=
true
)
public
ViandePoisson
(
int
idIngredient
,
String
nomIngredient
,
int
calories
,
int
gras
)
{
@Data
super
(
idIngredient
,
nomIngredient
);
public
class
ViandePoisson
extends
Ingredient
{
this
.
calories
=
calories
;
private
final
int
gras
;
this
.
gras
=
gras
;
}
public
ViandePoisson
(
int
idIngredient
,
String
nomIngredient
,
int
quantit
é
,
int
calories
,
boolean
bio
,
Consigne
[]
consignes
,
int
gras
)
{
public
int
getCalories
()
{
super
(
idIngredient
,
nomIngredient
,
quantit
é
,
calories
,
bio
,
consignes
);
return
calories
;
this
.
gras
=
gras
;
}
}
public
void
setCalories
(
int
calories
)
{
this
.
calories
=
calories
;
}
public
int
getGras
()
{
return
gras
;
}
public
void
setGras
(
int
gras
)
{
this
.
gras
=
gras
;
}
public
String
toString
()
{
return
super
.
toString
()
+
" Viande/Poisson [calories="
+
calories
+
", gras="
+
gras
+
"]"
;
}
}
}
\ No newline at end of file
src/test/java/imt/ingredients/IngredientTest.java
0 → 100644
View file @
46d9a61d
package
imt
.
ingredients
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.junit.jupiter.api.Test
;
public
class
IngredientTest
{
public
static
final
Ingredient
STEAK
=
new
ViandePoisson
(
1
,
"steak"
,
1
,
10
,
true
,
null
,
0
);
public
static
final
Ingredient
OIGNON
=
new
Legume
(
2
,
"oignon"
,
1
,
20
,
true
,
null
,
0
);
public
static
final
Ingredient
AUTRE
=
new
Autre
(
3
,
"autre"
,
1
,
30
,
false
,
null
);
@Test
void
epice_apportent_zero_calories
()
{
Ingredient
epice
=
new
Epice
(
1
,
"poivre"
,
1
,
10
,
false
,
null
);
assertThat
(
epice
.
getCalories
()).
isEqualTo
(
0
);
}
@Test
void
le_reste_apporte_des_calories
()
{
assertThat
(
STEAK
.
getCalories
()).
isEqualTo
(
10
);
assertThat
(
OIGNON
.
getCalories
()).
isEqualTo
(
20
);
assertThat
(
AUTRE
.
getCalories
()).
isEqualTo
(
30
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment