2023-06-20 19:45:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2018-2023 KMath contributors.
|
|
|
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package space.kscience.attributes
|
|
|
|
|
|
|
|
import kotlin.reflect.KType
|
|
|
|
|
|
|
|
public interface Attribute<T>
|
|
|
|
|
2023-07-09 15:51:50 +03:00
|
|
|
/**
|
|
|
|
* An attribute that could be either present or absent
|
|
|
|
*/
|
|
|
|
public interface FlagAttribute : Attribute<Unit>
|
2023-06-20 19:45:21 +03:00
|
|
|
|
2023-07-09 15:51:50 +03:00
|
|
|
/**
|
|
|
|
* An attribute with a default value
|
|
|
|
*/
|
2023-06-20 19:45:21 +03:00
|
|
|
public interface AttributeWithDefault<T> : Attribute<T> {
|
|
|
|
public val default: T
|
|
|
|
}
|
|
|
|
|
2023-07-09 15:51:50 +03:00
|
|
|
/**
|
|
|
|
* Attribute containing a set of values
|
|
|
|
*/
|
2023-06-20 19:45:21 +03:00
|
|
|
public interface SetAttribute<V> : Attribute<Set<V>>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An attribute that has a type parameter for value
|
2023-07-09 15:51:50 +03:00
|
|
|
* @param type parameter-type
|
2023-06-20 19:45:21 +03:00
|
|
|
*/
|
2023-07-09 15:51:50 +03:00
|
|
|
public abstract class PolymorphicAttribute<T>(public val type: SafeType<T>) : Attribute<T> {
|
|
|
|
override fun equals(other: Any?): Boolean = other != null &&
|
|
|
|
(this::class == other::class) &&
|
|
|
|
(other as? PolymorphicAttribute<*>)?.type == this.type
|
2023-06-20 19:45:21 +03:00
|
|
|
|
2023-07-09 15:51:50 +03:00
|
|
|
override fun hashCode(): Int = this::class.hashCode() + type.hashCode()
|
2023-06-20 19:45:21 +03:00
|
|
|
}
|