78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2007, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 *******************************************************************************/
|
|
11 module org.eclipse.core.internal.databinding.Queue;
|
|
12
|
|
13 import java.lang.all;
|
|
14
|
|
15 /**
|
|
16 * Created to avoid a dependency on java.util.LinkedList, see bug 205224.
|
|
17 *
|
|
18 * @since 1.1
|
|
19 *
|
|
20 */
|
|
21 public class Queue {
|
|
22
|
85
|
23 void notifyAll(){
|
|
24 implMissing( __FILE__, __LINE__ );
|
|
25 }
|
|
26 void wait(){
|
|
27 implMissing( __FILE__, __LINE__ );
|
|
28 }
|
|
29
|
78
|
30 static class Entry {
|
|
31 Object object;
|
|
32
|
|
33 this(Object o) {
|
|
34 this.object = o;
|
|
35 }
|
|
36
|
|
37 Entry next;
|
|
38 }
|
|
39
|
|
40 Entry first;
|
|
41 Entry last;
|
|
42
|
|
43 /**
|
|
44 * Adds the given object to the end of the queue.
|
|
45 *
|
|
46 * @param o
|
|
47 */
|
|
48 public void enqueue(Object o) {
|
|
49 Entry oldLast = last;
|
|
50 last = new Entry(o);
|
|
51 if (oldLast !is null) {
|
|
52 oldLast.next = last;
|
|
53 } else {
|
|
54 first = last;
|
|
55 }
|
|
56 }
|
|
57
|
|
58 /**
|
|
59 * Returns the first object in the queue. The queue must not be empty.
|
|
60 *
|
|
61 * @return the first object
|
|
62 */
|
|
63 public Object dequeue() {
|
|
64 Entry oldFirst = first;
|
|
65 if (oldFirst is null) {
|
|
66 throw new IllegalStateException();
|
|
67 }
|
|
68 first = oldFirst.next;
|
|
69 if (first is null) {
|
|
70 last = null;
|
|
71 }
|
|
72 oldFirst.next = null;
|
|
73 return oldFirst.object;
|
|
74 }
|
|
75
|
|
76 /**
|
|
77 * Returns <code>true</code> if the list is empty.
|
|
78 *
|
|
79 * @return <code>true</code> if the list is empty
|
|
80 */
|
|
81 public bool isEmpty() {
|
|
82 return first is null;
|
|
83 }
|
|
84 }
|