Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* This file is part of Codion.
*
* Codion is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Codion is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Codion. If not, see .
*
* Copyright (c) 2019 - 2024, Björn Darri Sigurðsson.
*/
package is.codion.framework.model;
import is.codion.framework.domain.entity.Entity;
import is.codion.framework.domain.entity.EntityType;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import static is.codion.framework.domain.entity.Entity.groupByType;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.*;
/**
* A central event hub for listening for entity inserts, updates and deletes.
* You must keep a live reference to any listeners added in order to prevent
* them from being garbage collected, since listeners are added via a {@link java.lang.ref.WeakReference}.
* {@link EntityEditModel} uses this to post its events.
* @see EntityEditModel#POST_EDIT_EVENTS
*/
public final class EntityEditEvents {
private static final EntityEditListener EDIT_LISTENER = new EntityEditListener();
private EntityEditEvents() {}
/**
* Adds an insert listener, notified each time entities of the given type are inserted.
* Note that you have to keep a live reference to the listener instance,
* otherwise it will be garbage collected, due to a weak reference.
* @param entityType the type of entity to listen for
* @param listener the listener
*/
public static void addInsertListener(EntityType entityType, Consumer> listener) {
EDIT_LISTENER.addInsertListener(entityType, listener);
}
/**
* Adds an update listener, notified each time entities of the given type are updated.
* Note that you have to keep a live reference to the listener instance,
* otherwise it will be garbage collected, due to a weak reference.
* @param entityType the type of entity to listen for
* @param listener the listener
*/
public static void addUpdateListener(EntityType entityType, Consumer