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.reference;
015
016import java.util.Objects;
017
018import java.util.function.Supplier;
019
020/**
021 * A skeletal implementation of the {@link ClientProxy} interface.
022 *
023 * @param <I> the type of contextual instance the implementation proxies
024 *
025 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
026 */
027public abstract class AbstractClientProxy<I> implements ClientProxy<I> {
028
029  private final Supplier<? extends I> s;
030
031  /**
032   * Creates a new {@link AbstractClientProxy}.
033   *
034   * @param s a {@link Supplier} of contextual instances; must not be {@code null}
035   *
036   * @exception NullPointerException if {@code s} is {@code null}
037   */
038  protected AbstractClientProxy(final Supplier<? extends I> s) {
039    super();
040    this.s = Objects.requireNonNull(s, "s");
041  }
042
043  @Override // ClientProxy<I>
044  public final I $proxied() {
045    return this.s.get(); // yes, each time
046  }
047
048}