Commit 2417c928 authored by sunye's avatar sunye
Browse files

Suivi d'exercices de TD - groupe 685 - Initial commit

parent 4252da4a
# 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
# TD-685
# Travaux dirigés - Groupe 685
## Année 2020-21
<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>
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();
}
}
package fr.unantes.l3.construction;
public class Field {
}
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
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();
}
}
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;
}
}
package fr.unantes.l3.construction.exercice6;
public class Action {
private ReferenceToButton button = new ReferenceToButton(this);
public ReferenceToButton button() {
return button;
}
}
package fr.unantes.l3.construction.exercice6;
public class Button {
private ReferenceToAction action = new ReferenceToAction(this);
public ReferenceToAction action() {
return this.action;
}
}
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();
}
}
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();
}
}
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());
}
}
}
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment