class SaveEventQueue {

    public void push(TransUnitSaveEvent event) {
        EventWrapper comingEvent = new EventWrapper(event);
        Optional<EventWrapper> previousEvent =
                Iterables.tryFind(eventQueue, new FindByTransUnitIdPredicate(
                        comingEvent.getId()));
        if (!previousEvent.isPresent()) {
            eventQueue.add(comingEvent);
            Log.info("pushed into queue:" + comingEvent);
            return;
        }
        // there is a previous pending item in it
        EventWrapper prevEvent = previousEvent.get();
        if (prevEvent.isSaving() && !stateEqual(event, prevEvent.toEvent())) {
            eventQueue.add(comingEvent);
            Log.info("saving event exist but this has new state. Pushed into queue:"
                    + comingEvent);
            return;
        }

        if (validState(comingEvent, prevEvent)) {
            replacePreviousEventIfApplicable(comingEvent, prevEvent);
        }
        Log.info("coming event will be discarded!" + event);
    }

}