Skip to content

Content of file UserActionProvider.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>UserActionProvider.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">TheseFoolishThings - Java 8 Supplements</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.role.ui</a> &gt; <span class="el_source">UserActionProvider.java</span></div><h1>UserActionProvider.java</h1><pre class="source lang-java linenums">/*
 * #%L
 * *********************************************************************************************************************
 *
 * These Foolish Things - Miscellaneous utilities
 * http://thesefoolishthings.tidalwave.it - git clone git@bitbucket.org:tidalwave/thesefoolishthings-src.git
 * %%
 * Copyright (C) 2009 - 2021 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.
 *
 * *********************************************************************************************************************
 *
 * $Id$
 *
 * *********************************************************************************************************************
 * #L%
 */
package it.tidalwave.role.ui;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Arrays;
import java.util.Optional;
import it.tidalwave.util.NotFoundException;

/***********************************************************************************************************************
 *
 * A role that provides {@link UserAction}s.
 *
 * @stereotype role
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public interface UserActionProvider
  {
<span class="fc" id="L48">    public static final Class&lt;UserActionProvider&gt; UserActionProvider = UserActionProvider.class;</span>

    /*******************************************************************************************************************
     *
     * Returns a collection of {@link UserAction}s.
     *
     * @return  a collection of actions
     *
     ******************************************************************************************************************/
    @Nonnull
    public Collection&lt;? extends UserAction&gt; getActions();

    /*******************************************************************************************************************
     *
     * Returns the default action, if available.
     *
     *
     * @return                      the default action
     * @throws  NotFoundException   if there's no default action
     *
     ******************************************************************************************************************/
//    FIXME: should be deprecated in favour of getOptionalDefaultAction().
should be deprecated in favour of getOptionalDefaultAction().
@Nonnull public UserAction getDefaultAction() throws NotFoundException; /******************************************************************************************************************* * * Returns the default action, if available. * * @since 3.1-ALPHA-2 * @return the default action * ******************************************************************************************************************/ @Nonnull public default Optional&lt;UserAction&gt; getOptionalDefaultAction() { try { <span class="fc" id="L87"> return Optional.of(getDefaultAction());</span> } <span class="fc" id="L89"> catch (NotFoundException e)</span> { <span class="fc" id="L91"> return Optional.empty();</span> } } /******************************************************************************************************************* * * Factory method which creates an instance out of an array of {@link UserAction}s. The first one is considered the * default action. * * @since 3.1-ALPHA-2 * @param actions the actions * @return the {@code UserActionProvider} * ******************************************************************************************************************/ @Nonnull public static UserActionProvider of (final @Nonnull UserAction ... actions) { <span class="fc" id="L108"> return new UserActionProvider()</span> <span class="fc" id="L109"> {</span> @Override @Nonnull public Collection&lt;? extends UserAction&gt; getActions() { <span class="fc" id="L113"> return Arrays.asList(actions);</span> } @Override @Nonnull public UserAction getDefaultAction() throws NotFoundException { <span class="fc bfc" id="L120" title="All 2 branches covered."> if (actions.length == 0)</span> { <span class="fc" id="L122"> throw new NotFoundException();</span> } <span class="fc" id="L125"> return actions[0];</span> } }; } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.6.202009150832</span></div></body></html>