"Fossies" - the Fresh Open Source Software Archive

Member "scala-js-1.3.1/javalib/src/main/scala/java/util/AbstractSequentialList.scala" (14 Nov 2020, 1346 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. See also the last Fossies "Diffs" side-by-side code changes report for "AbstractSequentialList.scala": 1.1.0_vs_1.1.1.

    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 AbstractSequentialList[E] protected ()
   16     extends AbstractList[E] {
   17 
   18   def get(index: Int): E = {
   19     val iter = listIterator(index)
   20     if (iter.hasNext()) iter.next()
   21     else throw new IndexOutOfBoundsException(index.toString)
   22   }
   23 
   24   override def set(index: Int, element: E): E = {
   25     val iter = listIterator(index)
   26     if (!iter.hasNext())
   27       throw new IndexOutOfBoundsException
   28     val ret = iter.next()
   29     iter.set(element)
   30     ret
   31   }
   32 
   33   override def add(index: Int, element: E): Unit =
   34     listIterator(index).add(element)
   35 
   36   override def remove(index: Int): E = {
   37     val iter = listIterator(index)
   38     if (!iter.hasNext())
   39       throw new IndexOutOfBoundsException
   40     val ret = iter.next()
   41     iter.remove()
   42     ret
   43   }
   44 
   45   override def addAll(index: Int, c: Collection[_ <: E]): Boolean = {
   46     val iter = listIterator(index)
   47     val citer = c.iterator()
   48     val changed = citer.hasNext()
   49     while (citer.hasNext()) {
   50       iter.add(citer.next())
   51     }
   52     changed
   53   }
   54 
   55   def listIterator(index: Int): ListIterator[E]
   56 }