-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathPeople.java
More file actions
67 lines (56 loc) · 1.63 KB
/
People.java
File metadata and controls
67 lines (56 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package io.zipcoder.interfaces;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public abstract class People<E extends Person> implements Iterable<E> {
List<E> personList = new ArrayList<E>();
public void add(E person) {
this.personList.add(person);
}
public E findById(Long id) {
E target = null;
for (E person: this.personList) {
if (person.getId().equals(id)) {
target = person;
break;
}
}
return target;
}
public Boolean contains(E person) {
Boolean exists = false;
for (E eachPerson: this.personList) {
if (eachPerson.getName().equals(person.getName())
&& eachPerson.getId().equals(person.getId())) {
exists = true;
break;
}
}
return exists;
}
public void remove(E person) {
if (this.contains(person)) {
this.personList.remove(person);
}
}
public void remove(Long id) {
E personToRemove = this.findById(id);
this.remove(personToRemove);
}
public void removeAll() {
this.personList = new ArrayList<E>();
}
public Integer count() {
return this.personList.size();
}
public abstract E[] toArray();
// Person[] personArray = new Person[this.count()];
// for (int i = 0; i < this.count(); i++) {
// personArray[i] = this.personList.get(i);
// }
// return personArray;
// }
public Iterator<E> iterator() {
return personList.iterator();
}
}