Dart API Referencedart:coreQueue<E>

Queue<E> abstract class

A Queue is a collection that can be manipulated at both ends. One can iterate over the elements of a queue through forEach or with an Iterator.

abstract class Queue<E> extends Collection<E> {

  /**
   * Creates a queue.
   */
  factory Queue() => new DoubleLinkedQueue<E>();

  /**
   * Creates a queue with the elements of [other]. The order in
   * the queue will be the order provided by the iterator of [other].
   */
  factory Queue.from(Iterable<E> other) => new DoubleLinkedQueue<E>.from(other);

  /**
   * Removes and returns the first element of this queue. Throws an
   * [EmptyQueueException] exception if this queue is empty.
   */
  E removeFirst();

  /**
   * Removes and returns the last element of the queue. Throws an
   * [EmptyQueueException] exception if this queue is empty.
   */
  E removeLast();

  /**
   * Adds [value] at the beginning of the queue.
   */
  void addFirst(E value);

  /**
   * Adds [value] at the end of the queue.
   */
  void addLast(E value);

  /**
   * Adds [value] at the end of the queue.
   */
  void add(E value);

  /**
   * Adds all elements of [collection] at the end of the queue. The
   * length of the queue is extended by the length of [collection].
   */
  void addAll(Collection<E> collection);

  /**
   * Returns the first element of the queue. Throws an
   * [EmptyQueueException] exception if this queue is empty.
   */
  E first();

  /**
   * Returns the last element of the queue. Throws an
   * [EmptyQueueException] exception if this queue is empty.
   */
  E last();

  /**
   * Removes all elements in the queue. The size of the queue becomes zero.
   */
  void clear();
}

Extends

Iterable<E> > Collection<E> > Queue<E>

Subclasses

DoubleLinkedQueue<E>

Constructors

factory Queue() #

Creates a queue.

factory Queue() => new DoubleLinkedQueue<E>();

factory Queue.from(Iterable<E> other) #

Creates a queue with the elements of other. The order in the queue will be the order provided by the iterator of other.

factory Queue.from(Iterable<E> other) => new DoubleLinkedQueue<E>.from(other);

Properties

final int length #

inherited from Collection

Returns the number of elements in this collection.

int get length;

Methods

void add(E value) #

Adds value at the end of the queue.

void add(E value);

void addAll(Collection<E> collection) #

Adds all elements of collection at the end of the queue. The length of the queue is extended by the length of collection.

void addAll(Collection<E> collection);

void addFirst(E value) #

Adds value at the beginning of the queue.

void addFirst(E value);

void addLast(E value) #

Adds value at the end of the queue.

void addLast(E value);

void clear() #

Removes all elements in the queue. The size of the queue becomes zero.

void clear();

bool contains(E element) #

inherited from Collection

Check whether the collection contains an element equal to element.

bool contains(E element) {
  for (E e in this) {
    if (e == element) return true;
  }
  return false;
}

bool every(bool f(E element)) #

inherited from Collection

Returns true if every elements of this collection satisify the predicate f. Returns false otherwise.

bool every(bool f(E element)) {
  for (E element in this) {
    if (!f(element)) return false;
  }
  return true;
}

Collection<E> filter(bool f(E element)) #

inherited from Collection

Returns a collection with the elements of this collection that satisfy the predicate f.

The returned collection should be of the same type as the collection creating it.

An element satisfies the predicate f if f(element) returns true.

Collection<E> filter(bool f(E element));

E first() #

Returns the first element of the queue. Throws an EmptyQueueException exception if this queue is empty.

E first();

void forEach(void f(E element)) #

inherited from Collection

Applies the function f to each element of this collection.

void forEach(void f(E element)) {
  for (E element in this) f(element);
}

bool isEmpty() #

inherited from Collection

Returns true if there is no element in this collection.

bool isEmpty() => !iterator().hasNext();

Iterator<E> iterator() #

inherited from Iterable

Returns an Iterator that iterates over this Iterable object.

Iterator<E> iterator();

E last() #

Returns the last element of the queue. Throws an EmptyQueueException exception if this queue is empty.

E last();

Collection map(f(E element)) #

inherited from Collection

Returns a new collection with the elements f(e) for each element e of this collection.

Subclasses of Collection should implement the map method to return a collection of the same general type as themselves. E.g., List.map should return a List.

Collection map(f(E element));

reduce(initialValue, combine(previousValue, E element)) #

inherited from Collection

Reduce a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function. Use initialValue as the initial value, and the function combine to create a new value from the previous one and an element.

Example of calculating the sum of a collection:

collection.reduce(0, (prev, element) => prev + element);

Dynamic reduce(var initialValue,
               Dynamic combine(var previousValue, E element)) {
  var value = initialValue;
  for (E element in this) value = combine(value, element);
  return value;
}

E removeFirst() #

Removes and returns the first element of this queue. Throws an EmptyQueueException exception if this queue is empty.

E removeFirst();

E removeLast() #

Removes and returns the last element of the queue. Throws an EmptyQueueException exception if this queue is empty.

E removeLast();

bool some(bool f(E element)) #

inherited from Collection

Returns true if one element of this collection satisfies the predicate f. Returns false otherwise.

bool some(bool f(E element)) {
  for (E element in this) {
    if (f(element)) return true;
  }
  return false;
}