private E getLastEvent(E complexEvents) {
        E lastEvent = complexEvents;
        while (lastEvent != null && lastEvent.getNext() != null
                && lastEvent.getNext() != complexEvents) {
            lastEvent = (E) lastEvent.getNext();
        }
        if (lastEvent != null && lastEvent.getNext() == complexEvents) {
            //to detach the loop
            lastEvent.setNext(null);
            if (Level.WARN.isMoreSpecificThan(log.getLevel())) {
                //To help finding the root cause of the event loop, such that it can be fixed.
                //if this is an legitimate usecase increase the log level to ERROR for class ComplexEventChunk
                Exception exception = new RuntimeException("Unexpected event loop found!");
                log.warn(exception.getMessage() + " If the usecase is legitimate, increase the log " +
                        "level to ERROR for class: " + this.getClass().getName(), exception);
            }
        }
        return lastEvent;
    }
Collection used to group and manage chunk or ComplexEvents

@param <E> sub types of ComplexEvent such as StreamEvent and StateEvent
modules/siddhi-core/src/main/java/io/siddhi/core/event/ComplexEventChunk.java