Skip to content
Snippets Groups Projects
Commit 6a8045e6 authored by Fabien Delecroix's avatar Fabien Delecroix
Browse files

TODO restants supprimés

parent 99d9b517
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@ package devoo.tp07;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
* @author Antoine Nongaillard, Fabien Delecroix
......
package devoo.tp07;
import java.util.Arrays;
/**
* @author Antoine Nongaillard, Fabien Delecroix
* Un {@literal}{PhoneNumber} contient les informations d'un numéro de téléphone en incluant son indicatif de pays.
......@@ -10,13 +8,13 @@ import java.util.Arrays;
public class PhoneNumber{
/** Code du pays, par exemple 33 pour la France */
protected final int countryCode;
protected final int COUNTRY_CODE;
/** Code de la zone, par exemple 3 pour les hauts de France */
protected final int areaCode;
protected final int AREA_CODE;
/** Code du secteur, par exemple 20 pour Lille et alentours*/
protected final int sectorCode;
protected final int SECTOR_CODE;
/** Trois derniers duos de chiffres */
protected final int[] lastOnes = new int[3];
protected final int[] LAST_ONES = new int[3];
/** Code indicatif de pays pour la France */
......@@ -43,12 +41,12 @@ public class PhoneNumber{
* @param three le dernier des 3 duos de chiffre finaux
*/
public PhoneNumber(int country, int area, int sector, int one, int two, int three) {
this.countryCode = country;
this.areaCode = area;
this.sectorCode = sector;
this.lastOnes[0] = one;
this.lastOnes[1] = two;
this.lastOnes[2] = three;
this.COUNTRY_CODE = country;
this.AREA_CODE = area;
this.SECTOR_CODE = sector;
this.LAST_ONES[0] = one;
this.LAST_ONES[1] = two;
this.LAST_ONES[2] = three;
}
/**
......@@ -58,11 +56,11 @@ public class PhoneNumber{
public String standardFormat() {
StringBuilder res = new StringBuilder();
res.append('0');
res.append(this.areaCode);
res.append(this.AREA_CODE);
res.append('.');
if(this.sectorCode<10) res.append('0');
res.append(this.sectorCode);
for (int num : lastOnes){
if(this.SECTOR_CODE<10) res.append('0');
res.append(this.SECTOR_CODE);
for (int num : LAST_ONES){
res.append('.');
if(num<10) res.append('0');
res.append(num);
......@@ -77,7 +75,7 @@ public class PhoneNumber{
public String internationalFormat() {
StringBuilder res = new StringBuilder();
res.append('+');
res.append(this.countryCode);
res.append(this.COUNTRY_CODE);
res.append('.');
res.append(this.standardFormat().substring(1));
return res.toString();
......@@ -92,49 +90,10 @@ public class PhoneNumber{
* @see #countryCodeReference
*/
public String toString() {
if (this.countryCode == PhoneNumber.countryCodeReference)
if (this.COUNTRY_CODE == PhoneNumber.countryCodeReference)
return standardFormat();
else
return internationalFormat();
}
//pour corrigé uniquement, TODO : retirer dans sujet
/**
* Compare le numéro de téléphone à l'objet donné
* @param obj l'objet avec lequel comparer ce {@code PhoneNumber}
* @return {@code true} si l'objet donné est un numéro de téléphone composé des mêmes indicatifs et numéros, {@code false} sinon
*/
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof PhoneNumber))
return false;
PhoneNumber other = (PhoneNumber) obj;
if (countryCode != other.countryCode)
return false;
if (areaCode != other.areaCode)
return false;
if (sectorCode != other.sectorCode)
return false;
if (!Arrays.equals(lastOnes, other.lastOnes))
return false;
return true;
}
//pour corrigé uniquement, TODO : retirer dans sujet
/**
* Retourne une valeur de hachage pour ce numéro de téléphone en se basant sur l'ensemble des informations qui le composent
* @return la valeur de hachage du numéro de téléphone
*/
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + countryCode;
result = prime * result + areaCode;
result = prime * result + sectorCode;
result = prime * result + Arrays.hashCode(lastOnes);
return result;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment