Class MemoryRepositoryRW<T>

java.lang.Object
dev.enola.data.MemoryRepositoryRW<T>
All Implemented Interfaces:
Provider<String,T>, ProviderFromIRI<T>, Repository<T>, RepositoryRW<T>, Store<T>
Direct Known Subclasses:
ThingMemoryRepositoryRW

@ThreadSafe public abstract class MemoryRepositoryRW<T> extends Object implements RepositoryRW<T>
MemoryRepositoryRW is an in-memory RepositoryRW implemented using a ConcurrentHashMap. It is suitable for us by multiple concurrent threads.
  • Constructor Details

    • MemoryRepositoryRW

      protected MemoryRepositoryRW(com.google.common.collect.ImmutableList<Trigger<? extends T>> triggers)
  • Method Details

    • map

      protected Map<String,T> map()
    • getIRI

      protected abstract String getIRI(T value)
    • merge

      protected abstract T merge(T existing, T update)
    • store

      @CanIgnoreReturnValue public dev.enola.data.AbstractMapRepositoryRW<T> store(T item)
      Description copied from interface: Store
      Store a T.

      If this store already has this T, then it's replaced (entirely, not merged).

      Specified by:
      store in interface Store<T>
    • merge

      public void merge(T item)
      Description copied from interface: Store
      Merge a T into this store.

      If this store does not already have this T, then this does the same as Store.store(Object).

      Otherwise, an implementation specific strategy "merges" the existing and new T in the store. Note that this strategy may well be "additive" - meaning you cannot "remove" (or "blank out") properties!

      Specified by:
      merge in interface Store<T>
    • list

      public Iterable<T> list()
      Description copied from interface: Repository
      list() returns Ts directly (not just the IRIs, like Repository.listIRI()).

      This default implementation here just combines Repository.listIRI() and ProviderFromIRI.get(String). Your subclass may be able to provide a more efficient and more "direct" implementation?

      Specified by:
      list in interface Repository<T>
    • listIRI

      public Iterable<String> listIRI()
      Specified by:
      listIRI in interface Repository<T>
    • get

      public T get(String iri)
      Description copied from interface: Provider
      Get.
      Specified by:
      get in interface Provider<String,T>
      Specified by:
      get in interface ProviderFromIRI<T>
      Parameters:
      iri - Key, never null
      Returns:
      value, or null if there is no Value for the given key
    • trigger

      protected void trigger(T existing, T updated)