001/*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2024-2026 The Enola <https://enola.dev> Authors
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package dev.enola.datatype;
019
020import com.google.errorprone.annotations.Immutable;
021
022import dev.enola.common.convert.ObjectToStringBiConverter;
023
024import java.lang.reflect.Type;
025import java.util.Optional;
026import java.util.regex.Pattern;
027
028@Immutable
029public interface Datatype<T> {
030    // NB: NOT extends Thing; there's a DatatypeThing for that!
031
032    /** IRI of this datatype. Always present, never null or empty. */
033    String iri();
034
035    /** Regular Expression {@link Pattern} which text of this datatype matches. */
036    Optional<Pattern> pattern();
037
038    /** Converter from/to T &lt;=&gt; text. */
039    ObjectToStringBiConverter<T> stringConverter();
040
041    /** Converter from/to Object (expected to be of T) &lt;==&gt; text. Just for convenience. */
042    @SuppressWarnings("unchecked")
043    default ObjectToStringBiConverter<Object> stringConverterFromObject() {
044        return (ObjectToStringBiConverter<Object>) stringConverter();
045    }
046
047    // BytesToObjectConverter<?> fromBytesConverter()
048
049    // ObjectToBytesConverter<?> toBytesConverter();
050
051    /**
052     * {@link Type} in Java.
053     *
054     * @return Java Type of this datatype, if any. (It may be unknown or N/A.)
055     */
056    Optional<Class<T>> javaType();
057
058    // TODO Optional<TypeToken<T>> javaTypeToken();
059
060    DatatypeBuilder<T> child();
061}