scala.collection.immutable

class Queue

[source: scala/collection/immutable/Queue.scala]

@serializable

class Queue[+A](protected val in : List[A], protected val out : List[A])
extends Sequence[A]
Queue objects implement data structures that allow to insert and retrieve elements in a first-in-first-out (FIFO) manner.
Author
Erik Stenman
Version
1.0, 08/07/2003
Value Summary
override lazy val hashCode : Int
Returns a hash code value for the object.
Method Summary
def + [B >: A](iter : Iterable[B]) : Queue[B]
Returns a new queue with all all elements provided by an Iterable object added at the end of the queue. The elements are prepended in the order they are given out by the iterator.
def + [B >: A](elem : B) : Queue[B]
Creates a new queue with element added at the end of the old queue.
def apply (n : Int) : A
Returns the n-th element of this queue. The first element is at position 0.
def dequeue : (A, Queue[A])
Returns a tuple with the first element in the queue, and a new queue with this element removed.
def enqueue [B >: A](elem : B) : Queue[B]
Creates a new queue with element added at the end of the old queue.
def enqueue [B >: A](iter : Iterable[B]) : Queue[B]
Returns a new queue with all elements provided by an Iterable object added at the end of the queue. The elements are prepended in the order they are given out by the iterator.
override def equals (o : Any) : Boolean
Compares two queues for equality by comparing each element in the queues.
def front : A
Returns the first element in the queue, or throws an error if there is no element contained in the queue.
override def isEmpty : Boolean
Checks if the queue is empty.
override def iterator : Iterator[A]
Returns the elements in the list as an iterator
def length : Int
Returns the length of the queue.
override def toString : java.lang.String
Returns a string representation of this queue.
Methods inherited from Sequence
companion
Methods inherited from SequenceTemplate
lengthCompare, size, isDefinedAt, zip, zipAll, zipWithIndex, segmentLength, prefixLength, indexWhere, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, reverse, reverseIterator, reversedElements, startsWith, startsWith, endsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, padTo, toSequence, indices, view, view, sortWith, findLastIndexOf, slice, equalsWith, containsSlice, projection
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from IterableTemplate
elements, foreach, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, first, firstOption, toSeq
Methods inherited from TraversableClass
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Value Details
override lazy val hashCode : Int
Returns a hash code value for the object.

The default hashing algorithm is platform dependent. Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Returns
the hash code value for the object.

Overrides
Sequence.hashCode

Method Details
def apply(n : Int) : A
Returns the n-th element of this queue. The first element is at position 0.
Parameters
n - index of the element to return
Returns
the element at position n in this queue.
Throws
Predef.NoSuchElementException - if the queue is too short.

override def iterator : Iterator[A]
Returns the elements in the list as an iterator

override def isEmpty : Boolean
Checks if the queue is empty.
Returns
true, iff there is no element in the queue.

def length : Int
Returns the length of the queue.

@deprecated("Use the method <code>enqueue</code> from now on.")

def +[B >: A](elem : B) : Queue[B]
Creates a new queue with element added at the end of the old queue.
Parameters
elem - the element to insert

def enqueue[B >: A](elem : B) : Queue[B]
Creates a new queue with element added at the end of the old queue.
Parameters
elem - the element to insert

@deprecated("Use the method <code>enqueue</code> from now on.")

def +[B >: A](iter : Iterable[B]) : Queue[B]
Returns a new queue with all all elements provided by an Iterable object added at the end of the queue. The elements are prepended in the order they are given out by the iterator.
Parameters
iter - an iterable object

def enqueue[B >: A](iter : Iterable[B]) : Queue[B]
Returns a new queue with all elements provided by an Iterable object added at the end of the queue. The elements are prepended in the order they are given out by the iterator.
Parameters
iter - an iterable object

def dequeue : (A, Queue[A])
Returns a tuple with the first element in the queue, and a new queue with this element removed.
Throws
Predef.NoSuchElementException -
Returns
the first element of the queue.

def front : A
Returns the first element in the queue, or throws an error if there is no element contained in the queue.
Throws
Predef.NoSuchElementException -
Returns
the first element.

override def toString : java.lang.String
Returns a string representation of this queue.

override def equals(o : Any) : Boolean
Compares two queues for equality by comparing each element in the queues.
Returns
true, iff the two queues are structurally equal.