That fuck shit the fascists are using
1package org.tm.archive.contacts;
2
3import androidx.annotation.NonNull;
4
5import java.util.ArrayList;
6import java.util.Iterator;
7import java.util.LinkedList;
8import java.util.List;
9
10/**
11 * Specialised set for {@link SelectedContact} that will not allow more than one entry that
12 * {@link SelectedContact#matches(SelectedContact)} any other.
13 */
14public final class SelectedContactSet {
15
16 private final List<SelectedContact> contacts = new LinkedList<>();
17
18 public boolean add(@NonNull SelectedContact contact) {
19 if (contains(contact)) {
20 return false;
21 }
22
23 contacts.add(contact);
24 return true;
25 }
26
27 public boolean contains(@NonNull SelectedContact otherContact) {
28 for (SelectedContact contact : contacts) {
29 if (otherContact.matches(contact)) {
30 return true;
31 }
32 }
33 return false;
34 }
35
36 public List<SelectedContact> getContacts() {
37 return new ArrayList<>(contacts);
38 }
39
40 public int size() {
41 return contacts.size();
42 }
43
44 public void clear() {
45 contacts.clear();
46 }
47
48 public int remove(@NonNull SelectedContact otherContact) {
49 int removeCount = 0;
50 Iterator<SelectedContact> iterator = contacts.iterator();
51
52 while (iterator.hasNext()) {
53 SelectedContact next = iterator.next();
54 if (next.matches(otherContact)) {
55 iterator.remove();
56 removeCount++;
57 }
58 }
59
60 return removeCount;
61 }
62}