public abstract class Registries extends Object
registries
.Modifier and Type | Method and Description |
---|---|
static <O> RegistryBuilder |
add(Class<? super O> type,
O object)
Adds a registry entry that is available by the given type.
|
static <O> RegistryBuilder |
add(Class<O> type,
Factory<? extends O> factory)
Adds a lazily created entry to the registry.
|
static RegistryBuilder |
add(Object object)
Adds a registry entry.
|
static Registry |
join(Registry parent,
Registry child)
Joins the given registries into a new registry.
|
static <T> Registry |
just(Class<? super T> publicType,
T implementation)
Creates a single entry registry, using
RegistryBuilder.add(Class, Object) . |
static <T> Registry |
just(Class<T> publicType,
Factory<? extends T> factory)
Creates a single lazily created entry registry, using
RegistryBuilder.add(Class, Factory) . |
static Registry |
just(Object object)
Creates a single entry registry, using
RegistryBuilder.add(Object) . |
static RegistryBuilder |
registry()
Creates a new
registry builder . |
static Registry |
registry(Action<? super RegistrySpec> action)
Builds a registry from the given action.
|
public static <O> RegistryBuilder add(Class<? super O> type, O object)
O
- the public type of the registry entrytype
- the public type of the registry entryobject
- the actual registry entrypublic static RegistryBuilder add(Object object)
object
- the object to add to the registrypublic static <O> RegistryBuilder add(Class<O> type, Factory<? extends O> factory)
The factory will be invoked exactly once, when a query is made to the registry of a compatible type of the given type.
O
- the public type of the registry entrytype
- the public type of the registry entryfactory
- the factory for creating the object when neededpublic static Registry join(Registry parent, Registry child)
The returned registry is effectively the union of the two registries, with the child
taking precedence.
This means that child entries are effectively “returned first”.
import ratpack.registry.Registry; import static ratpack.registry.Registries.registry; import static ratpack.registry.Registries.join; public interface Thing { String getName() } public class ThingImpl implements Thing { private final String name public ThingImpl(String name) { this.name = name; } public String getName() { return name; } } Registry child = registry().add(Thing.class, new ThingImpl("child-1")).add(Thing.class, new ThingImpl("child-2")).build(); Registry parent = registry().add(Thing.class, new ThingImpl("parent-1")).add(Thing.class, new ThingImpl("parent-2")).build(); Registry joined = join(parent, child); assert joined.get(Thing.class).getName() == "child-1"; List<Thing> all = joined.getAll(Thing.class); assert all.get(0).getName() == "child-1"; assert all.get(1).getName() == "child-2"; assert all.get(2).getName() == "parent-1"; assert all.get(3).getName() == "parent-2";
parent
- the parent registrychild
- the child registrypublic static <T> Registry just(Class<T> publicType, Factory<? extends T> factory)
RegistryBuilder.add(Class, Factory)
.T
- the public type of the entrypublicType
- the public type of the entryfactory
- the factory for the objectRegistryBuilder.add(Class, Factory)
public static Registry just(Object object)
RegistryBuilder.add(Object)
.object
- the entry objectRegistryBuilder.add(java.lang.Object)
public static <T> Registry just(Class<? super T> publicType, T implementation)
RegistryBuilder.add(Class, Object)
.T
- the public type of the entrypublicType
- the public type of the entryimplementation
- the entry objectRegistryBuilder.add(Class, Object)
public static RegistryBuilder registry()
registry builder
.RegistryBuilder
public static Registry registry(Action<? super RegistrySpec> action) throws Exception
action
- the action that defines the registryException
- any thrown by the actionRegistrySpecAction