public class TLcyGenericComposite<T> extends Object implements Iterable<T>
A composite implementation of T
according to the composite design pattern.
When creating a TLcyGenericComposite<T>
using the default constructor (see
TLcyGenericComposite()
, the created instance will only work on/with the instances of
T
registered on this composite instance (see add(Object)
and remove(Object)
).
When creating a new TLcyGenericComposite<T>
using the constructor
specifying an ILcyLucyEnv
instance (see TLcyGenericComposite(com.luciad.lucy.ILcyLucyEnv, Class)
, the created instance will work on the
Lucy back-end services. It will
use all registered instances of T
of the Lucy back-end, adding and/or removing an
instance of T
will add/remove the instance as service from Lucy, ... .
Modifier and Type | Field and Description |
---|---|
static int |
PRIORITY_DEFAULT
Constant defining the normal priority.
|
static int |
PRIORITY_FALLBACK
Constant defining the fallback priority.
|
Constructor and Description |
---|
TLcyGenericComposite()
Default constructor.
|
TLcyGenericComposite(ILcyLucyEnv aLucyEnv,
Class<T> aServiceClass)
Construct a
TLcyGenericComposite working on the Lucy back-end. |
Modifier and Type | Method and Description |
---|---|
void |
add(T aService)
Adds the given instance of
T to the list of registered instances. |
void |
add(T aService,
int aPriority)
Adds the given instance of
T to the list of registered instances with the given
priority. |
List<T> |
getList()
Returns an unmodifiable
List containing all registered instances of
T . |
int |
getPriority(int aIndex)
Returns the priority for the service at the specified index
|
Iterator<T> |
iterator() |
void |
remove(T aService)
Removes the given instance of
T to the list of registered instances. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static final int PRIORITY_DEFAULT
Constant defining the normal priority. Services added with this priority constant have a
higher priority than services added with the PRIORITY_FALLBACK
constant. Its
value is the same as ILcyLucyEnv.PRIORITY_DEFAULT
.
add(Object, int)
,
Constant Field Valuespublic static final int PRIORITY_FALLBACK
Constant defining the fallback priority. Services added with this priority constant have a
lower priority than services added with the PRIORITY_NORMAL
constant. Its value is
the same as ILcyLucyEnv.PRIORITY_FALLBACK
.
add(Object, int)
,
Constant Field Valuespublic TLcyGenericComposite()
Default constructor.
The created instance will only work on the instances of T
registered to it. If
you want to use all registered instances of T
of the Lucy back-end, use TLcyGenericComposite(com.luciad.lucy.ILcyLucyEnv, Class)
instead.
public TLcyGenericComposite(ILcyLucyEnv aLucyEnv, Class<T> aServiceClass)
Construct a TLcyGenericComposite
working on the Lucy back-end.
It will use all instances of T
registered to the back-end, and adding an/or
removing instances of T
to/from this TLcyGenericComposite
will
respectively add/remove it as service from the back-end.
If you want to create a TLcyGenericComposite
which does not use the back-end,
use TLcyGenericComposite()
instead.
aLucyEnv
- The Lucy back-end. When null
, calling this constructor is
equivalent to calling the default constructor TLcyGenericComposite()
.aServiceClass
- The class of the service that this composite will manage. E.g. if you add
an object implementing T
and another interface, it will only
be registered as a service of class T
and not for the other
interface.public void add(T aService)
Adds the given instance of T
to the list of registered instances.
Equivalent of calling add(Object, int)
with PRIORITY_DEFAULT
aService
- The instance to add.remove(Object)
public void add(T aService, int aPriority)
Adds the given instance of T
to the list of registered instances with the given
priority. A single instance can only have one priority at a time, so it cannot be added twice
with two different priorities.
If the constructor specifying an ILcyLucyEnv
is used, the instance of
T
will be registered as a service on the Lucy back-end (see ILcyLucyEnv.addService(Object)
). When calling ILcyLucyEnv.getServices(Class)
afterwards, aService
will only be
included in the returned list when the requested class was the class specified in the
constructor.
Note: if you want to remove the registered instance of T
afterwards, use
remove(Object)
and not ILcyLucyEnv.removeService(Object)
.
aService
- The instance to add.aPriority
- The priority for the instance. Lower values mean higher priorities. Services
with higher priority appear earlier in the list of results. Common values are
PRIORITY_DEFAULT
and PRIORITY_FALLBACK
public void remove(T aService)
Removes the given instance of T
to the list of registered instances. Nothing
will happen if the given instance was never added before.
If the constructor specifying an ILcyLucyEnv
is used, the instance of
T
will be removed as a service on the Lucy back-end (see ILcyLucyEnv.addService(Object)
).
Note: it is only possible to remove instances of T
which were registered
using the add(Object)
method.
aService
- The instance to add.remove(Object)
public List<T> getList()
Returns an unmodifiable List
containing all registered instances of
T
.
List
containing all registered instances of
T
.public int getPriority(int aIndex)
aIndex
- The index of the service for which the priority should be returned.