<commit_before>package time

/**
 * Created by <NAME> on 14/10/2017
 */

//region Number
val Number.seconds: Interval<Second>
    get() = Interval(this.toDouble())

val Number.minutes: Interval<Minute>
    get() = Interval(this.toDouble())

val Number.milliseconds: Interval<Millisecond>
    get() = Interval(this.toDouble())

val Number.microseconds: Interval<Microsecond>
    get() = Interval(this.toDouble())

val Number.nanoseconds: Interval<Nanosecond>
    get() = Interval(this.toDouble())

val Number.hours: Interval<Hour>
    get() = Interval(this.toDouble())

val Number.days: Interval<Day>
    get() = Interval(this.toDouble())
//endregion


class Interval<out T : TimeUnit>(val value: Double , val factory: () -> T) {

    val inSeconds: Interval<Second>
        get() = converted()

    val inMinutes: Interval<Minute>
        get() = converted()

    val inMilliseconds: Interval<Millisecond>
        get() = converted()

    val inMicroseconds: Interval<Microsecond>
        get() = converted()

    val inNanoseconds: Interval<Nanosecond>
        get() = converted()

    val inHours: Interval<Hour>
        get() = converted()

    val inDays: Interval<Day>
        get() = converted()

    inline fun <reified OtherUnit : TimeUnit> converted(): Interval<OtherUnit> {
        val otherInstance = OtherUnit::class.java.newInstance()
        return Interval(value * factory().conversionRate(otherInstance))
    }
//    inline fun <reified OtherUnit : TimeUnit> converted(otherTimeUnit: OtherUnit): Interval<OtherUnit> {
//        return Interval(value * factory().conversionRate(otherTimeUnit))
//    }
    companion object {
        inline operator fun <reified K : TimeUnit> invoke(value: Double) = Interval(value) {
            K::class.java.newInstance()
        }
    }

    operator fun plus(other: Interval<TimeUnit>): Interval<T> {
        val newValue = value + other.value * other.factory().conversionRate(factory())
        return Interval(newValue){return@Interval factory()}
    }

    operator fun minus(other: Interval<TimeUnit>): Interval<T> {
        val newValue = value - other.value * other.factory().conversionRate(factory())
        return Interval(newValue){return@Interval factory()}
    }

    operator fun times(other: Number): Interval<T> {
        return Interval(value * other.toDouble()){return@Interval factory()}
    }

    operator fun div(other: Number): Interval<T> {
        return Interval(value / other.toDouble()){return@Interval factory()}
    }
}

interface TimeUnit {
    val timeIntervalRatio: Double
    fun <OtherUnit : TimeUnit> conversionRate(otherTimeUnit: OtherUnit): Double {
        return timeIntervalRatio / otherTimeUnit.timeIntervalRatio
    }
}

class Day : TimeUnit {
    override val timeIntervalRatio = 86400.0
}

class Hour : TimeUnit {
    override val timeIntervalRatio = 3600.0
}

class Minute : TimeUnit {
    override val timeIntervalRatio = 60.0
}

class Second : TimeUnit {
    override val timeIntervalRatio = 1.0
}

class Millisecond : TimeUnit {
    override val timeIntervalRatio = 0.001
}

class Microsecond : TimeUnit {
    override val timeIntervalRatio =  0.000001
}

class Nanosecond : TimeUnit {
    override val timeIntervalRatio = 1e-9
}
<commit_msg>Implement all operator functions.<commit_after>package time

/**
 * Created by <NAME> on 14/10/2017
 */


interface TimeUnit {
    val timeIntervalRatio: Double
    fun <OtherUnit : TimeUnit> conversionRate(otherTimeUnit: OtherUnit): Double {
        return timeIntervalRatio / otherTimeUnit.timeIntervalRatio
    }
}


class Interval<out T : TimeUnit>(val value: Double, val factory: () -> T) {

    val inDays: Interval<Day>
        get() = converted()

    val inHours: Interval<Hour>
        get() = converted()

    val inMinutes: Interval<Minute>
        get() = converted()

    val inSeconds: Interval<Second>
        get() = converted()

    val inMilliseconds: Interval<Millisecond>
        get() = converted()

    val inMicroseconds: Interval<Microsecond>
        get() = converted()

    val inNanoseconds: Interval<Nanosecond>
        get() = converted()


    inline fun <reified OtherUnit : TimeUnit> converted(): Interval<OtherUnit> {
        val otherInstance = OtherUnit::class.java.newInstance()
        return Interval(value * factory().conversionRate(otherInstance))
    }

    companion object {
        inline operator fun <reified K : TimeUnit> invoke(value: Double) = Interval(value) {
            K::class.java.newInstance()
        }
    }

    operator fun plus(other: Interval<TimeUnit>): Interval<T> {
        val newValue = value + other.value * other.factory().conversionRate(factory())
        return Interval(newValue) { return@Interval factory() }
    }

    operator fun minus(other: Interval<TimeUnit>): Interval<T> {
        val newValue = value - other.value * other.factory().conversionRate(factory())
        return Interval(newValue) { return@Interval factory() }
    }

    operator fun times(other: Number): Interval<T> {
        return Interval(value * other.toDouble()) { return@Interval factory() }
    }

    operator fun div(other: Number): Interval<T> {
        return Interval(value / other.toDouble()) { return@Interval factory() }
    }

    operator fun inc() = Interval(value + 1, { factory() })

    operator fun dec() = Interval(value - 1, { factory() })

    operator fun compareTo(other: Interval<TimeUnit>)
            = inMilliseconds.value.compareTo(other.inMilliseconds.value)

    operator fun contains(other: Interval<TimeUnit>)
            = inMilliseconds.value >= other.inMilliseconds.value

    override operator fun equals(other: Any?): Boolean {
        if (other == null || other !is Interval<TimeUnit>) return false
        return compareTo(other) == 0
    }

    override fun hashCode() = inMilliseconds.value.hashCode()
}


class Day : TimeUnit {
    override val timeIntervalRatio = 86400.0
}

class Hour : TimeUnit {
    override val timeIntervalRatio = 3600.0
}

class Minute : TimeUnit {
    override val timeIntervalRatio = 60.0
}

class Second : TimeUnit {
    override val timeIntervalRatio = 1.0
}

class Millisecond : TimeUnit {
    override val timeIntervalRatio = 0.001
}

class Microsecond : TimeUnit {
    override val timeIntervalRatio = 0.000001
}

class Nanosecond : TimeUnit {
    override val timeIntervalRatio = 1e-9
}


val Number.days: Interval<Day>
    get() = Interval(this.toDouble())

val Number.hours: Interval<Hour>
    get() = Interval(this.toDouble())

val Number.minutes: Interval<Minute>
    get() = Interval(this.toDouble())

val Number.seconds: Interval<Second>
    get() = Interval(this.toDouble())

val Number.milliseconds: Interval<Millisecond>
    get() = Interval(this.toDouble())

val Number.microseconds: Interval<Microsecond>
    get() = Interval(this.toDouble())

val Number.nanoseconds: Interval<Nanosecond>
    get() = Interval(this.toDouble())



{'fraction_non_alphanumeric': 0.11780028943560057, 'fraction_numerical': 0.011143270622286542, 'mean_word_length': 3.407525510204082, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 63, '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': '6247487', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2013, 'n_words': 501}