diff --git a/2020-2021/TD1.ucls b/2020-2021/src/TD1/TD1.ucls similarity index 100% rename from 2020-2021/TD1.ucls rename to 2020-2021/src/TD1/TD1.ucls diff --git a/2020-2021/src/TD2/Canal.java b/2020-2021/src/TD2/Canal.java new file mode 100755 index 0000000..c41c971 --- /dev/null +++ b/2020-2021/src/TD2/Canal.java @@ -0,0 +1,70 @@ +package TD2; + +import java.util.ArrayList; +import java.util.List; + +public class Canal { + + private int maxMessage; + private String nomCanal; + private Forum forum; + private List lmsg = new ArrayList(); + + public Canal(String nc, int mm) { + this.setNomCanal(nc); + this.setMaxMessage(mm); + } + + public Canal(String nc) { + this(nc, 1000); + } + + public void addMessage(Message m) { + this.getLmsg().add(m); + } + + /** + * @return the maxMessage + */ + public int getMaxMessage() { + return maxMessage; + } + + /** + * @param maxMessage the maxMessage to set + */ + public void setMaxMessage(int maxMessage) { + this.maxMessage = maxMessage; + } + + /** + * @return the nomCanal + */ + public String getNomCanal() { + return nomCanal; + } + + /** + * @param nomCanal the nomCanal to set + */ + public void setNomCanal(String nomCanal) { + this.nomCanal = nomCanal; + } + + /** + * @return the lmsg + */ + public List getLmsg() { + return lmsg; + } + + /** + * @param lmsg the lmsg to set + */ + public void setLmsg(List lmsg) { + this.lmsg = lmsg; + } + + + +} diff --git a/2020-2021/src/TD2/Forum.java b/2020-2021/src/TD2/Forum.java index ba383f4..09191d2 100644 --- a/2020-2021/src/TD2/Forum.java +++ b/2020-2021/src/TD2/Forum.java @@ -11,7 +11,7 @@ public class Forum { private MessageManager mg; private ForumManager fm; private List member = new ArrayList(); - private List lmsg = new ArrayList(); + private List canaux = new ArrayList(); public Forum(String n) { @@ -27,8 +27,8 @@ public class Forum { return this.getMessageManager().createMessage(content, auth); } - public void addMessage(Message msg) { - this.lmsg.add(msg); + public void addMessage(Message msg, String nomCanal) { + this.getCanaux().get(getCanalId(nomCanal)).addMessage(msg); } public void createUser(String i) { @@ -77,17 +77,14 @@ public class Forum { this.nom = nom; } - public List getLmsg() { - return this.lmsg; - } - public List getLatestmsg(Member m) { + public List getLatestmsg(Member m, String canalName) { List l = new ArrayList(); - for (Message msg : this.getLmsg()) { - if(msg.getCreationDate().compareTo(Date.from(Instant.now() )) <= 10) { - l.add(msg); + for (Message msg : this.getCanaux().get(getCanalId(canalName)).getLmsg()) { + if(msg.getCreationDate().compareTo(Date.from(Instant.now() )) <= 10) { + l.add(msg); + } } - } m.lireMessage(l); return l; } @@ -136,5 +133,29 @@ public class Forum { return false; return true; } + + public int getCanalId(String nomCanal) { + int index = -1; + for(int i = 0; i < this.getCanaux().size(); i++) { + if(this.getCanaux().get(i).getNomCanal().equalsIgnoreCase(nomCanal)) { + index = i; + } + } + return index; + } + + /** + * @return the canal + */ + public List getCanaux() { + return canaux; + } + + /** + * @param canaux the canal to set + */ + public void setCanaux(List canaux) { + this.canaux = canaux; + } } diff --git a/2020-2021/src/TD2/ForumManager.java b/2020-2021/src/TD2/ForumManager.java index 1308104..d1f8f20 100644 --- a/2020-2021/src/TD2/ForumManager.java +++ b/2020-2021/src/TD2/ForumManager.java @@ -27,8 +27,8 @@ public class ForumManager { } else { //Si un forum avec ce nom existe déjà, il ne se passe rien. (On renvoi le Forum déjà existant return l.get(index); } - } - + } + public List getListeForum() { return this.l; } diff --git a/2020-2021/src/TD2/Internaute.java b/2020-2021/src/TD2/Internaute.java deleted file mode 100644 index 7b15374..0000000 --- a/2020-2021/src/TD2/Internaute.java +++ /dev/null @@ -1,14 +0,0 @@ -package TD2; - -public class Internaute { - - private String nom; - - public Internaute(String n) { - this.nom = n; - } - - public String getNom() { - return this.nom; - } -} diff --git a/2020-2021/src/TD2/TD2.ucls b/2020-2021/src/TD2/TD2.ucls new file mode 100644 index 0000000..76fb7ca --- /dev/null +++ b/2020-2021/src/TD2/TD2.ucls @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2020-2021/tests/TD2/ForumTest.java b/2020-2021/tests/TD2/ForumTest.java index b3acebb..81db4b9 100644 --- a/2020-2021/tests/TD2/ForumTest.java +++ b/2020-2021/tests/TD2/ForumTest.java @@ -1,7 +1,6 @@ package TD2; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; @@ -31,7 +30,10 @@ class ForumTest { Admin stade = new Admin("oogle-stade", fm.createForum("OGCN")); stade.getForum().setFm(fm); stade.getForum().createUser("unPseudo"); - + } + + @Test + void forumHasCanal() throws InterruptedException { }