"Fossies" - the Fresh Open Source Software Archive

Member "scala-js-1.3.1/javalib/src/main/scala/java/util/AbstractRandomAccessListIterator.scala" (14 Nov 2020, 1348 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 "AbstractRandomAccessListIterator.scala": 1.2.0_vs_1.3.0.

    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 private[util] class AbstractRandomAccessListIterator[E](private var i: Int,
   16     start: Int, protected var end: Int) extends ListIterator[E] with SizeChangeEvent {
   17 
   18   private var last = -1
   19 
   20   def hasNext(): Boolean =
   21     i < end
   22 
   23   def next(): E = {
   24     last = i
   25     i += 1
   26     get(last)
   27   }
   28 
   29   def hasPrevious(): Boolean =
   30     start < i
   31 
   32   def previous(): E = {
   33     i -= 1
   34     last = i
   35     get(last)
   36   }
   37 
   38   def nextIndex(): Int = i
   39 
   40   def previousIndex(): Int = i - 1
   41 
   42   override def remove(): Unit = {
   43     checkThatHasLast()
   44     remove(last)
   45     if (last < i)
   46       i -= 1
   47     last = -1
   48     changeSize(-1)
   49   }
   50 
   51   def set(e: E): Unit = {
   52     checkThatHasLast()
   53     set(last, e)
   54   }
   55 
   56   def add(e: E): Unit = {
   57     add(i, e)
   58     changeSize(1)
   59     last = -1
   60     i += 1
   61   }
   62 
   63   protected def get(index: Int): E
   64 
   65   protected def remove(index: Int): Unit
   66 
   67   protected def set(index: Int, e: E): Unit
   68 
   69   protected def add(index: Int, e: E): Unit
   70 
   71   private def checkThatHasLast(): Unit = {
   72     if (last == -1)
   73       throw new IllegalStateException
   74   }
   75 }