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.bean;
015
016/**
017 * A supplier of {@link References} objects.
018 *
019 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
020 *
021 * @see #references(AttributedType)
022 *
023 * @see #reference(AttributedType)
024 *
025 * @see References
026 */
027public interface ReferencesSelector {
028
029  /**
030   * Returns a {@link References} capable of locating contextual references of the relevant type.
031   *
032   * @param <R> the contextual reference type
033   *
034   * @param t an {@link AttributedType} describing the contextual reference type; must not be {@code null}
035   *
036   * @return a non-{@code null} {@link References}
037   *
038   * @exception NullPointerException if {@code t} is {@code null}
039   *
040   * @see References
041   */
042  public <R> References<R> references(final AttributedType t);
043
044  /**
045   * Returns the sole contextual reference of the relevant type.
046   *
047   * @param <R> the contextual reference type
048   *
049   * @param t an {@link AttributedType} describing the contextual reference type; must not be {@code null}
050   *
051   * @return a non-{@code null} contextual reference
052   *
053   * @exception NullPointerException if {@code t} is {@code null}
054   *
055   * @exception UnsatisfiedReductionException if there is no contextual reference for the relevant type
056   *
057   * @exception AmbiguousReductionException if there is more than one contextual reference for the relevant type
058   */
059  public default <R> R reference(final AttributedType t) {
060    return this.<R>references(t).get();
061  }
062
063}