-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.amazon.ionschema.model | ||
|
||
/** | ||
* A [ContinuousRange] of [TimestampPrecisionValue]. | ||
* `TimestampPrecision` is a discrete measurement (i.e. there is no fractional number of digits of precision). | ||
* However, because Ion Schema models timestamp precision as an enum, there are possible precisions that exist between | ||
* the available enum values. For example, `timestamp_precision: range::[exclusive::second, exclusive::millisecond]` | ||
* allows 1 or 2 digits of precision for the fractional seconds of a timestamp. | ||
*/ | ||
class TimestampPrecisionRange(start: Limit<TimestampPrecisionValue>, end: Limit<TimestampPrecisionValue>) : ContinuousRange<TimestampPrecisionValue>(start, end) { | ||
private constructor(value: Limit.Closed<TimestampPrecisionValue>) : this(value, value) | ||
constructor(value: TimestampPrecisionValue) : this(Limit.Closed(value)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.amazon.ionschema.writer.internal.constraints | ||
|
||
import com.amazon.ion.IonWriter | ||
import com.amazon.ionschema.model.Constraint | ||
import com.amazon.ionschema.model.ExperimentalIonSchemaModel | ||
import com.amazon.ionschema.writer.internal.writeTimestampPrecisionRange | ||
|
||
@ExperimentalIonSchemaModel | ||
internal object TimestampPrecisionWriter : ConstraintWriter { | ||
override val supportedClasses = setOf(Constraint.TimestampPrecision::class) | ||
Check warning on line 13 in ion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/TimestampPrecisionWriter.kt Codecov / codecov/patchion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/TimestampPrecisionWriter.kt#L13
|
||
|
||
override fun IonWriter.write(c: Constraint) { | ||
check(c is Constraint.TimestampPrecision) | ||
setFieldName("timestamp_precision") | ||
writeTimestampPrecisionRange(c.range) | ||
Check warning on line 18 in ion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/TimestampPrecisionWriter.kt Codecov / codecov/patchion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/TimestampPrecisionWriter.kt#L17-L18
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.amazon.ionschema.writer.internal.constraints | ||
|
||
import com.amazon.ion.IonWriter | ||
import com.amazon.ionschema.model.Constraint | ||
import com.amazon.ionschema.model.ExperimentalIonSchemaModel | ||
import com.amazon.ionschema.model.ValidValue | ||
import com.amazon.ionschema.writer.internal.writeIonValue | ||
import com.amazon.ionschema.writer.internal.writeNumberRange | ||
import com.amazon.ionschema.writer.internal.writeTimestampRange | ||
import com.amazon.ionschema.writer.internal.writeToList | ||
|
||
@ExperimentalIonSchemaModel | ||
internal object ValidValuesWriter : ConstraintWriter { | ||
override val supportedClasses = setOf(Constraint.ValidValues::class) | ||
Check warning on line 17 in ion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/ValidValuesWriter.kt Codecov / codecov/patchion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/ValidValuesWriter.kt#L17
|
||
|
||
override fun IonWriter.write(c: Constraint) { | ||
check(c is Constraint.ValidValues) | ||
setFieldName("valid_values") | ||
writeToList(c.values) { | ||
when (it) { | ||
Check warning on line 23 in ion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/ValidValuesWriter.kt Codecov / codecov/patchion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/ValidValuesWriter.kt#L21-L23
|
||
is ValidValue.NumberRange -> writeNumberRange(it) | ||
is ValidValue.TimestampRange -> writeTimestampRange(it) | ||
is ValidValue.Value -> writeIonValue(it.value) | ||
} | ||
} | ||
Check warning on line 28 in ion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/ValidValuesWriter.kt Codecov / codecov/patchion-schema/src/main/kotlin/com/amazon/ionschema/writer/internal/constraints/ValidValuesWriter.kt#L27-L28
|
||
} | ||
} |