Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ahmed mohammed BAGHAWITAH
TD-685
Commits
2417c928
Commit
2417c928
authored
Feb 09, 2021
by
sunye
Browse files
Suivi d'exercices de TD - groupe 685 - Initial commit
parent
4252da4a
Changes
14
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
2417c928
# Folder view configuration files
.DS_Store
Desktop.ini
# Thumbnail cache files
._*
Thumbs.db
# Files that might appear on external disks
.Spotlight-V100
.Trashes
# Java
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Gradle
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Cache of project
.gradletasknamecache
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
# IntelliJ
# Created by https://www.gitignore.io/api/intellij
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
.idea/
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
# End of https://www.gitignore.io/api/intellij
# Maven
**/target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
README.md
View file @
2417c928
# TD-685
# Travaux dirigés - Groupe 685
## Année 2020-21
pom.xml
0 → 100644
View file @
2417c928
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
fr.unantes.l3.construction
</groupId>
<artifactId>
sce-example
</artifactId>
<packaging>
jar
</packaging>
<version>
1.0-SNAPSHOT
</version>
<name>
sce-example
</name>
<url>
http://maven.apache.org
</url>
<properties>
<maven.compiler.source>
11
</maven.compiler.source>
<maven.compiler.target>
11
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
org.atlanmod.commons
</groupId>
<artifactId>
commons-core
</artifactId>
<version>
1.0.5
</version>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-api
</artifactId>
<version>
5.7.1
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
<version>
5.7.1
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.assertj
</groupId>
<artifactId>
assertj-core
</artifactId>
<version>
3.19.0
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
src/main/java/fr/unantes/l3/construction/Event.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
Event
{
private
final
AlarmWrapper
alarms
=
new
AlarmWrapper
();
public
AlarmWrapper
getAlarms
()
{
return
alarms
;
}
public
static
void
main
(
String
[]
args
)
{
Event
evt
=
new
Event
();
evt
.
getAlarms
().
addAlarm
(
Integer
.
valueOf
(
13
));
evt
.
getAlarms
().
addAlarm
(
Integer
.
valueOf
(
255
));
evt
.
getAlarms
().
removeAlarm
(
Integer
.
valueOf
(
13
));
}
}
class
AlarmWrapper
{
private
List
<
Integer
>
alarms
=
new
ArrayList
<>(
5
);
public
void
addAlarm
(
Integer
i
)
{
if
(
alarms
.
size
()
>=
5
)
throw
new
IllegalStateException
();
alarms
.
add
(
i
);
}
public
void
removeAlarm
(
Integer
i
)
{
alarms
.
remove
(
i
);
}
public
boolean
containsAlarm
(
Integer
i
)
{
return
alarms
.
contains
(
i
);
}
public
Iterator
<
Integer
>
alarmIterator
()
{
return
alarms
.
iterator
();
}
}
src/main/java/fr/unantes/l3/construction/Field.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction
;
public
class
Field
{
}
src/main/java/fr/unantes/l3/construction/Reference.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
public
class
Reference
<
T
>
{
private
Collection
<
T
>
contents
;
protected
Reference
(
Collection
<
T
>
contents
)
{
this
.
contents
=
contents
;
}
public
void
add
(
T
newElement
)
{
this
.
contents
.
add
(
newElement
);
}
public
void
remove
(
T
elementToRemove
)
{
this
.
contents
.
remove
(
elementToRemove
);
}
public
Iterator
<
T
>
iterator
()
{
return
this
.
contents
.
iterator
();
}
}
class
UniqueReference
<
T
>
extends
Reference
<
T
>
{
public
UniqueReference
()
{
super
(
new
HashSet
<>());
}
}
class
NonuniqueReference
<
T
>
extends
Reference
<
T
>
{
public
NonuniqueReference
()
{
super
(
new
LinkedList
<>());
}
}
\ No newline at end of file
src/main/java/fr/unantes/l3/construction/ReferenceToField.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction
;
import
java.util.*
;
public
class
ReferenceToField
{
private
Collection
<
Field
>
fields
=
new
LinkedList
<
Field
>();
public
void
add
(
Field
newField
)
{
this
.
fields
.
add
(
newField
);
}
public
void
remove
(
Field
fieldToRemove
)
{
this
.
fields
.
remove
(
fieldToRemove
);
}
public
Iterator
<
Field
>
iterator
()
{
return
this
.
fields
.
iterator
();
}
}
src/main/java/fr/unantes/l3/construction/Window.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
public
class
Window
{
private
final
Reference
<
Field
>
widgets
=
new
Reference
<>(
new
HashSet
<>());
public
Reference
<
Field
>
getWidgets
()
{
return
widgets
;
}
}
src/main/java/fr/unantes/l3/construction/exercice6/Action.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction.exercice6
;
public
class
Action
{
private
ReferenceToButton
button
=
new
ReferenceToButton
(
this
);
public
ReferenceToButton
button
()
{
return
button
;
}
}
src/main/java/fr/unantes/l3/construction/exercice6/Button.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction.exercice6
;
public
class
Button
{
private
ReferenceToAction
action
=
new
ReferenceToAction
(
this
);
public
ReferenceToAction
action
()
{
return
this
.
action
;
}
}
src/main/java/fr/unantes/l3/construction/exercice6/ReferenceToAction.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction.exercice6
;
import
java.util.Optional
;
public
class
ReferenceToAction
{
private
final
Button
container
;
private
Optional
<
Action
>
action
=
Optional
.
empty
();
public
ReferenceToAction
(
Button
container
)
{
this
.
container
=
container
;
}
public
boolean
isSet
()
{
return
action
.
isPresent
();
}
public
void
basicSet
(
Action
action
)
{
if
(
this
.
isSet
())
{
this
.
unSet
();
}
else
{
this
.
action
=
Optional
.
of
(
action
);
}
}
public
void
basicUnset
()
{
if
(
action
.
isPresent
())
{
action
=
Optional
.
empty
();
}
}
public
void
unSet
()
{
if
(
action
.
isPresent
())
{
action
.
get
().
button
().
basicUnset
();
this
.
basicUnset
();
}
}
public
void
set
(
Action
action
)
{
this
.
basicSet
(
action
);
action
.
button
().
basicSet
(
this
.
container
);
}
public
Action
get
()
{
return
action
.
get
();
}
}
src/main/java/fr/unantes/l3/construction/exercice6/ReferenceToButton.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction.exercice6
;
import
java.util.Optional
;
public
class
ReferenceToButton
{
private
final
Action
container
;
private
Optional
<
Button
>
button
=
Optional
.
empty
();
public
ReferenceToButton
(
Action
container
)
{
this
.
container
=
container
;
}
public
boolean
isSet
()
{
return
button
.
isPresent
();
}
public
void
basicSet
(
Button
button
)
{
if
(
this
.
isSet
())
{
this
.
unSet
();
}
else
{
this
.
button
=
Optional
.
of
(
button
);
}
}
public
void
basicUnset
()
{
if
(
button
.
isPresent
())
{
button
=
Optional
.
empty
();
}
}
public
void
unSet
()
{
// 1. Si button est nulll -> rien faire
// 2. si le button n'est pas null -> appeler unSet() de ReferenceToAction();
if
(
button
.
isPresent
())
{
button
.
get
().
action
().
basicUnset
();
this
.
basicUnset
();
}
}
public
void
set
(
Button
button
)
{
// 1 - Appeler basicSet local
// 2 - Appeler basicSet de button
this
.
basicSet
(
button
);
button
.
action
().
basicSet
(
this
.
container
);
}
public
Button
get
()
{
return
button
.
get
();
}
}
src/test/java/fr/unantes/l3/construction/TestWindow.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction
;
import
org.junit.jupiter.api.Test
;
import
java.util.Iterator
;
public
class
TestWindow
{
@Test
void
testWidgets
()
{
Window
w
=
new
Window
();
Field
f
=
new
Field
();
w
.
getWidgets
().
add
(
f
);
w
.
getWidgets
().
remove
(
f
);
Iterator
<
Field
>
it
=
w
.
getWidgets
().
iterator
();
while
(
it
.
hasNext
())
{
System
.
out
.
println
(
it
.
next
());
}
}
}
src/test/java/fr/unantes/l3/construction/exercice6/ActionTest.java
0 → 100644
View file @
2417c928
package
fr.unantes.l3.construction.exercice6
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
ActionTest
{
@Test
public
void
testHandshake
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
a1
.
button
().
set
(
b1
);
assertThat
(
b1
.
action
().
get
()).
isEqualTo
(
a1
);
}
}
\ No newline at end of file
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