Skip to content
Snippets Groups Projects
Commit 2761eb73 authored by jonas.stirnema's avatar jonas.stirnema
Browse files

Modified dyn array and fixed contact

parent 73867e6a
No related branches found
No related tags found
No related merge requests found
......@@ -54,10 +54,10 @@ public class Contact {
}
public void setNames(List<String> names) {
if (!names.isEmpty() || (names.contains("") && (names.size() == 1))) {
this.names = names;
if (names.isEmpty() || (names.contains("") && (names.size() == 1))) {
this.names = new ArrayList<String>(Arrays.asList("Anoname"));
} else {
this.names = new ArrayList<String>(Arrays.asList("Anon"));
this.names = names;
}
}
......@@ -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("----------");
}
}
......@@ -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.intoString());
System.out.println(this.toString());
}
public String intoString() {
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);
......
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment