This repository was archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleQueue.pde
More file actions
67 lines (57 loc) · 1.27 KB
/
SimpleQueue.pde
File metadata and controls
67 lines (57 loc) · 1.27 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
60
61
62
63
64
65
66
67
// Copyright (c) 2003-2009, Jodd Team (jodd.org). All Rights Reserved.
public class SimpleQueue<E> {
private LinkedList<E> list = new LinkedList<E>();
/**
* Puts object in queue.
*/
public void put(E o) {
list.addLast(o);
}
/**
* Returns an element (object) from queue.
*
* @return element from queue or <code>null</code> if queue is empty
*/
public E get() {
if (list.isEmpty()) {
return null;
}
return list.removeFirst();
}
/**
* Returns all elements from the queue and clears it.
*/
public Object[] getAll() {
Object[] res = new Object[list.size()];
for (int i = 0; i < res.length; i++) {
res[i] = list.get(i);
}
list.clear();
return res;
}
/**
* Peeks an element in the queue. Returned elements is not removed from the queue.
*/
public E peek() {
return list.getFirst();
}
/**
* Returns <code>true</code> if queue is empty, otherwise <code>false</code>
*/
public boolean isEmpty() {
return list.isEmpty();
}
/**
* Returns queue size.
*/
public int size() {
return list.size();
}
public Float[] toArray() {
Float[] array = list.toArray(new Float[list.size()]);
return array;
}
public void clear() {
list = new LinkedList<E>();
}
}