<commit_before>package com.googlecode.totallylazy.matchers;

import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Function1;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.predicates.LogicalPredicate;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.SelfDescribing;
import org.hamcrest.TypeSafeMatcher;

import static com.googlecode.totallylazy.Sequences.sequence;
import static com.googlecode.totallylazy.Unchecked.cast;
import static org.hamcrest.StringDescription.asString;

public class Matchers {

    public static <T> Iterable<Matcher<T>> are(final Iterable<T> values, Class<T> clazz) {
        return are(values);
    }

    public static <T> Iterable<Matcher<T>> are(final Iterable<T> values) {
        return sequence(values).map(Matchers.<T>isMatcher());
    }

    public static Function1<SelfDescribing, String> description() {
        return new Function1<SelfDescribing, String>() {
            @Override
            public String call(SelfDescribing selfDescribing) throws Exception {
                return asString(selfDescribing);
            }
        };
    }<commit_msg>Added functions to describe or diagnose mismatches in hamcrest Matchers<commit_after>package com.googlecode.totallylazy.matchers;

import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Function1;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.predicates.LogicalPredicate;
import org.hamcrest.Description;
import org.hamcrest.DiagnosingMatcher;
import org.hamcrest.Matcher;
import org.hamcrest.SelfDescribing;
import org.hamcrest.StringDescription;
import org.hamcrest.TypeSafeMatcher;

import static com.googlecode.totallylazy.Callables.returns1;
import static com.googlecode.totallylazy.Sequences.sequence;
import static com.googlecode.totallylazy.Unchecked.cast;
import static org.hamcrest.StringDescription.asString;

public class Matchers {

    public static <T> Iterable<Matcher<T>> are(final Iterable<T> values, Class<T> clazz) {
        return are(values);
    }

    public static <T> Iterable<Matcher<T>> are(final Iterable<T> values) {
        return sequence(values).map(Matchers.<T>isMatcher());
    }

    public static Function1<SelfDescribing, String> description() {
        return new Function1<SelfDescribing, String>() {
            @Override
            public String call(SelfDescribing selfDescribing) throws Exception {
                return asString(selfDescribing);
            }
        };
    }

    public static <T> Function1<T, String> describeMismatch(Class<T> type, final Matcher<? super T> matcher) {
        return describeMismatch(matcher);
    }

    public static <T> Function1<T, String> describeMismatch(final Matcher<? super T> matcher) {
        if (matcher instanceof DiagnosingMatcher)
            return diagnoseMismatch((DiagnosingMatcher) matcher);
        return returns1(StringDescription.asString(matcher));
    }

    public static <T> Function1<T, String> diagnoseMismatch(Class<T> type, final DiagnosingMatcher matcher) {
        return diagnoseMismatch(matcher);
    }

    public static <T> Function1<T, String> diagnoseMismatch(final DiagnosingMatcher matcher) {
        return new Function1<T, String>() {
            @Override
            public String call(T t) throws Exception {
                StringDescription mismatchDescription = new StringDescription();
                matcher.describeMismatch(t, mismatchDescription);
                return mismatchDescription.toString();
            }
        };
    }
{'fraction_non_alphanumeric': 0.0924439523941323, 'fraction_numerical': 0.004151674508718516, 'mean_word_length': 3.8122503328894806, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558752', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1019, 'n_words': 224}