
it.tidalwave.util.spi.PriorityAsSupport Maven / Gradle / Ivy
The newest version!
/*
* *********************************************************************************************************************
*
* blueMarine II: Semantic Media Centre
* http://tidalwave.it/projects/bluemarine2
*
* Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
*
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); 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 "AS IS" 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/bluemarine2-src
* git clone https://github.com/tidalwave-it/bluemarine2-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.util.spi;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import it.tidalwave.util.As;
import it.tidalwave.util.AsException;
import it.tidalwave.dci.annotation.DciRole;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* A specialisation of {@link AsSupport} that deals with multiple roles of the same type by prioritising them; they
* are ordered from most relevant to least relevant (where relevance is associated to specialisation, that is most
* specialised roles, or roles associated via {@code @DciRole} to most specialised datum classes, are most relevant).
*
* FIXME: could be seen as a replacement to {@code AsSupport}?
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
@Slf4j
public class PriorityAsSupport extends AsSupport implements As
{
@FunctionalInterface
public static interface RoleProvider
{
@Nonnull
public Collection findRoles (@Nonnull final Class type);
}
@Nonnull
private final Object owner; // for logging only
@Nonnull
private final Optional additionalRoleProvider;
public PriorityAsSupport (final Object owner)
{
this(owner, Collections.emptyList());
}
public PriorityAsSupport (@Nonnull final Object owner, @Nonnull final Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy