org.commonjava.emb.plexus.ComponentSelector Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010 Red Hat, Inc.
*
* 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.
*/
package org.commonjava.emb.plexus;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class ComponentSelector
{
private Map, ComponentKey>> remappedComponentHints =
new HashMap, ComponentKey>>();
public ComponentSelector()
{
}
public ComponentSelector merge( final ComponentSelector selectorToCopy )
{
if ( selectorToCopy != null && !selectorToCopy.isEmpty() )
{
final Map, ComponentKey>> result = new HashMap, ComponentKey>>();
result.putAll( selectorToCopy.remappedComponentHints );
if ( !remappedComponentHints.isEmpty() )
{
result.putAll( remappedComponentHints );
}
remappedComponentHints = result;
}
return this;
}
public boolean isEmpty()
{
return remappedComponentHints.isEmpty();
}
public boolean hasOverride( final Class role, final String hint )
{
final ComponentKey check = new ComponentKey( role, hint );
return remappedComponentHints.containsKey( check );
}
public boolean hasOverride( final Class role )
{
final ComponentKey check = new ComponentKey( role );
return remappedComponentHints.containsKey( check );
}
public Set> getKeysOverriddenBy( final Class> role, final String hint )
{
@SuppressWarnings( { "rawtypes", "unchecked" } )
final ComponentKey check = new ComponentKey( role, hint );
final Set> result = new HashSet>();
for ( final Map.Entry, ComponentKey>> mapping : remappedComponentHints.entrySet() )
{
if ( mapping.getValue().equals( check ) )
{
result.add( mapping.getKey() );
}
}
return result;
}
public ComponentSelector setSelection( final ComponentKey originalKey, final String newHint )
{
remappedComponentHints.put( originalKey, new ComponentKey( originalKey.getRoleClass(), newHint ) );
return this;
}
public ComponentSelector setSelection( final Class role, final String oldHint, final String newHint )
{
final ComponentKey originalKey = new ComponentKey( role, oldHint );
remappedComponentHints.put( originalKey, new ComponentKey( role, newHint ) );
return this;
}
public ComponentSelector setSelection( final Class role, final String newHint )
{
final ComponentKey originalKey = new ComponentKey( role );
remappedComponentHints.put( originalKey, new ComponentKey( role, newHint ) );
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy