// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/HasSameItemsAsCollectionMatcher.java
// @Factory
// public static <T> Matcher<Collection<? extends T>> hasSameItemsAsCollection(Collection<? extends T> correctList) {
//     return new HasSameItemsAsCollectionMatcher<>(correctList);
// }
// 
// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/MismatchHelper.java
// @SuppressWarnings("unchecked")
// public static void appendMismatch(Description mismatchDescription, String comment, Collection collectionToPrint) {
//     if (collectionToPrint.size() > 0) {
//         mismatchDescription.appendText("\n(").appendText(comment)
//                 .appendText(") [")
//                 .appendValue(collectionToPrint.size())
//                 .appendText("]:\n")
//                 .appendValueList("-> ", "\n-> ", "", collectionToPrint);
//     }
// }
// 
// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/WrapperConverter.java
// public static <T> WrapperConverter<T> wrap(List<? extends T> list, WrapperFactory<T> factory) {
//     return new WrapperConverter<T>(list, factory);
// }


import ch.lambdaj.collection.LambdaList;
import org.hamcrest.*;
import java.util.Collection;
import java.util.List;
import static ch.lambdaj.collection.LambdaCollections.with;
import static org.hamcrest.Matchers.*;
import static ru.yandex.qatools.matchers.collection.HasSameItemsAsCollectionMatcher.hasSameItemsAsCollection;
import static ru.yandex.qatools.matchers.collection.MismatchHelper.appendMismatch;
import static ru.yandex.qatools.matchers.collection.WrapperConverter.wrap;
package ru.yandex.qatools.matchers.collection;




/**
 * Created with IntelliJ IDEA.
 * User: lanwen
 * Date: 25.05.13
 * Time: 21:35
 */
public class HasSameItemsAsListMatcher<T> extends TypeSafeDiagnosingMatcher<List<? extends T>> {
    private List<? extends T> expected;

    @SuppressWarnings("unchecked")
    private WrapperFactory<T> wrapperFactory = (WrapperFactory<T>) ObjectMethodsWrapper.standardMethods();

    private boolean sortcheck = false;

    public HasSameItemsAsListMatcher(List<? extends T> expect) {
        this.expected = expect;
    }

    public HasSameItemsAsListMatcher<T> useWrapperFactory(WrapperFactory<T> wrapperFactory) {
        if (wrapperFactory == null) {
            throw new IllegalArgumentException("Wrapper factory can't be null");
        }
        this.wrapperFactory = wrapperFactory;
        return this;
    }

    public HasSameItemsAsListMatcher<T> sameSorted() {
        sortcheck = true;
        return this;
    }


    @Override
    protected boolean matchesSafely(List<? extends T> actual, Description mismatchDescription) {
// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/HasSameItemsAsCollectionMatcher.java
// @Factory
// public static <T> Matcher<Collection<? extends T>> hasSameItemsAsCollection(Collection<? extends T> correctList) {
//     return new HasSameItemsAsCollectionMatcher<>(correctList);
// }
// 
// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/MismatchHelper.java
// @SuppressWarnings("unchecked")
// public static void appendMismatch(Description mismatchDescription, String comment, Collection collectionToPrint) {
//     if (collectionToPrint.size() > 0) {
//         mismatchDescription.appendText("\n(").appendText(comment)
//                 .appendText(") [")
//                 .appendValue(collectionToPrint.size())
//                 .appendText("]:\n")
//                 .appendValueList("-> ", "\n-> ", "", collectionToPrint);
//     }
// }
// 
// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/WrapperConverter.java
// public static <T> WrapperConverter<T> wrap(List<? extends T> list, WrapperFactory<T> factory) {
//     return new WrapperConverter<T>(list, factory);
// }


// Path: collection-matchers/src/main/java/ru/yandex/qatools/matchers/collection/HasSameItemsAsListMatcher.java
import ch.lambdaj.collection.LambdaList;
import org.hamcrest.*;
import java.util.Collection;
import java.util.List;
import static ch.lambdaj.collection.LambdaCollections.with;
import static org.hamcrest.Matchers.*;
import static ru.yandex.qatools.matchers.collection.HasSameItemsAsCollectionMatcher.hasSameItemsAsCollection;
import static ru.yandex.qatools.matchers.collection.MismatchHelper.appendMismatch;
import static ru.yandex.qatools.matchers.collection.WrapperConverter.wrap;

package ru.yandex.qatools.matchers.collection;




/**
 * Created with IntelliJ IDEA.
 * User: lanwen
 * Date: 25.05.13
 * Time: 21:35
 */
public class HasSameItemsAsListMatcher<T> extends TypeSafeDiagnosingMatcher<List<? extends T>> {
    private List<? extends T> expected;

    @SuppressWarnings("unchecked")
    private WrapperFactory<T> wrapperFactory = (WrapperFactory<T>) ObjectMethodsWrapper.standardMethods();

    private boolean sortcheck = false;

    public HasSameItemsAsListMatcher(List<? extends T> expect) {
        this.expected = expect;
    }

    public HasSameItemsAsListMatcher<T> useWrapperFactory(WrapperFactory<T> wrapperFactory) {
        if (wrapperFactory == null) {
            throw new IllegalArgumentException("Wrapper factory can't be null");
        }
        this.wrapperFactory = wrapperFactory;
        return this;
    }

    public HasSameItemsAsListMatcher<T> sameSorted() {
        sortcheck = true;
        return this;
    }


    @Override
    protected boolean matchesSafely(List<? extends T> actual, Description mismatchDescription) {
        LambdaList<Wrapper<T>> wrappedActual = with(actual).convert(wrap(actual, wrapperFactory));