src/Pure/PIDE/command.scala
changeset 51494 8f3d1a7bee26
parent 51048 123be08eed88
child 51496 cb677987b7e3
equal deleted inserted replaced
51493:59d8a1031c00 51494:8f3d1a7bee26
    23   {
    23   {
    24     val empty = new Results(SortedMap.empty)
    24     val empty = new Results(SortedMap.empty)
    25     def merge(rs: Iterable[Results]): Results = (empty /: rs.iterator)(_ ++ _)
    25     def merge(rs: Iterable[Results]): Results = (empty /: rs.iterator)(_ ++ _)
    26   }
    26   }
    27 
    27 
    28   final class Results private(rep: SortedMap[Long, XML.Tree])
    28   final class Results private(private val rep: SortedMap[Long, XML.Tree])
    29   {
    29   {
    30     def defined(serial: Long): Boolean = rep.isDefinedAt(serial)
    30     def defined(serial: Long): Boolean = rep.isDefinedAt(serial)
    31     def get(serial: Long): Option[XML.Tree] = rep.get(serial)
    31     def get(serial: Long): Option[XML.Tree] = rep.get(serial)
    32     def entries: Iterator[(Long, XML.Tree)] = rep.iterator
    32     def entries: Iterator[(Long, XML.Tree)] = rep.iterator
    33 
    33 
    38     def ++ (other: Results): Results =
    38     def ++ (other: Results): Results =
    39       if (this eq other) this
    39       if (this eq other) this
    40       else if (rep.isEmpty) other
    40       else if (rep.isEmpty) other
    41       else (this /: other.entries)(_ + _)
    41       else (this /: other.entries)(_ + _)
    42 
    42 
       
    43     override def hashCode: Int = rep.hashCode
       
    44     override def equals(that: Any): Boolean =
       
    45       that match {
       
    46         case other: Results => rep == other.rep
       
    47         case _ => false
       
    48       }
    43     override def toString: String = entries.mkString("Results(", ", ", ")")
    49     override def toString: String = entries.mkString("Results(", ", ", ")")
    44   }
    50   }
    45 
    51 
    46 
    52 
    47   /* state */
    53   /* state */
    54   {
    60   {
    55     def markup_to_XML(filter: XML.Elem => Boolean): XML.Body =
    61     def markup_to_XML(filter: XML.Elem => Boolean): XML.Body =
    56       markup.to_XML(command.range, command.source, filter)
    62       markup.to_XML(command.range, command.source, filter)
    57 
    63 
    58 
    64 
    59     /* accumulate content */
    65     /* content */
       
    66 
       
    67     def eq_content(other: State): Boolean =
       
    68       command.source == other.command.source &&
       
    69       status == other.status &&
       
    70       results == other.results &&
       
    71       markup == other.markup
    60 
    72 
    61     private def add_status(st: Markup): State = copy(status = st :: status)
    73     private def add_status(st: Markup): State = copy(status = st :: status)
    62     private def add_markup(m: Text.Markup): State = copy(markup = markup + m)
    74     private def add_markup(m: Text.Markup): State = copy(markup = markup + m)
    63 
    75 
    64     def + (alt_id: Document.ID, message: XML.Elem): Command.State =
    76     def + (alt_id: Document.ID, message: XML.Elem): Command.State =