class MiscUtils extends AbstractCaller {

    @UtilityMethod
    @Description("Returns  the equality of the expected count of messages in accordance with the filter and the actual.<br/>"
            + "<b>collection</b> - messages for checking.<br/>"
            + "<b>filter</b> - filter message.<br/>"
            + "<b>expected</b> - expected number of occurrences of the filter message.<br/>"
            + "Considering the above said, the final syntax is:<br/>"
            + "#{getCount(collection, filter, expectedCount)}")
    public boolean checkCount(Collection<?> collection, Object filter, int expected) throws Exception {
        Objects.requireNonNull(collection, "collection cannot be null");
        Objects.requireNonNull(filter, "filter cannot be null");

        if (filter instanceof IMessage) {
            IMessage messageFilter = (IMessage)filter;
            int count = 0;
            StringBuilder knownBugBuilder = new StringBuilder();

            int itemCount = 0;
            for (Object object : collection) {
                if (object instanceof IMessage) {
                    ComparatorSettings settings = new ComparatorSettings();
                    IPostValidation validation = new KnownBugPostValidation(null, messageFilter);
                    settings.setPostValidation(validation);

                    IMessage message = (IMessage)object;
                    ComparisonResult comparisonResult = MessageComparator.compare(message, messageFilter, settings);
                    StatusType statusType = ComparisonUtil.getStatusType(comparisonResult);

                    if (statusType == StatusType.CONDITIONALLY_PASSED || statusType == StatusType.PASSED) {
                        count++;
                        if (statusType == StatusType.CONDITIONALLY_PASSED) {
                            knownBugBuilder.append(itemCount).append(" : ").append(comparisonResult.getExceptionMessage()).append(System.lineSeparator());
                        }
                    }
                }
                itemCount++;
            }

            if (count == expected) {
                if (knownBugBuilder.length() != 0) {
                    throw new FieldKnownBugException("Count equlas with known bugs", new BugDescription(knownBugBuilder.toString()));
                }
                return true;
            }
            return false;
        } else {
            return Collections.frequency(collection, filter) == expected;
        }
    }

}