quark.concurrent.Queue Maven / Gradle / Ivy
/* Quark 1.0.452 run at 2016-11-11 16:09:46.008093 */
package quark.concurrent;
/**
* A simple FIFO
*/
public class Queue implements io.datawire.quark.runtime.QObject {
public java.util.ArrayList items;
public Integer head;
public Integer tail;
public Queue() {
(this).items = new java.util.ArrayList();
(this).head = 0;
(this).tail = 0;
}
public void put(T item) {
if (((this).tail) < (((this).items).size())) {
((this).items).set(((this).tail), (item));
} else {
((this).items).add(item);
}
(this).tail = ((this).tail) + (1);
}
public T get() {
T item = (T) (null);
if (((this).head) < ((this).tail)) {
item = ((this).items).get((this).head);
(this).head = ((this).head) + (1);
} else {
if (((this).head) > (0)) {
(this).head = 0;
(this).tail = 0;
}
}
return item;
}
public Integer size() {
return ((this).tail) - ((this).head);
}
public String _getClass() {
return "quark.concurrent.Queue";
}
public Object _getField(String name) {
if ((name)==("items") || ((Object)(name) != null && ((Object) (name)).equals("items"))) {
return (this).items;
}
if ((name)==("head") || ((Object)(name) != null && ((Object) (name)).equals("head"))) {
return (this).head;
}
if ((name)==("tail") || ((Object)(name) != null && ((Object) (name)).equals("tail"))) {
return (this).tail;
}
return null;
}
public void _setField(String name, Object value) {
if ((name)==("items") || ((Object)(name) != null && ((Object) (name)).equals("items"))) {
(this).items = (java.util.ArrayList) (value);
}
if ((name)==("head") || ((Object)(name) != null && ((Object) (name)).equals("head"))) {
(this).head = (Integer) (value);
}
if ((name)==("tail") || ((Object)(name) != null && ((Object) (name)).equals("tail"))) {
(this).tail = (Integer) (value);
}
}
}