Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2023 - R3.04 - TP1-Annuaire
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Clavier
2023 - R3.04 - TP1-Annuaire
Commits
6a8045e6
Commit
6a8045e6
authored
1 year ago
by
Fabien Delecroix
Browse files
Options
Downloads
Patches
Plain Diff
TODO restants supprimés
parent
99d9b517
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/devoo/tp07/PhoneBook.java
+0
-1
0 additions, 1 deletion
src/main/java/devoo/tp07/PhoneBook.java
src/main/java/devoo/tp07/PhoneNumber.java
+16
-57
16 additions, 57 deletions
src/main/java/devoo/tp07/PhoneNumber.java
with
16 additions
and
58 deletions
src/main/java/devoo/tp07/PhoneBook.java
+
0
−
1
View file @
6a8045e6
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/main/java/devoo/tp07/PhoneNumber.java
+
16
−
57
View file @
6a8045e6
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment