io.annot8.common.implementations.factories.NotifyingItemFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of annot8-common-implementations Show documentation
Show all versions of annot8-common-implementations Show documentation
Common functionality used by Annot8 implementations
/* Annot8 (annot8.io) - Licensed under Apache-2.0. */
package io.annot8.common.implementations.factories;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import io.annot8.core.data.Item;
public class NotifyingItemFactory extends SimpleItemFactory {
private final Set> listeners = new HashSet<>();
public NotifyingItemFactory(ItemCreator creator) {
super(creator);
}
public void registerListener(Consumer- consumer) {
listeners.add(consumer);
}
public void unregisterListener(Consumer
- consumer) {
listeners.remove(consumer);
}
@Override
public Item create() {
Item item = super.create();
notifyListeners(item);
return item;
}
@Override
public Item create(Item parent) {
Item item = super.create(parent);
notifyListeners(item);
return item;
}
private void notifyListeners(Item item) {
listeners.forEach(l -> l.accept(item));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy