org.omnaest.utils.beans.autowired
Interface AutowiredContainer<E>

All Superinterfaces:
Iterable<E>, Serializable
All Known Subinterfaces:
AutowiredPropertyContainer
All Known Implementing Classes:
AutowiredContainerAbstract, AutowiredContainerDecorator, ClassMapToAutowiredContainerAdapter, TypeToAutowiredPropertyContainerAdapter

public interface AutowiredContainer<E>
extends Iterable<E>, Serializable

An AutowiredContainer represents a high level container of objects which can be retrieved by the Class types they are assignable to.

This results in the use of interfaces or classes as keys when object instances are put into the AutowiredContainer.

Usage example:

 public interface ExampleInterface
 {
 }
 
 public class Example extends ExampleInterface
 {
 }
 
 {
   Example example = new Example();
   autowiredContainer.put( example );
   
   assertEquals( 1, autowiredContainer.getValueSet( Example.class ).size() );
   assertEquals( example, autowiredContainer.getValue( Example.class ) );
   
   assertEquals( 1, autowiredContainer.getValueSet( ExampleInterface.class ).size() );
   assertEquals( example, autowiredContainer.getValue( ExampleInterface.class ) );
 }
 

Depending on the implementation of the AutowiredContainer the behavior of how many objects can be put into the AutowiredContainer for the same Class type e.g. can differ.

This container is not intended to have many objects stored within it, instead it should allow to overcome the common use of Map<String,Object> for an untyped but very flexible store possibility.

Author:
Omnaest
See Also:
AutowiredContainerUtils, ListUtils.valueOf(Iterable), SetUtils.valueOf(Iterable), AutowiredContainerAbstract

Method Summary
<O extends E>
boolean
containsAssignable(Class<O> type)
          Returns true if the current container contains any type which can be assigned to the given one.
<O extends E>
O
getValue(Class<? extends O> type)
          Returns the value which can be assigned as value to the given Class type.
<O extends E>
Set<O>
getValueSet(Class<? extends O> type)
          Returns a Set for all values which can be assigned to the given Class.
 boolean isEmpty()
          Returns true if there are no elements within this container.
 AutowiredContainer<E> put(E object)
          Adds an Object to the AutowiredContainer using its Object.getClass() as primary type.
<O extends E>
AutowiredContainer<E>
put(O object, Class<? extends O>... types)
          Adds an Object to the AutowiredContainer for one or more given Class types.
 AutowiredContainer<E> putAll(Iterable<E> iterable)
          Adds multiple Objects to the AutowiredContainer.
<O extends E>
AutowiredContainer<E>
remove(O object)
          Removes the given element from the AutowiredContainer
 AutowiredContainer<E> removeAllAssignableTo(Class<? extends E> type)
          Removes all elements within the AutowiredContainer which are Class.isAssignableFrom(Class) to the given type.
 AutowiredContainer<E> removeAllHavingExactTypeOf(Class<? extends E> type)
          Removes all elements within the AutowiredContainer which are put into the container with the given primary type.
 int size()
          Returns the size of the AutowiredContainer
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

getValue

<O extends E> O getValue(Class<? extends O> type)
Returns the value which can be assigned as value to the given Class type. If there are multiple values available with fitting types null is returned.

Type Parameters:
O -
Parameters:
type -
Returns:

getValueSet

<O extends E> Set<O> getValueSet(Class<? extends O> type)
Returns a Set for all values which can be assigned to the given Class.

Type Parameters:
O -
Parameters:
type -

containsAssignable

<O extends E> boolean containsAssignable(Class<O> type)
Returns true if the current container contains any type which can be assigned to the given one.

Parameters:
type -
Returns:

isEmpty

boolean isEmpty()
Returns true if there are no elements within this container.

Returns:

put

AutowiredContainer<E> put(E object)
Adds an Object to the AutowiredContainer using its Object.getClass() as primary type.

Parameters:
object -
Returns:
this
See Also:
put(Object, Class...), putAll(Iterable)

putAll

AutowiredContainer<E> putAll(Iterable<E> iterable)
Adds multiple Objects to the AutowiredContainer.

Parameters:
iterable -
Returns:
this
See Also:
put(Object)

put

<O extends E> AutowiredContainer<E> put(O object,
                                        Class<? extends O>... types)
Adds an Object to the AutowiredContainer for one or more given Class types.

Parameters:
object -
types -
Returns:
this
See Also:
put(Object)

remove

<O extends E> AutowiredContainer<E> remove(O object)
Removes the given element from the AutowiredContainer

Parameters:
object -
Returns:
this

removeAllHavingExactTypeOf

AutowiredContainer<E> removeAllHavingExactTypeOf(Class<? extends E> type)
Removes all elements within the AutowiredContainer which are put into the container with the given primary type.

Parameters:
type -
Returns:
this
See Also:
removeAllAssignableTo(Class)

removeAllAssignableTo

AutowiredContainer<E> removeAllAssignableTo(Class<? extends E> type)
Removes all elements within the AutowiredContainer which are Class.isAssignableFrom(Class) to the given type.

Parameters:
type -
Returns:
this
See Also:
removeAllHavingExactTypeOf(Class)

size

int size()
Returns the size of the AutowiredContainer

Returns:


Copyright © 2013. All Rights Reserved.