Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP Train
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CELERIER Auguste
TP Train
Commits
4a2877a3
Commit
4a2877a3
authored
4 months ago
by
ACHARD Romain
Browse files
Options
Downloads
Patches
Plain Diff
Premier invariant
parent
3bf8c022
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/train/Element.java
+2
-5
2 additions, 5 deletions
src/train/Element.java
src/train/Section.java
+18
-0
18 additions, 0 deletions
src/train/Section.java
src/train/Station.java
+15
-0
15 additions, 0 deletions
src/train/Station.java
with
35 additions
and
5 deletions
src/train/Element.java
+
2
−
5
View file @
4a2877a3
...
@@ -4,11 +4,8 @@ package train;
...
@@ -4,11 +4,8 @@ package train;
* Cette classe abstraite est la représentation générique d'un élément de base d'un
* Cette classe abstraite est la représentation générique d'un élément de base d'un
* circuit, elle factorise les fonctionnalités communes des deux sous-classes :
* circuit, elle factorise les fonctionnalités communes des deux sous-classes :
* l'entrée d'un train, sa sortie et l'appartenance au circuit.<br/>
* l'entrée d'un train, sa sortie et l'appartenance au circuit.<br/>
* Les deux sous-classes sont :
*
* <ol>
*
* <li>La représentation d'une gare : classe {@link Station}</li>
* <li>La représentation d'une section de voie ferrée : classe {@link Section}</li>
* </ol>
*
*
* @author Fabien Dagnat <fabien.dagnat@imt-atlantique.fr>
* @author Fabien Dagnat <fabien.dagnat@imt-atlantique.fr>
* @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr>
* @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr>
...
...
This diff is collapsed.
Click to expand it.
src/train/Section.java
+
18
−
0
View file @
4a2877a3
...
@@ -8,7 +8,25 @@ package train;
...
@@ -8,7 +8,25 @@ package train;
* @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr>
* @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr>
*/
*/
public
class
Section
extends
Element
{
public
class
Section
extends
Element
{
private
Train
currentTrain
=
null
;
public
Section
(
String
name
)
{
public
Section
(
String
name
)
{
super
(
name
);
super
(
name
);
this
.
currentTrain
=
null
;
}
}
public
synchronized
void
enterSection
(
Train
t
)
throws
InterruptedException
{
while
(
currentTrain
!=
null
)
{
// Attendre que la section soit libre
wait
();
}
currentTrain
=
t
;
}
public
synchronized
void
leaveSection
(
Train
t
)
{
if
(
currentTrain
==
t
)
{
currentTrain
=
null
;
notifyAll
();
// Réveille les trains en attente
}
}
}
}
This diff is collapsed.
Click to expand it.
src/train/Station.java
+
15
−
0
View file @
4a2877a3
...
@@ -10,11 +10,26 @@ package train;
...
@@ -10,11 +10,26 @@ package train;
*/
*/
public
class
Station
extends
Element
{
public
class
Station
extends
Element
{
private
final
int
size
;
private
final
int
size
;
private
int
currentTrain
=
0
;
public
Station
(
String
name
,
int
size
)
{
public
Station
(
String
name
,
int
size
)
{
super
(
name
);
super
(
name
);
if
(
name
==
null
||
size
<=
0
)
if
(
name
==
null
||
size
<=
0
)
throw
new
NullPointerException
();
throw
new
NullPointerException
();
this
.
size
=
size
;
this
.
size
=
size
;
this
.
currentTrain
=
0
;
}
}
public
synchronized
void
enterStation
(
Train
t
)
throws
InterruptedException
{
while
(
currentTrain
>=
size
)
{
// Si la gare est pleine, attendre
wait
();
}
currentTrain
++;
}
public
synchronized
void
leaveStation
(
Train
t
)
{
currentTrain
--;
notifyAll
();
// Réveille les trains en attente
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment