From 80ca7168c3ebab9576b9b7a7f41935ec07bb301d Mon Sep 17 00:00:00 2001 From: foussats Date: Mon, 23 Nov 2020 16:45:36 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9marrage=20codage=20chat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat/.classpath | 10 +++++ chat/.project | 17 ++++++++ chat/.settings/org.eclipse.jdt.core.prefs | 14 ++++++ chat/bin/model/Contact.class | Bin 0 -> 1085 bytes chat/bin/model/ListeContacts.class | Bin 0 -> 2090 bytes chat/bin/module-info.class | Bin 0 -> 143 bytes chat/bin/network/Tools.class | Bin 0 -> 756 bytes chat/src/model/Contact.java | 44 +++++++++++++++++++ chat/src/model/ListeContacts.java | 50 ++++++++++++++++++++++ chat/src/module-info.java | 2 + chat/src/network/Tools.java | 17 ++++++++ 11 files changed, 154 insertions(+) create mode 100644 chat/.classpath create mode 100644 chat/.project create mode 100644 chat/.settings/org.eclipse.jdt.core.prefs create mode 100644 chat/bin/model/Contact.class create mode 100644 chat/bin/model/ListeContacts.class create mode 100644 chat/bin/module-info.class create mode 100644 chat/bin/network/Tools.class create mode 100644 chat/src/model/Contact.java create mode 100644 chat/src/model/ListeContacts.java create mode 100644 chat/src/module-info.java create mode 100644 chat/src/network/Tools.java diff --git a/chat/.classpath b/chat/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/chat/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/chat/.project b/chat/.project new file mode 100644 index 0000000..517a7cf --- /dev/null +++ b/chat/.project @@ -0,0 +1,17 @@ + + + chat + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/chat/.settings/org.eclipse.jdt.core.prefs b/chat/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/chat/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=13 diff --git a/chat/bin/model/Contact.class b/chat/bin/model/Contact.class new file mode 100644 index 0000000000000000000000000000000000000000..839935e5378936a8d7d4744a987470eb526e1dda GIT binary patch literal 1085 zcmZ{i-EPxB5QWb=sht?NNljv!Lg^1JBrd|&2viAGAR$G76qI|%Sp`?FUD+F+3nU^W zE_eVQ3Nd55O-bAvdv^Bt%(rL#=kKrI0A8YRKoi)!Or|pO&XZXAfih4RXkYkWeJ}Fk znfGyWAp<3#UuAMWO$6-Wa&x58FrK}l-Awsvo(UNKbehVHDyPuJQhD#`@uujr_H`JC z>P+CYziw6i(O@i4KPOBRHEdZh(GsZj2jeCLwk>Qx=jy(N2AU0Y1sZSTgD9NElKT%V z7|;b;!!VW~=9d$he)cDk=}D3; zCEbei@kvawDdP~>x%OEP$|SEFU9U7-m9ZgnjraoSo*3Y|Hb==k4dlC!k7|_{{DQ9! zhZIYVeu5e_PLC>$Gs@qTA-xS!n7Btzi&g>cv%c&8#HM??K-+!3fbH6y1)T5sXFK$C z$PCy*9W63xQ?-o_Z1kvmP#9nr4{1eK`CyS(JW``kkFZw`^ytld8}1LZzfqxq2k3dT zn;Tk%pfnVCjD6}b?HQ>xR_CNkJTve1Xz*_C;1sGGB)vou1j`Ar*KH7c6=bgxR@@jpL>pTzpyo8=`KW@LuU-FweD_jjIi&i(73-+l*h4UaU01Uidu z-YTRQ?6PmoxsGq<{IZ6KK>N12Yo-gPvzflLv2Epifk>rnc>-+io4M6xpaq7^!gj2sN^!&TR?Uq9!^alfoLR`4o-M!C zrj9T=H1tuY1}W+2MTd;}iUAE#-s^AKWr3DW%b!1@?nxxi;MQ}VW%|}#rD{A;Q$#7g z;(NBUnMr0fToO26r?-wPxT;~8`;O&5a=o4Os_PcY1`aY|;{0u*5op@2cH}N!tH5!VSIN`%)INGr2k51D|IfH^ z?A@w>+7UqquZpQCM$HEo6-pmo#cM&l%jyJ(?4k1qb>A^T{D`0#11eRCeuI%ELE8a_ z)>6OV@;*{8Fm?=}tK9mC+<)ToHl#5@Hz9j8xcpmMMz}YT`Uw}Rczx+RTparqZwvf^ zp~cZEZjA81ikYW47kSQ;4+NgQ{5$-dK4B$QH&qAIiZi84OzH~P<9x)VbOTC=i6Cj- zf{&H7akOKBs}L4x)rHVYmMEe@Xmr##q39#u67B?)-;hyOYbr&W0$hzZP5H z$LD((Q-}{@8&y20B45R(%!a0gds34cXH4Ze%pSPP_c%cfQi`#=7Ws&ADqxgkEc7H1 g+%rI)o&{1m4dVR=WQ-u=#7Gll^8bQV$P~ivzec#f#{d8T literal 0 HcmV?d00001 diff --git a/chat/bin/module-info.class b/chat/bin/module-info.class new file mode 100644 index 0000000000000000000000000000000000000000..39fbb61038bdfcc9d1f0471451de6fd34bef3424 GIT binary patch literal 143 zcmX^0Z`VEs1_nz8E_MbcMh5QO{FKt1RNc(Hw0uSeuHgLAqU2P!%$!t41_2}~y{yEt zL`DWSU$AOn26jdUmgJ1Y5@7~TMg~rhq+U{DacTnt10&FI2w-Ah1~Ql!SQuD=v={>$ NSeTK4qXEo-5C9``8z%q& literal 0 HcmV?d00001 diff --git a/chat/bin/network/Tools.class b/chat/bin/network/Tools.class new file mode 100644 index 0000000000000000000000000000000000000000..9a6622b249963ff41807c14da73c73cfc9be232f GIT binary patch literal 756 zcmZuv+invv5Is)QIN5HRHf=+>ly0Fw5)k{0f{;)}Mb&VTQu6NXn$*q4j&>aie^qz@ z!~-9|M-UeJ0G{9xM}eWLrM)!iC_FPJ$vBD(8yDh(2os@) z;hVvQj4VUxsnW_mV_0dn`V7S*6H5;(sQ6e#iJ{h2TE3o+2QobqgG4gayCxDzU!=!{IqBP(y2v@ OgdB51VQ7 listeContact; + + + //la liste doit être un singleton + + private static final ListeContacts instance = new ListeContacts(); + + private ListeContacts() { + this.listeContact = new ArrayList(); + } + + public static final ListeContacts getInstance() { + return instance; + } + + public static void createUser(String pseudo) { + user = new Contact(pseudo, Tools.getLocalIp()); + } + + public boolean contactExist(Contact contact) { + for(Contact c : listeContact) { + if(c.getPseudo().equals(contact.getPseudo())){ + return true; + } + } + return false; + } + + public void addContact(Contact contact) { + if(!contactExist(contact)){ + System.out.println("Pseudo : "+user.getPseudo()+"ajouté\n"); + listeContact.add(contact); + } + } + + public void deleteContact(Contact contact) { + if(contactExist(contact)){ + System.out.println("Pseudo : "+user.getPseudo()+"supprimé\n"); + listeContact.remove(contact); + } + } +} diff --git a/chat/src/module-info.java b/chat/src/module-info.java new file mode 100644 index 0000000..b70f100 --- /dev/null +++ b/chat/src/module-info.java @@ -0,0 +1,2 @@ +module chat { +} \ No newline at end of file diff --git a/chat/src/network/Tools.java b/chat/src/network/Tools.java new file mode 100644 index 0000000..0fd246d --- /dev/null +++ b/chat/src/network/Tools.java @@ -0,0 +1,17 @@ +package network; +import java.net.*; + +public class Tools { + + public static InetAddress getLocalIp(){ + try{ + InetAddress address = InetAddress.getLocalHost(); + return address; + } + catch (UnknownHostException e){ + System.out.println ("Could not find local address!"); + } + return null; + } +} +