"Fossies" - the Fresh Open Source Software Archive

Member "scala-js-1.3.1/javalib/src/main/scala/java/util/AbstractQueue.scala" (14 Nov 2020, 942 Bytes) of package /linux/www/scala-js-1.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scala source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Scala.js (https://www.scala-js.org/)
    3  *
    4  * Copyright EPFL.
    5  *
    6  * Licensed under Apache License 2.0
    7  * (https://www.apache.org/licenses/LICENSE-2.0).
    8  *
    9  * See the NOTICE file distributed with this work for
   10  * additional information regarding copyright ownership.
   11  */
   12 
   13 package java.util
   14 
   15 abstract class AbstractQueue[E] protected ()
   16     extends AbstractCollection[E] with Queue[E] {
   17 
   18   override def add(e: E): Boolean =
   19     if (offer(e)) true
   20     else throw new IllegalStateException()
   21 
   22   def remove(): E =
   23     if (!isEmpty()) poll()
   24     else throw new NoSuchElementException()
   25 
   26   def element(): E =
   27     if (!isEmpty()) peek()
   28     else throw new NoSuchElementException()
   29 
   30   override def clear(): Unit = {
   31     while (poll() != null) {}
   32   }
   33 
   34   override def addAll(c: Collection[_ <: E]): Boolean = {
   35     val iter = c.iterator
   36     var changed = false
   37     while (iter.hasNext())
   38       changed = add(iter.next()) || changed
   39     changed
   40   }
   41 }