Unverified Commit 5c09014b authored by Mathieu Gicquel's avatar Mathieu Gicquel
Browse files

Implements association between Task -- Context - fix #8

parent 31af6704
package fr.alma.gtd.server.core;
public interface SingleReference<T> {
void set(T newValue);
T get();
void unset();
boolean isSet();
void basicSet(T newValue);
void basicUnSet();
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package fr.alma.gtd.server.main.donnees;
import fr.alma.gtd.server.core.IContext;
import fr.alma.gtd.server.core.IParticipant;
import fr.alma.gtd.server.core.MultipleReference;
import java.util.Date;
......@@ -10,9 +11,17 @@ public class Context implements IContext {
private String nom;
private String idServeur;
private MultipleReference<Task> tasks;
public Context() {
this.tasks = new ReferenceContextToTasks(this);
}
public Context(IContext autre) {
this();
this.nom = autre.getName();
this.idServeur = autre.getServerIdentifier();
}
@Override
......@@ -54,4 +63,8 @@ public class Context implements IContext {
public void setLastModificationDate(Date lastModificationDate) {
}
public MultipleReference<Task> getTaskReference() {
return this.tasks;
}
}
package fr.alma.gtd.server.main.donnees;
import fr.alma.gtd.server.core.ITask;
import fr.alma.gtd.server.core.MultipleReference;
import java.util.ArrayList;
import java.util.List;
public class ReferenceContextToTasks implements MultipleReference<Task> {
Context c;
List<Task> tasks;
public ReferenceContextToTasks(Context c) {
this.c = c;
tasks = new ArrayList<>();
}
@Override
public boolean add(Task value) {
if(value.getContextReference().isSet()) value.getContextReference().unset();
value.getContextReference().basicSet(c);
basicAdd(value);
return true;
}
@Override
public void remove(Task value) {
if(value.getContextReference().isSet() && this.contains(value)) value.getContextReference().unset();
this.basicRemove(value);
}
@Override
public boolean contains(Task value) {
return this.tasks.contains(value);
}
@Override
public int size() {
return this.tasks.size();
}
@Override
public void basicAdd(Task value) {
this.tasks.add(value);
}
@Override
public void basicRemove(Task value) {
this.tasks.remove(value);
}
}
package fr.alma.gtd.server.main.donnees;
import fr.alma.gtd.server.core.IContext;
import fr.alma.gtd.server.core.SingleReference;
public class ReferenceTaskToContext implements SingleReference<Context> {
Task t;
Context c;
public ReferenceTaskToContext(Task t) {
this.t = t;
}
@Override
public void set(Context newValue) {
if(this.isSet()) this.unset();
newValue.getTaskReference().add(t);
this.basicSet(newValue);
}
@Override
public Context get() {
return this.c;
}
@Override
public void unset() {
if(this.isSet()) this.c.getTaskReference().basicRemove(this.t);
this.basicUnSet();
}
@Override
public boolean isSet() {
return this.c!=null;
}
@Override
public void basicSet(Context newValue) {
this.c = newValue;
}
@Override
public void basicUnSet() {
this.c = null;
}
}
......@@ -15,9 +15,11 @@ public class Task implements ITask {
private Date debut,fin;
private ReferenceToTags tags;
private SingleReference<Context> context;
public Task() {
tags = new ReferenceToTags();
context = new ReferenceTaskToContext(this);
}
public Task(ITask autre) {
......@@ -174,12 +176,16 @@ public class Task implements ITask {
@Override
public IContext getContext() {
return null;
return this.context.get();
}
@Override
public void setContext(IContext c) {
public SingleReference<Context> getContextReference() {
return this.context;
}
@Override
public void setContext(IContext c) throws ClassCastException{
this.context.set((Context) c);
}
@Override
......
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