-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLimitedQueue.java
More file actions
36 lines (28 loc) · 768 Bytes
/
Copy pathLimitedQueue.java
File metadata and controls
36 lines (28 loc) · 768 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
package sample;
import java.util.LinkedList;
/**
* @author liuxf
* @version 1.0
* @date 2020/12/9 16:07
*/
class LimitedQueue<E> extends LinkedList<E> {
private static final long serialVersionUID = 1L;
private int limit;
public LimitedQueue(int limit) {
this.limit = limit;
}
@Override
public boolean add(E o) {
super.add(o);
while (size() > limit) { super.remove(); }
return true;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
for (E e: this){
stringBuilder.append(System.lineSeparator()).append(e).append("---接收完成").append(System.lineSeparator());
}
return stringBuilder.toString();
}
}