Content of file ImplementationFactory.java.html

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>ImplementationFactory.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Mistral Processor</a> &gt; <a href="../index.html" class="el_bundle">image-core</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.image.op</a> &gt; <span class="el_source">ImplementationFactory.java</span></div><h1>ImplementationFactory.java</h1><pre class="source lang-java linenums">/*
 * *********************************************************************************************************************
 *
 * Mistral: open source imaging engine
 * http://tidalwave.it/projects/mistral
 *
 * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
 *
 * *********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * *********************************************************************************************************************
 *
 * git clone https://bitbucket.org/tidalwave/mistral-src
 * git clone https://github.com/tidalwave-it/mistral-src
 *
 * *********************************************************************************************************************
 */
package it.tidalwave.image.op;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import java.awt.image.BufferedImage;
import it.tidalwave.image.ImageModel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * @author Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="pc bpc" id="L44" title="1 of 2 branches missed.">@RequiredArgsConstructor @ToString(of = &quot;modelClass&quot;) @Slf4j</span>
public abstract class ImplementationFactory
  {
<span class="fc" id="L47">    @Getter @Nonnull</span>
    private final Class modelClass;

<span class="fc" id="L50">    private final Map&lt;Class&lt;? extends Operation&gt;, Class&lt;? extends OperationImplementation&gt;&gt; implementationMapping =</span>
            new HashMap&lt;&gt;();

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void registerImplementation (@Nonnull final Class&lt;? extends Operation&gt; operationClass,
                                        @Nonnull final Class&lt;? extends OperationImplementation&gt; implementationClass)
      {
<span class="fc" id="L60">        implementationMapping.put(operationClass, implementationClass);</span>
<span class="fc" id="L61">      }</span>

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void unregisterImplementation (@Nonnull final Class&lt;? extends Operation&gt; operationClass)
      {
<span class="nc" id="L69">        implementationMapping.remove(operationClass);</span>
<span class="nc" id="L70">      }</span>

    /*******************************************************************************************************************
     *
     * Finds the concrete implementation for a given operation.
     *
     * @param  operation  operation
     * @return the implementation (null if not supported)
     *
     ******************************************************************************************************************/
    @Nonnull
    public OperationImplementation&lt;Operation, Object&gt; findImplementation (@Nonnull final Operation operation)
      {
<span class="fc" id="L83">        final var implementationClass =</span>
<span class="fc" id="L84">                (Class&lt;OperationImplementation&lt;Operation, Object&gt;&gt;)implementationMapping.get(operation.getClass());</span>

<span class="pc bpc" id="L86" title="1 of 2 branches missed.">        if (implementationClass != null)</span>
          {
            try
              {
<span class="fc" id="L90">                final var implementation = implementationClass.newInstance();</span>
                // FIXME: drop these setters and pass to the constructor, so the object is truly immutable
drop these setters and pass to the constructor, so the object is truly immutable
<span class="fc" id="L92"> implementation.setFactory(this);</span> <span class="fc" id="L93"> implementation.bind(operation);</span> <span class="fc" id="L95"> return implementation;</span> } <span class="nc" id="L97"> catch (IllegalAccessException | InstantiationException e)</span> { <span class="nc" id="L99"> log.error(&quot;findImplementation()&quot;, e);</span> } } <span class="nc" id="L103"> return null;</span> } /******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public ImageModel createImageModel (@Nonnull final BufferedImage image) { <span class="nc" id="L113"> throw new UnsupportedOperationException();</span> } /******************************************************************************************************************* * * Return true if we can convert the given imageClass into our specific image * class. * ******************************************************************************************************************/ public abstract boolean canConvertFrom (@Nonnull Class imageClass); /******************************************************************************************************************* * * Converts the given image into our specific image representation. * ******************************************************************************************************************/ @Nonnull public abstract ImageModel convertFrom (@Nonnull Object image); /******************************************************************************************************************* * * ******************************************************************************************************************/ public abstract boolean canConvertTo (@Nonnull Class&lt;?&gt; imageClass); /******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public abstract Object convertTo (@Nonnull Object image); } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>