@FunctionalInterface public interface Registration extends Serializable
Modifier and Type | Method and Description |
---|---|
static <T> Registration |
addAndRemove(Collection<T> collection,
T item)
Creates a registration by adding an item to a collection immediately and
removing the item from the collection when the registration is removed.
|
static Registration |
combine(Registration... registrations)
Creates a registration that will remove multiple registrations.
|
static Registration |
once(Command command)
Creates a registration that will run a command only once.
|
void |
remove()
Removes the associated listener from the event source.
|
void remove()
The remove
method called after removal does nothing.
once(Command)
static Registration once(Command command)
command
- the command to run the first time the registration is removed,
not null
null
static Registration combine(Registration... registrations)
registrations
- the registrations to remove, not null
null
static <T> Registration addAndRemove(Collection<T> collection, T item)
Care should be used when using this pattern to iterate over a copy of the
collection to avoid ConcurrentModificationException
if a listener
or other callback may trigger adding or removing registrations.
collection
- the collection to which the item should be added and removed,
not null
item
- the item to add and removenull
Copyright © 2023. All rights reserved.