All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mercateo.jsonschema.schema.ObjectContext.kt Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package com.mercateo.jsonschema.schema

import com.mercateo.jsonschema.property.Property
import java.util.*

data class ObjectContext(
        val property: Property<*, T>,
        val defaultValue: T? = null,
        val allowedValues: Set = emptySet()
) {
    val propertyDescriptor get() = property.propertyDescriptor
    val reference get() = property.reference

    fun  createInner(child: Property, valueAccessor: (T) -> U?): ObjectContext {

        @Suppress("UNCHECKED_CAST")
        val allowedValues = allowedValues.map(valueAccessor).filter(
                Objects::nonNull).toSet() as Set

        val defaultValue = defaultValue?.let(valueAccessor)

        return ObjectContext(child, defaultValue, allowedValues)
    }
}