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.thing.impl;
019
020import com.google.common.collect.ImmutableMap;
021import com.google.common.collect.ImmutableSet;
022
023import dev.enola.common.context.TLC;
024import dev.enola.thing.Thing;
025import dev.enola.thing.java.TBF;
026
027import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
028
029import org.jspecify.annotations.Nullable;
030
031/**
032 * {@link Thing} with only an IRI and no properties (optimized).
033 *
034 * <p>See {@link dev.enola.thing.repo.AlwaysThingProvider}.
035 */
036// TODO Make OnlyIRIThing package private; this should only be used by AlwaysThingProvider!
037@SuppressFBWarnings("EQ_DOESNT_OVERRIDE_EQUALS")
038// skipcq: JAVA-W0100
039public class OnlyIRIThing implements IImmutableThing {
040
041    private final String iri;
042
043    public OnlyIRIThing(String iri) {
044        this.iri = iri;
045    }
046
047    @Override
048    public String iri() {
049        return iri;
050    }
051
052    @Override
053    public ImmutableMap<String, Object> properties() {
054        return ImmutableMap.of();
055    }
056
057    @Override
058    public ImmutableSet<String> predicateIRIs() {
059        return ImmutableSet.of();
060    }
061
062    @Override
063    public @Nullable String datatype(String predicateIRI) {
064        return null;
065    }
066
067    @Override
068    public ImmutableMap<String, String> datatypes() {
069        return ImmutableMap.of();
070    }
071
072    @Override
073    public <T> @Nullable T get(String predicateIRI) {
074        return null;
075    }
076
077    @Override
078    public Thing.Builder<? extends Thing> copy() {
079        return TLC.get(TBF.class).create();
080    }
081
082    @Override
083    public final int hashCode() {
084        return ThingHashCodeEqualsToString.hashCode(this);
085    }
086
087    @Override
088    public final boolean equals(Object obj) {
089        return ThingHashCodeEqualsToString.equals(this, obj);
090    }
091
092    @Override
093    public final String toString() {
094        return ThingHashCodeEqualsToString.toString(this, properties(), datatypes());
095    }
096}