public Integer detectTemplate()

in tcbot-teamcity-ignited/src/main/java/org/apache/ignite/tcignited/history/AbstractRunHist.java [106:145]


    public Integer detectTemplate(IEventTemplate t) {
        int centralEvtBuild = t.beforeEvent().length;

        int[] template = concatArr(t.beforeEvent(), t.eventAndAfter());

        assert centralEvtBuild < template.length;
        assert centralEvtBuild >= 0;

        boolean includeMissing = t.includeMissing();

        List<Invocation> histAsArr = new ArrayList<>();
        for (Invocation invocation : invocations()) {
            if (includeMissing || invocation.status() != InvocationData.MISSING)
                histAsArr.add(invocation);
        }

        if (histAsArr.size() < template.length)
            return null;

        Integer detectedAt = null;

        //startIgnite from the end to find most recent
        for (int idx = histAsArr.size() - template.length; idx >= 0; idx--) {
            detectedAt = checkTemplateAtPos(template, centralEvtBuild, histAsArr, idx);

            if (detectedAt != null)
                break;
        }

        if (detectedAt != null && t.shouldBeFirstNonMissing()) {
            for (Invocation invocation : invocations()) {
                if (invocation.status() != InvocationData.MISSING)
                    return invocation.buildId() != detectedAt ? null : detectedAt;
            }

            return null;
        }

        return detectedAt;
    }