"Fossies" - the Fresh Open Source Software Archive

Member "scala-js-1.0.0-RC1/javalib/src/main/scala/java/util/AbstractSet.scala" (21 Nov 2019, 1403 Bytes) of package /linux/www/scala-js-1.0.0-RC1.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 import scala.annotation.tailrec
   16 
   17 import ScalaOps._
   18 
   19 abstract class AbstractSet[E] protected () extends AbstractCollection[E]
   20                                               with Set[E] {
   21   override def equals(that: Any): Boolean = {
   22     if (that.asInstanceOf[AnyRef] eq this) true
   23     else {
   24       that match {
   25         case that: Collection[_] => that.size == this.size && containsAll(that)
   26         case _                   => false
   27       }
   28     }
   29   }
   30 
   31   override def hashCode(): Int =
   32     this.scalaOps.foldLeft(0)((prev, item) => item.hashCode + prev)
   33 
   34   override def removeAll(c: Collection[_]): Boolean = {
   35     if (size > c.size) {
   36       c.scalaOps.foldLeft(false)((prev, elem) => this.remove(elem) || prev)
   37     } else {
   38       @tailrec
   39       def removeAll(iter: Iterator[E], modified: Boolean): Boolean = {
   40         if (iter.hasNext) {
   41           if (c.contains(iter.next())) {
   42             iter.remove()
   43             removeAll(iter, true)
   44           } else {
   45             removeAll(iter, modified)
   46           }
   47         } else {
   48           modified
   49         }
   50       }
   51       removeAll(this.iterator, false)
   52     }
   53   }
   54 }