-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathPeople.java
More file actions
48 lines (36 loc) · 1010 Bytes
/
People.java
File metadata and controls
48 lines (36 loc) · 1010 Bytes
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
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 add(E person){
personList.add(person);
}
public E findById(Long id){
for (E person : personList) {
Long currentId = person.getId();
boolean isSameId = currentId.equals(id);
if (isSameId)
return person;
}
return null;
}
public void remove(E person){
personList.remove(person);
}
public void removeById(Long id){
personList.removeIf(person -> person.getId().equals(id));
}
public void removeAll(){
personList.clear();
}
public int count(){
return personList.size();
}
public abstract E[] getArray();
@Override
public Iterator<E> iterator(){
return personList.iterator();
}
}