MessageSearcher.java

  1. package net.morimekta.providence.storage;

  2. import net.morimekta.providence.PMessage;
  3. import net.morimekta.providence.PMessageBuilder;

  4. import javax.annotation.Nonnull;
  5. import java.util.List;

  6. import static net.morimekta.providence.util.MessageUtil.toBuilderAll;

  7. /**
  8.  * Interface for searching a store for a specific search S.
  9.  *
  10.  * @param <Q> Search query param, be it single string or struct or union with search parameters.
  11.  * @param <M> PMessage that we search for.
  12.  */
  13. public interface MessageSearcher<Q, M extends PMessage<M>>
  14.         extends Searcher<Q, M> {
  15.     /**
  16.      * Get a list of builders for the query input. No modifications
  17.      * to the returned builders will be reflected onto the store.
  18.      *
  19.      * @param query The key to look up.
  20.      * @param <B>   The builder type.
  21.      * @return List of builders that matches query Q.
  22.      */
  23.     @Nonnull
  24.     default <B extends PMessageBuilder<M>>
  25.     List<B> searchBuilders(@Nonnull Q query) {
  26.         return toBuilderAll(search(query));
  27.     }
  28. }