<commit_before>package io.fintrospect.parameters

import org.jboss.netty.handler.codec.http.{HttpRequest, QueryStringDecoder}

import scala.collection.JavaConverters._
import scala.util.{Failure, Success, Try}

abstract class QueryParameter[T](val name: String, val description: Option[String], val paramType: ParamType)
  extends Parameter
  with Validatable[T, HttpRequest]
  with Bindable[T, QueryBinding] {

  val where = "query"
}

abstract class SingleQueryParameter[T](spec: ParameterSpec[T]) extends QueryParameter[T](spec.name, spec.description, spec.paramType) {

  override def -->(value: T) = Seq(new QueryBinding(this, spec.serialize(value)))

  def validate(request: HttpRequest) =
    Try(new QueryStringDecoder(request.getUri).getParameters.get(name).asScala.toSeq.head).toOption.map {
      v => Try(spec.deserialize(v)) match {
        case Success(d) => Right(Option(d))
        case Failure(_) => Left(this)
      }
    }.getOrElse(if (required) Left(this) else Right(None))
}

abstract class MultiQueryParameter[T](spec: ParameterSpec[T])
  extends QueryParameter[Seq[T]](spec.name, spec.description, spec.paramType) {

  override def -->(value: Seq[T]) = value.map(v => new QueryBinding(this, spec.serialize(v)))

  def validate(request: HttpRequest) = {
    Option(new QueryStringDecoder(request.getUri).getParameters.get(name))
      .map(_.asScala.toSeq)
      .map(v =>
      Try(v.map(s => spec.deserialize(s))) match {
        case Success(d) => Right(Option(d))
        case Failure(_) => Left(this)
      }).getOrElse(if (required) Left(this) else Right(None))<commit_msg>dave - refactor<commit_after>package io.fintrospect.parameters

import org.jboss.netty.handler.codec.http.{HttpRequest, QueryStringDecoder}

import scala.collection.JavaConverters._
import scala.util.{Failure, Success, Try}

abstract class QueryParameter[T](val name: String, val description: Option[String], val paramType: ParamType)
  extends Parameter
  with Validatable[T, HttpRequest]
  with Bindable[T, QueryBinding] {

  val where = "query"
}

abstract class SingleQueryParameter[T](spec: ParameterSpec[T]) extends QueryParameter[T](spec.name, spec.description, spec.paramType) {

  override def -->(value: T) = Seq(new QueryBinding(this, spec.serialize(value)))

  def validate(request: HttpRequest) =
    Option(new QueryStringDecoder(request.getUri).getParameters.get(name))
      .map(_.asScala.toSeq)
      .map(v =>
      Try(spec.deserialize(v.head)) match {
        case Success(d) => Right(Option(d))
        case Failure(_) => Left(this)
      }).getOrElse(if (required) Left(this) else Right(None))
}

abstract class MultiQueryParameter[T](spec: ParameterSpec[T])
  extends QueryParameter[Seq[T]](spec.name, spec.description, spec.paramType) {

  override def -->(value: Seq[T]) = value.map(v => new QueryBinding(this, spec.serialize(v)))

  def validate(request: HttpRequest) = {
    Option(new QueryStringDecoder(request.getUri).getParameters.get(name))
      .map(_.asScala.toSeq)
      .map(v =>
      Try(v.map(s => spec.deserialize(s))) match {
        case Success(d) => Right(Option(d))
        case Failure(_) => Left(this)
      }).getOrElse(if (required) Left(this) else Right(None))
{'fraction_non_alphanumeric': 0.14281269446172992, 'fraction_numerical': 0.0, 'mean_word_length': 4.63047285464098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870812', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1013, 'n_words': 209}