001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2025 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 list of elements from which immutable sublists may be <dfn>selected</dfn> according to some
020 * <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 return a determinate value.</p>
036   *
037   * <p>Implementations of this method must not return {@code null}.</p>
038   *
039   * @param criteria the criteria to use; may be {@code null} to indicate no particular criteria should be used during
040   * selection
041   *
042   * @return an immutable sublist of this {@link Selectable}'s elements effectively selected by the supplied {@code
043   * criteria}; never {@code null}
044   */
045  // Filters this thing according to the supplied criteria, producing a List.
046  // List not Stream to permit caching
047  // List not Collection so equals() is well-defined
048  // List is unmodifiable and is always valid for the supplied criteria (unenforceable)
049  // C and not Predicate because equality semantics for Predicate are not well-defined (caching again)
050  public List<E> select(final C criteria);
051
052}