package com.opencredo.concourse.mapping.events.methods.ordering;

import com.opencredo.concourse.domain.events.Event;
import com.opencredo.concourse.domain.events.EventType;

import java.util.Comparator;
import java.util.Map;

public final class CausalOrdering {

    public static final int INITIAL = Integer.MIN_VALUE;
    public static final int TERMINAL = Integer.MAX_VALUE;
    public static final int PRE_TERMINAL = TERMINAL - 1;

    private CausalOrdering() {
    }

    public static Comparator<Event> onEventTypes(Map<EventType, Integer> eventTypeMap) {
        return Comparator.comparing((Event evt) -> eventTypeMap.getOrDefault(EventType.of(evt), PRE_TERMINAL))
                .thenComparing(Event::getEventTimestamp);
    }
}

@@ -111,16 +111,83 @@
 .Event;%0A
+import com.opencredo.concourse.domain.events.EventCharacteristics;%0A
 import c
@@ -723,80 +723,428 @@
 vt),
- PRE_TERMINAL))%0A                .thenComparing(Event::getEventTimestamp)
+%0A                getDefaultOrderBasedOnCharacteristics(evt)))%0A                .thenComparing(Event::getEventTimestamp);%0A    %7D%0A%0A    private static int getDefaultOrderBasedOnCharacteristics(Event evt) %7B%0A        return evt.hasCharacteristic(EventCharacteristics.IS_INITIAL)%0A            ? INITIAL%0A            : evt.hasCharacteristic(EventCharacteristics.IS_TERMINAL)%0A                ? TERMINAL%0A                : PRE_TERMINAL
 ;%0A  

Use event characteristics in causal ordering