001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2025–2026 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
006 * the License. You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
012 * specific language governing permissions and limitations under the License.
013 */
014package org.microbean.assign;
015
016import java.util.List;
017
018/**
019 * A notional, opaque, stable collection of elements from which immutable sublists may be <dfn>selected</dfn> according
020 * to some <dfn>criteria</dfn>.
021 *
022 * @param <C> the criteria type
023 *
024 * @param <E> the element type
025 *
026 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
027 */
028@FunctionalInterface
029public interface Selectable<C, E> {
030
031  /**
032   * <em>Selects</em> and returns an immutable {@link List} representing a sublist of this {@link Selectable}'s
033   * elements, as mediated by the supplied criteria.
034   *
035   * <p>Implementations of this method must be idempotent and must be <dfn>stable</dfn>, <em>i. e.</em> return a
036   * determinate value.</p>
037   *
038   * <p>Implementations of this method must not return {@code null}.</p>
039   *
040   * @param criteria the criteria to use; may be {@code null} to indicate no particular criteria should be used during
041   * selection
042   *
043   * @return a non-{@code null}, immutable, determinate sublist of this {@link Selectable}'s elements effectively selected by the
044   * supplied {@code criteria}
045   */
046  // Filters this thing according to the supplied criteria, producing a List.
047  // List not Stream to permit caching
048  // List not Collection so equals() is well-defined
049  // List is unmodifiable and is always valid for the supplied criteria (unenforceable)
050  // C and not Predicate because equality semantics for Predicate are not well-defined (caching again)
051  public List<E> select(final C criteria);
052
053}