|
@@ -1,13 +1,16 @@
|
|
|
package data;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import IRC.Server;
|
|
|
import main.AffichableSurIRC;
|
|
|
import main.Cache;
|
|
|
+import main.Main;
|
|
|
|
|
|
public class ISP implements AffichableSurIRC {
|
|
|
-
|
|
|
+
|
|
|
private String name;
|
|
|
private int id;
|
|
|
private boolean isFFDNMember;
|
|
@@ -15,9 +18,18 @@ public class ISP implements AffichableSurIRC {
|
|
|
private String last_update;
|
|
|
private ISPdata data;
|
|
|
private CoveredAreas [] coveredAreas;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Constructeur principal de la classe.
|
|
|
+ * @param name
|
|
|
+ * @param id
|
|
|
+ * @param isFFDNMember
|
|
|
+ * @param date_added
|
|
|
+ * @param last_update
|
|
|
+ * @param data
|
|
|
+ * @param ca
|
|
|
+ */
|
|
|
+
|
|
|
public ISP(String name, int id, boolean isFFDNMember, String date_added, String last_update, ISPdata data, CoveredAreas [] ca) {
|
|
|
super();
|
|
|
this.name = name;
|
|
@@ -27,8 +39,15 @@ public class ISP implements AffichableSurIRC {
|
|
|
this.last_update = last_update;
|
|
|
this.data = data;
|
|
|
this.coveredAreas = ca;
|
|
|
+ for(int i=0; i<coveredAreas.length;++i) {
|
|
|
+ coveredAreas[i].setIsp(this);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Méthode pour récuperer le plus court des noms du FAI, c'est à dire, si il existe shortname, sinon name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public String getShortestName() {
|
|
|
if(data.hasShortName()) {
|
|
|
return data.getShortname();
|
|
@@ -36,7 +55,7 @@ public class ISP implements AffichableSurIRC {
|
|
|
return name;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Méthode pour récuperer le nom le plus correct pour afficher les informations.
|
|
|
* Si il n'y a pas de Shortname alors name sera utilisé.
|
|
@@ -56,7 +75,7 @@ public class ISP implements AffichableSurIRC {
|
|
|
}else {
|
|
|
return name;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
* Inverse de getBetterName. Le but est dans le cadre de l'affichage de plusieurs noms
|
|
@@ -70,12 +89,12 @@ public class ISP implements AffichableSurIRC {
|
|
|
}else {
|
|
|
return shortname;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}else {
|
|
|
return name;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void setName(String name) {
|
|
|
this.name = name;
|
|
|
}
|
|
@@ -105,7 +124,7 @@ public class ISP implements AffichableSurIRC {
|
|
|
this.isFFDNMember = isFFDNMember;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
public String getDate_added() {
|
|
|
return date_added;
|
|
|
}
|
|
@@ -133,7 +152,7 @@ public class ISP implements AffichableSurIRC {
|
|
|
public int getSubscribersCount() {
|
|
|
return data.getSubscribersCount();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public String toString() {
|
|
|
String res="";
|
|
|
res+=name+" : ";
|
|
@@ -141,20 +160,20 @@ public class ISP implements AffichableSurIRC {
|
|
|
res+="Nombre de membres: "+getMembersCount()+" Nombre d'abonnements:"+getSubscribersCount();
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private String booleanToOuiNon(boolean b) {
|
|
|
if(b) {
|
|
|
return "oui";
|
|
|
}
|
|
|
return "non";
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Renvoie une Liste de chaine de caractères pour permettre l'affichage sur IRC ligne par ligne, bien que le \n ne soit pas interprété.
|
|
|
* @return Une Liste de chaine correspondant à toutes les lignes que le bot doit écrire
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public List<String> toStringIRC () {
|
|
|
Cache c = Cache.getInstance();
|
|
|
List<String> res = new LinkedList<>();
|
|
@@ -167,11 +186,11 @@ public class ISP implements AffichableSurIRC {
|
|
|
res.add(preface+"Nombre de Membres : "+getMembersCount());
|
|
|
res.add(preface+"Nombre d'abonnements : "+getSubscribersCount());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private String getShortName() {
|
|
|
return data.getShortname();
|
|
|
}
|
|
@@ -180,5 +199,54 @@ public class ISP implements AffichableSurIRC {
|
|
|
return coveredAreas;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Récupere la zone couverte correspondante au paramètre
|
|
|
+ * @param name Nom de la zone
|
|
|
+ * @return la première Zone correspondante au nom.
|
|
|
+ */
|
|
|
+ public CoveredAreas getCoveredArea(String name) {
|
|
|
+ for(CoveredAreas ca : coveredAreas) {
|
|
|
+ if(ca.getName().equalsIgnoreCase(name)) {
|
|
|
+ return ca;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Récupere la zone couverte correspondante au paramètre
|
|
|
+ * @param name Nom de la zone
|
|
|
+ * @return toutes les Zones correspondante au nom.
|
|
|
+ */
|
|
|
+ public List<CoveredAreas> getCoveredAreas(String name){
|
|
|
+ List<CoveredAreas> lca = new ArrayList<>(4);
|
|
|
+ for(CoveredAreas ca : coveredAreas) {
|
|
|
+ if(ca.getName().equalsIgnoreCase(name)) {
|
|
|
+ lca.add(ca);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lca;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> contact() {
|
|
|
+ List<String> s = new ArrayList<>();
|
|
|
+ s.add( "["+this.getBetterName()+"] est joignable par:");
|
|
|
+ s.add("Site web: "+getData().getWebsite());
|
|
|
+ s.add("Mail: "+getData().emailSyntaxer());
|
|
|
+ String chats="Chat : ";
|
|
|
+ Server[] chans = getData().getIrcChan();
|
|
|
+ if(chans != null) {
|
|
|
+ for(int i=0; i<chans.length; i++) {
|
|
|
+ chats+=chans[i].toString()+" ";
|
|
|
+ }
|
|
|
+ s.add(chats);
|
|
|
+ } else {
|
|
|
+ if(Main.isDebug()) {
|
|
|
+ s.add("Chans a Null");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
}
|