1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.nio;
17
18 import java.nio.channels.SelectionKey;
19 import java.util.AbstractSet;
20 import java.util.Arrays;
21 import java.util.Iterator;
22
23 final class SelectedSelectionKeySet extends AbstractSet<SelectionKey> {
24
25 SelectionKey[] keys;
26 int size;
27
28 SelectedSelectionKeySet() {
29 keys = new SelectionKey[1024];
30 }
31
32 @Override
33 public boolean add(SelectionKey o) {
34 if (o == null) {
35 return false;
36 }
37
38 keys[size++] = o;
39 if (size == keys.length) {
40 increaseCapacity();
41 }
42
43 return true;
44 }
45
46 @Override
47 public int size() {
48 return size;
49 }
50
51 @Override
52 public boolean remove(Object o) {
53 return false;
54 }
55
56 @Override
57 public boolean contains(Object o) {
58 return false;
59 }
60
61 @Override
62 public Iterator<SelectionKey> iterator() {
63 throw new UnsupportedOperationException();
64 }
65
66 void reset() {
67 reset(0);
68 }
69
70 void reset(int start) {
71 Arrays.fill(keys, start, size, null);
72 size = 0;
73 }
74
75 private void increaseCapacity() {
76 SelectionKey[] newKeys = new SelectionKey[keys.length << 1];
77 System.arraycopy(keys, 0, newKeys, 0, size);
78 keys = newKeys;
79 }
80 }