Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contact_manager
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
SECOND
java
contact_manager
Commits
2761eb73
Commit
2761eb73
authored
2 years ago
by
jonas.stirnema
Browse files
Options
Downloads
Patches
Plain Diff
Modified dyn array and fixed contact
parent
73867e6a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Contact.java
+25
-11
25 additions, 11 deletions
src/Contact.java
src/DynArray.java
+12
-12
12 additions, 12 deletions
src/DynArray.java
src/Main.java
+5
-0
5 additions, 0 deletions
src/Main.java
with
42 additions
and
23 deletions
src/Contact.java
+
25
−
11
View file @
2761eb73
...
...
@@ -54,10 +54,10 @@ public class Contact {
}
public
void
setNames
(
List
<
String
>
names
)
{
if
(
!
names
.
isEmpty
()
||
(
names
.
contains
(
""
)
&&
(
names
.
size
()
==
1
)))
{
this
.
names
=
n
ames
;
if
(
names
.
isEmpty
()
||
(
names
.
contains
(
""
)
&&
(
names
.
size
()
==
1
)))
{
this
.
names
=
n
ew
ArrayList
<
String
>(
Arrays
.
asList
(
"Anoname"
))
;
}
else
{
this
.
names
=
n
ew
ArrayList
<
String
>(
Arrays
.
asList
(
"Anon"
))
;
this
.
names
=
n
ames
;
}
}
...
...
@@ -66,10 +66,10 @@ public class Contact {
}
public
void
setAddress
(
String
address
)
{
if
(!
address
.
isBlank
())
{
this
.
address
=
address
;
}
else
{
if
(
address
.
isBlank
())
{
this
.
address
=
"Nowhere"
;
}
else
{
this
.
address
=
address
;
}
}
...
...
@@ -78,8 +78,10 @@ public class Contact {
}
public
void
setPhoneNumbers
(
List
<
String
>
phoneNumbers
)
{
if
(
!
phoneNumbers
.
isEmpty
()
||
(
phoneNumbers
.
contains
(
""
)
&&
(
phoneNumbers
.
size
()
==
1
)))
{
if
(
phoneNumbers
.
isEmpty
()
||
(
phoneNumbers
.
contains
(
""
)
&&
(
phoneNumbers
.
size
()
==
1
)))
{
this
.
phoneNumbers
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"0102030405"
));
}
else
{
this
.
phoneNumbers
=
phoneNumbers
;
}
}
...
...
@@ -88,8 +90,10 @@ public class Contact {
}
public
void
setEmails
(
List
<
String
>
emails
)
{
if
(
!
emails
.
isEmpty
())
{
if
(
emails
.
isEmpty
()
||
(
emails
.
contains
(
""
)
&&
(
emails
.
size
()
==
1
))
)
{
this
.
emails
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"none@none.com"
));
}
else
{
this
.
emails
=
emails
;
}
}
...
...
@@ -98,10 +102,10 @@ public class Contact {
}
public
void
setSocials
(
List
<
String
>
socials
)
{
if
(
!
socials
.
isEmpty
())
{
this
.
socials
=
socials
;
if
(
socials
.
isEmpty
()
||
(
socials
.
contains
(
""
)
&&
(
socials
.
size
()
==
1
))
)
{
this
.
socials
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"@No_one"
))
;
}
else
{
this
.
socials
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"none@none.com"
))
;
this
.
socials
=
socials
;
}
}
...
...
@@ -147,7 +151,16 @@ public class Contact {
System
.
out
.
println
(
"Job : "
+
this
.
job
);
}
public
String
toShortString
()
{
return
this
.
fname
+
" "
+
this
.
names
.
get
(
0
);
}
public
void
showShort
()
{
System
.
out
.
println
(
this
.
toShortString
());
}
public
void
show
()
{
System
.
out
.
println
(
"----------"
);
showFname
();
showNames
();
showAddress
();
...
...
@@ -155,6 +168,7 @@ public class Contact {
showEmails
();
showSocials
();
showJob
();
System
.
out
.
println
(
"----------"
);
}
}
This diff is collapsed.
Click to expand it.
src/DynArray.java
+
12
−
12
View file @
2761eb73
...
...
@@ -3,22 +3,22 @@ public class DynArray {
private
final
int
basev
=
10
;
private
int
size
=
0
;
private
String
[]
array
;
private
Contact
[]
array
;
private
int
capacity
;
public
DynArray
(
String
[]
a
)
{
public
DynArray
(
Contact
[]
a
)
{
this
.
size
=
a
.
length
;
this
.
capacity
=
this
.
basev
;
this
.
array
=
new
String
[
this
.
capacity
];
this
.
array
=
new
Contact
[
this
.
capacity
];
copy_content
(
a
,
this
.
array
);
}
public
DynArray
()
{
this
.
array
=
new
String
[
this
.
capacity
];
this
.
array
=
new
Contact
[
this
.
capacity
];
this
.
size
=
0
;
}
public
void
append
(
String
[]
a
)
{
public
void
append
(
Contact
[]
a
)
{
make_sure_size
(
a
);
// REALLOC IF NEEDED
this
.
size
+=
a
.
length
;
int
s
=
this
.
size
;
...
...
@@ -38,12 +38,12 @@ public class DynArray {
this
.
size
--;
}
public
void
make_sure_size
(
String
[]
a
)
{
public
void
make_sure_size
(
Contact
[]
a
)
{
if
((
this
.
size
+
a
.
length
)
>
this
.
capacity
)
// Overflow?
{
// Realloc new array
this
.
capacity
*=
2
;
String
[]
new_arr
=
new
String
[
this
.
capacity
];
Contact
[]
new_arr
=
new
Contact
[
this
.
capacity
];
copy_content
(
this
.
array
,
new_arr
);
this
.
array
=
new_arr
;
// Copy pointer
...
...
@@ -51,15 +51,15 @@ public class DynArray {
}
public
void
show_it
()
{
System
.
out
.
println
(
this
.
in
toString
());
System
.
out
.
println
(
this
.
toString
());
}
public
String
in
toString
()
{
public
String
toString
()
{
String
s
=
""
;
for
(
int
i
=
0
;
i
<
this
.
size
;
i
++)
{
s
=
s
.
concat
(
array
[
i
]);
s
=
s
.
concat
(
",
"
);
s
=
s
.
concat
(
array
[
i
]
.
toShortString
()
);
s
=
s
.
concat
(
",
\n
"
);
}
return
s
;
}
...
...
@@ -68,7 +68,7 @@ public class DynArray {
return
size
==
0
;
}
private
static
void
copy_content
(
String
[]
source
,
String
[]
dest
)
{
private
static
void
copy_content
(
Contact
[]
source
,
Contact
[]
dest
)
{
// System.out.println("Source lenght" + source.length);
// System.out.println("Dest lenght" + dest.length);
...
...
This diff is collapsed.
Click to expand it.
src/Main.java
+
5
−
0
View file @
2761eb73
...
...
@@ -10,6 +10,11 @@ public class Main {
Arrays
.
asList
(
"@Jonas"
,
"@TPO"
),
"Eboueur"
);
Contact
c2
=
new
Contact
();
c1
.
show
();
c2
.
show
();
System
.
out
.
println
(
c1
.
toShortString
());
c2
.
showShort
();
}
}
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