-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathPeople.java
More file actions
56 lines (41 loc) · 1.14 KB
/
People.java
File metadata and controls
56 lines (41 loc) · 1.14 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
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<>();
public void addPerson (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 containsPerson (E person) {
return this.personList.contains(person);
}
public Integer count () {
return personList.size();
}
public void removePerson (E person){
personList.remove(person);
}
public void removePersonById (Long id) {
E personToRemove = findById(id);
removePerson(personToRemove);
}
public void removeAll (){
personList.clear();
}
public abstract E [] listToArray () ;
@Override
public Iterator<E> iterator() {
return this.personList.iterator();
}
}