Commit a16e1395 authored by sunye's avatar sunye
Browse files

Add partial correction of ex. 7

parent c006308c
......@@ -31,15 +31,19 @@ public class ReferenceToAction {
public void unSet() {
if (action.isPresent()) {
action.get().button().basicUnset();
opposite(action.get()).basicUnset();
this.basicUnset();
}
}
private ReferenceToButton opposite(Action action) {
return action.button();
}
public void set(Action action) {
this.basicSet(action);
action.button().basicSet(this.container);
opposite(action).basicSet(this.container);
}
public Action get() {
......
package fr.unantes.l3.construction.exercice7;
public class Action {
}
package fr.unantes.l3.construction.exercice7;
public class Button {
}
package fr.unantes.l3.construction.exercice7;
import java.util.Optional;
public class ReferenceToOne<C, T> {
private final C container;
private Optional<T> target = Optional.empty();
public ReferenceToOne(C container) {
this.container = container;
}
public boolean isSet() {
return target.isPresent();
}
public void basicSet(T newTarget) {
if (this.isSet()) {
this.unSet();
} else {
this.target = Optional.of(newTarget);
}
}
public void basicUnset() {
if (target.isPresent()) {
target = Optional.empty();
}
}
public void unSet() {
if (target.isPresent()) {
opposite(target.get()).basicUnset();
this.basicUnset();
}
}
private ReferenceToOne<T, C> opposite(T target) {
return null;
//return target.button();
}
public void set(T newTarget) {
this.basicSet(newTarget);
opposite(newTarget).basicSet(this.container);
}
public T get() {
return target.get();
}
}
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