-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathPeople.java
More file actions
59 lines (45 loc) · 1.21 KB
/
People.java
File metadata and controls
59 lines (45 loc) · 1.21 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
package io.zipcoder.interfaces;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;
public class People<E extends Person>implements Iterable<E>{
List<E> personList;
public People () {
this.personList = new ArrayList<>();
}
public void add (E person) {
personList.add(person);
}
public E findById (long id) {
for (E person : personList) {
if (person.getId() == id) {
return person;
}
}
return null;
}
public Boolean containsPerson (E person) {
return personList.contains(person);
}
public void removePerson (E person) {
personList.remove(person);
}
public void removePerson (long id) {
personList.remove(findById(id));
}
public void removeAll () {
personList.removeAll(personList);
}
public Integer count () {
return personList.size();
}
public Array[] toArray () {
return (Array[]) personList.toArray();
}
public Iterator<E> iterator() {
return (Iterator<E>) personList.iterator();
}
}