<commit_before>package com.avsystem.commons
package hocon

import java.time.temporal.TemporalAmount
import java.time.{Duration, Period}
import java.util.Base64

import com.avsystem.commons.serialization.GenCodec.ReadFailure
import com.avsystem.commons.serialization._
import com.typesafe.config._

import scala.concurrent.duration.FiniteDuration

object HoconInput {
  def read[T: GenCodec](value: ConfigValue): T =
    GenCodec.read[T](new HoconInput(value))

  def read[T: GenCodec](config: Config): T =
    GenCodec.read[T](new HoconInput(config.root))
}

trait BaseHoconInput {
  protected final def handleFailures[T](code: => T): T =
    try code.opt.getOrElse(throw new ReadFailure("null")) catch {
      case rf: ReadFailure => throw rf
      case NonFatal(cause) => throw new ReadFailure(cause.getMessage, cause)
    }
}

class HoconInput(value: ConfigValue) extends InputAndSimpleInput with BaseHoconInput {
  // For wrapping ConfigValue into Config in order to use its rich API
  // Why is this API not available directly on ConfigValue?
  private def FakePath = "fake"

  private def config: Config =
    ConfigFactory.empty.withValue(FakePath, value)<commit_msg>some docs and explicitGenerics annot for HoconInput methods<commit_after>package com.avsystem.commons
package hocon

import java.time.temporal.TemporalAmount
import java.time.{Duration, Period}
import java.util.Base64

import com.avsystem.commons.annotation.explicitGenerics
import com.avsystem.commons.serialization.GenCodec.ReadFailure
import com.avsystem.commons.serialization._
import com.typesafe.config._

import scala.concurrent.duration.FiniteDuration

object HoconInput {
  @explicitGenerics def read[T: GenCodec](value: ConfigValue): T =
    GenCodec.read[T](new HoconInput(value))

  @explicitGenerics def read[T: GenCodec](config: Config): T =
    GenCodec.read[T](new HoconInput(config.root))
}

trait BaseHoconInput {
  protected final def handleFailures[T](code: => T): T =
    try code.opt.getOrElse(throw new ReadFailure("null")) catch {
      case rf: ReadFailure => throw rf
      case NonFatal(cause) => throw new ReadFailure(cause.getMessage, cause)
    }
}

/**
  * An [[com.avsystem.commons.serialization.Input Input]] implementation which allows deserialization from
  * HOCON (represented as [[com.typesafe.config.Config Config]] or [[com.typesafe.config.ConfigValue ConfigValue]])
  * using [[com.avsystem.commons.serialization.GenCodec GenCodec]].
  */
class HoconInput(value: ConfigValue) extends InputAndSimpleInput with BaseHoconInput {
  // For wrapping ConfigValue into Config in order to use its rich API
  // Why is this API not available directly on ConfigValue?
  private def FakePath = "fake"

  private def config: Config =
    ConfigFactory.empty.withValue(FakePath, value)
{'fraction_non_alphanumeric': 0.0987078248384781, 'fraction_numerical': 0.0014357501794687725, 'mean_word_length': 4.917197452229299, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4265791', 'n_tokens_mistral': 847, 'n_tokens_neox': 833, 'n_words': 223}