<commit_before>package com.rackspace.com.papi.components.checker.step

import scala.collection.immutable.List

//
//  Base class for all checker results
//
abstract class Result(val message : String,   // A message describing the result
                      val valid : Boolean,    // Was the http req/res valid?
                      val terminal : Boolean, // Are we at a terminal node in the machine
                      val uriLevel : Int,     // The URI level at the error
                      stepId : String) {      // The ID of the machine at the error

  var stepIDs : List[String] = List[String]() // ID of the linear steps it took to get
                                              // to this result

  addStepId(stepId)

  def addStepId(stepId : String) : Unit = {
    stepIDs = stepId +: stepIDs
  }

  protected val startPath = "["
  protected val endPath = "]"

  def path : String = startPath+stepIDs.reduceLeft(_+" "+_)+endPath
  def cmpString : String = message+" "+path+" "+terminal+" "+uriLevel
  override def toString : String = path
  override def hashCode : Int = cmpString.hashCode
  override def equals (any : Any) : Boolean = {
    any match {
      case r : Result => this.hashCode() == r.hashCode()
      case _ => false
    }
  }
}

class ErrorResult(message : String, val code : Int, uriLevel : Int, stepId : String) extends Result(message, false, true, uriLevel, stepId) {
  override def toString : String = path+" "+code+" : "+message
  override def cmpString : String = super.cmpString+" "+code
}

class AcceptResult(message: String, uriLevel : Int, stepId : String)  extends Result(message, true, true, uriLevel, stepId)
class BadContentResult(message : String, uriLevel : Int, stepId : String) extends ErrorResult(message, 400, uriLevel, stepId)
class URLFailResult(message : String, uriLevel : Int, stepId : String) extends ErrorResult(message, 404, uriLevel, stepId)
class MethodFailResult(message: String, uriLevel : Int, stepId : String) extends ErrorResult(message, 405, uriLevel, stepId)
class BadMediaTypeResult(message: String, uriLevel : Int, stepId : String) extends ErrorResult(message, 415, uriLevel, stepId)
class MismatchResult(message: String, uriLevel : Int, stepId : String) extends Result(message, false, false, uriLevel, stepId) {
  override protected val startPath = "("
  override protected val endPath = ")"
}

class MultiFailResult(val fails : Array[Result], uriLevel : Int, stepId : String)
      extends Result ("Multiple possible errors", false, false, uriLevel, stepId)
{
  override protected val startPath = "{"
  override protected val endPath = "}"

  override def path : String = startPath+(for {f <- fails} yield f.path).reduceLeft(_+" "+_)+endPath

  override def toString : String = {
    reduce match {
      case Some(e : ErrorResult) => path+" "+e.code+" : "+e.message
      case Some(r : Result) => path
      case None => path
    }
  }<commit_msg>Fixed issue where multi-fail result string is missing states.<commit_after>package com.rackspace.com.papi.components.checker.step

import scala.collection.immutable.List

//
//  Base class for all checker results
//
abstract class Result(val message : String,   // A message describing the result
                      val valid : Boolean,    // Was the http req/res valid?
                      val terminal : Boolean, // Are we at a terminal node in the machine
                      val uriLevel : Int,     // The URI level at the error
                      stepId : String) {      // The ID of the machine at the error

  var stepIDs : List[String] = List[String]() // ID of the linear steps it took to get
                                              // to this result

  addStepId(stepId)

  def addStepId(stepId : String) : Unit = {
    stepIDs = stepId +: stepIDs
  }

  protected val startPath = "["
  protected val endPath = "]"

  def path : String = startPath+stepIDs.reduceLeft(_+" "+_)+endPath
  def cmpString : String = message+" "+path+" "+terminal+" "+uriLevel
  override def toString : String = path
  override def hashCode : Int = cmpString.hashCode
  override def equals (any : Any) : Boolean = {
    any match {
      case r : Result => this.hashCode() == r.hashCode()
      case _ => false
    }
  }
}

class ErrorResult(message : String, val code : Int, uriLevel : Int, stepId : String) extends Result(message, false, true, uriLevel, stepId) {
  override def toString : String = path+" "+code+" : "+message
  override def cmpString : String = super.cmpString+" "+code
}

class AcceptResult(message: String, uriLevel : Int, stepId : String)  extends Result(message, true, true, uriLevel, stepId)
class BadContentResult(message : String, uriLevel : Int, stepId : String) extends ErrorResult(message, 400, uriLevel, stepId)
class URLFailResult(message : String, uriLevel : Int, stepId : String) extends ErrorResult(message, 404, uriLevel, stepId)
class MethodFailResult(message: String, uriLevel : Int, stepId : String) extends ErrorResult(message, 405, uriLevel, stepId)
class BadMediaTypeResult(message: String, uriLevel : Int, stepId : String) extends ErrorResult(message, 415, uriLevel, stepId)
class MismatchResult(message: String, uriLevel : Int, stepId : String) extends Result(message, false, false, uriLevel, stepId) {
  override protected val startPath = "("
  override protected val endPath = ")"
}

class MultiFailResult(val fails : Array[Result], uriLevel : Int, stepId : String)
      extends Result ("Multiple possible errors", false, false, uriLevel, stepId)
{
  override protected val startPath = "{"
  override protected val endPath = "}"

  override def path : String = startPath+stepIDs.reduceLeft(_+" "+_)+" "+(for {f <- fails} yield f.path).reduceLeft(_+" "+_)+endPath

  override def toString : String = {
    reduce match {
      case Some(e : ErrorResult) => path+" "+e.code+" : "+e.message
      case Some(r : Result) => path
      case None => path
    }
  }
{'fraction_non_alphanumeric': 0.10970677451971689, 'fraction_numerical': 0.004044489383215369, 'mean_word_length': 3.2332382310984307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4923699', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1646, 'n_words': 591}