class AbstractNotifiable<Solution_, T extends AbstractVariableListener<Solution_, Object>>
        implements EntityNotifiable<Solution_> {

    private final ScoreDirector<Solution_> scoreDirector;
    private final T variableListener;
    private final Collection<Notification<Solution_, ? super T>> notificationQueue;
    private final int globalOrder;

    static <Solution_> EntityNotifiable<Solution_> buildNotifiable(
            ScoreDirector<Solution_> scoreDirector,
            AbstractVariableListener<Solution_, Object> variableListener,
            int globalOrder) {<FILL_FUNCTION_BODY>}

    AbstractNotifiable(ScoreDirector<Solution_> scoreDirector,
            T variableListener,
            Collection<Notification<Solution_, ? super T>> notificationQueue,
            int globalOrder) {
        this.scoreDirector = scoreDirector;
        this.variableListener = variableListener;
        this.notificationQueue = notificationQueue;
        this.globalOrder = globalOrder;
    }

    @Override
    public void notifyBefore(EntityNotification<Solution_> notification) {
        if (notificationQueue.add(notification)) {
            notification.triggerBefore(variableListener, scoreDirector);
        }
    }

    protected boolean storeForLater(Notification<Solution_, T> notification) {
        return notificationQueue.add(notification);
    }

    protected void triggerBefore(Notification<Solution_, T> notification) {
        notification.triggerBefore(variableListener, scoreDirector);
    }

    @Override
    public void resetWorkingSolution() {
        variableListener.resetWorkingSolution(scoreDirector);
    }

    @Override
    public void closeVariableListener() {
        variableListener.close();
    }

    @Override
    public void triggerAllNotifications() {
        int notifiedCount = 0;
        for (Notification<Solution_, ? super T> notification : notificationQueue) {
            notification.triggerAfter(variableListener, scoreDirector);
            notifiedCount++;
        }
        if (notifiedCount != notificationQueue.size()) {
            throw new IllegalStateException("The variableListener (" + variableListener.getClass()
                    + ") has been notified with notifiedCount (" + notifiedCount
                    + ") but after being triggered, its notificationCount (" + notificationQueue.size()
                    + ") is different.\n"
                    + "Maybe that variableListener (" + variableListener.getClass()
                    + ") changed an upstream shadow variable (which is illegal).");
        }
        notificationQueue.clear();
    }

    @Override
    public String toString() {
        return "(" + globalOrder + ") " + variableListener;
    }
}

        if (variableListener instanceof ListVariableListener) {
            return new ListVariableListenerNotifiable<>(
                    scoreDirector,
                    ((ListVariableListener<Solution_, Object, Object>) variableListener),
                    new ArrayDeque<>(), globalOrder);
        } else {
            VariableListener<Solution_, Object> basicVariableListener = (VariableListener<Solution_, Object>) variableListener;
            return new VariableListenerNotifiable<>(
                    scoreDirector,
                    basicVariableListener,
                    basicVariableListener.requiresUniqueEntityEvents()
                            ? new ListBasedScalingOrderedSet<>()
                            : new ArrayDeque<>(),
                    globalOrder);
        }
    
<no_super_class>