New component record - Unspecific dependency injector storage

Dependency injection functions are now stored as type-unspecific. This
makes them easier to use.
This commit is contained in:
Emmanuel BENOîT 2015-09-15 09:40:46 +02:00
parent a932b90b7d
commit 5dc745670b
2 changed files with 22 additions and 18 deletions

View file

@ -305,7 +305,7 @@ public final class NewComponentInfo< T >
/** Lifecylce actions for the new component */
private final EnumMap< LifecycleStage , ThrowingConsumer< ? super T > > lcActions;
/** Dependency injectors */
private final HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super T , Object > > > injectors;
private final HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors;
/** Whether the component should be activated automatically */
private boolean autostart;
@ -505,7 +505,7 @@ public final class NewComponentInfo< T >
* @return the modifiable map of dependency injectors, with the dependency information as the key and a list of
* functions that inject the dependency into the target component as the value.
*/
public HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super T , Object > > > getInjectors( )
public HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > getInjectors( )
{
return this.injectors;
}
@ -524,12 +524,16 @@ public final class NewComponentInfo< T >
public NewComponentInfo< T > addDependencyInjector( final DependencyInfo dependency ,
final ThrowingBiConsumer< ? super T , Object > injector )
{
ArrayList< ThrowingBiConsumer< ? super T , Object > > injectors = this.injectors.get( dependency );
ArrayList< ThrowingBiConsumer< Object , Object > > injectors = this.injectors.get( dependency );
if ( injectors == null ) {
injectors = new ArrayList< >( );
this.injectors.put( dependency , injectors );
}
injectors.add( injector );
@SuppressWarnings( "unchecked" )
ThrowingBiConsumer< Object , Object > ci = (ThrowingBiConsumer< Object , Object >) injector;
injectors.add( ci );
this.dependencies.add( dependency );
return this;
}

View file

@ -527,10 +527,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp8 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp8 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp8 , Object > injector = diList.get( 0 );
assertNotNull( injector );
@ -556,10 +556,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp9 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp9 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp9 , Object > injector = diList.get( 0 );
assertNotNull( injector );
@ -626,10 +626,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp10 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp10 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp10 , Object > injector = diList.get( 0 );
assertNotNull( injector );
@ -655,10 +655,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp11 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp11 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp11 , Object > injector = diList.get( 0 );
assertNotNull( injector );
@ -739,10 +739,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp12 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp12 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp12 , Object > injector = diList.get( 0 );
assertNotNull( injector );
@ -767,10 +767,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp13 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp13 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp13 , Object > injector = diList.get( 0 );
assertNotNull( injector );
@ -796,10 +796,10 @@ public class TestNewComponentInfo
assertEquals( 1 , deps.size( ) );
assertTrue( deps.contains( expectedDep ) );
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< ? super TestCmp14 , Object > > > injectors = nci
HashMap< DependencyInfo , ArrayList< ThrowingBiConsumer< Object , Object > > > injectors = nci
.getInjectors( );
assertEquals( 1 , injectors.size( ) );
ArrayList< ThrowingBiConsumer< ? super TestCmp14 , Object > > diList = injectors.get( expectedDep );
ArrayList< ThrowingBiConsumer< Object , Object > > diList = injectors.get( expectedDep );
assertEquals( 1 , diList.size( ) );
ThrowingBiConsumer< ? super TestCmp14 , Object > injector = diList.get( 0 );
assertNotNull( injector );