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.repo; 019 020import com.google.common.collect.ImmutableList; 021 022import dev.enola.data.RepositoryBuilder; 023import dev.enola.data.Trigger; 024import dev.enola.thing.Thing; 025 026/** 027 * Builds a read-only Repository of {@link Thing}s. 028 * 029 * <p>{@link ThingMemoryRepositoryRW} is one of possibly several other alternatives for this. 030 */ 031public class ThingMemoryRepositoryROBuilder extends RepositoryBuilder<Thing> 032 implements ThingRepositoryStore { 033 034 public ThingMemoryRepositoryROBuilder(ImmutableList<Trigger<? extends Thing>> triggers) { 035 super(triggers); 036 } 037 038 public ThingMemoryRepositoryROBuilder() { 039 this(ImmutableList.of()); 040 } 041 042 @Override 043 protected String getIRI(Thing thing) { 044 return require(thing.iri(), "iri"); 045 } 046 047 @Override 048 public ThingMemoryRepositoryROBuilder store(Thing item) { 049 super.store(item); 050 return this; 051 } 052 053 @Override 054 public ThingMemoryRepositoryROBuilder storeAll(Iterable<Thing> items) { 055 super.storeAll(items); 056 return this; 057 } 058 059 @Override 060 public ThingRepository build() { 061 var thingRepository = super.build(); 062 return new ThingRepository() { 063 064 @Override 065 public Iterable<String> listIRI() { 066 return thingRepository.listIRI(); 067 } 068 069 @Override 070 public Thing get(String iri) { 071 return thingRepository.get(iri); 072 } 073 }; 074 } 075}