Initializer.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * TheseFoolishThings: Miscellaneous utilities
  5.  * http://tidalwave.it/projects/thesefoolishthings
  6.  *
  7.  * Copyright (C) 2009 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
  22.  * git clone https://github.com/tidalwave-it/thesefoolishthings-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.util;

  27. import jakarta.annotation.Nonnull;
  28. import java.io.Serializable;

  29. /***************************************************************************************************************************************************************
  30.  *
  31.  * @author  Fabrizio Giudici
  32.  * @it.tidalwave.javadoc.draft
  33.  *
  34.  **************************************************************************************************************************************************************/
  35. @FunctionalInterface
  36. public interface Initializer<T>
  37.   {
  38.     /***********************************************************************************************************************************************************
  39.      * @param object    an argument
  40.      * @return          the argument
  41.      **********************************************************************************************************************************************************/
  42.     public T initialize (@Nonnull T object);

  43.     /***********************************************************************************************************************************************************
  44.      * @param <T>       the static type
  45.      * @return          an empty initializer
  46.      * @since           3.2-ALPHA-2
  47.      **********************************************************************************************************************************************************/
  48.     @Nonnull
  49.     public static <T> Initializer<T> empty()
  50.       {
  51.         return new EmptyInitializer<>();
  52.       }

  53.     /***********************************************************************************************************************************************************
  54.      *
  55.      **********************************************************************************************************************************************************/
  56.     static final class EmptyInitializer<K> implements Initializer<K>, Serializable
  57.       {
  58.         private static final long serialVersionUID = 6039459583930596L;

  59.         @Override @Nonnull
  60.         public K initialize (@Nonnull final K entity)
  61.           {
  62.             return entity;
  63.           }
  64.       }
  65.   }