package org.xbib.datastructures.immutable.order;

import java.util.List;
import org.xbib.datastructures.immutable.ImmutableList;

/**
 * An ordering that treats all references as equals, even nulls.
 */
final class AllEqualOrdering extends Ordering<Object> {
    static final AllEqualOrdering INSTANCE = new AllEqualOrdering();

    @Override
    public int compare(Object left, Object right) {
        return 0;
    }

    @Override
    public <E> List<E> sortedCopy(Iterable<E> iterable) {
        return ImmutableList.newArrayList(iterable.iterator());
    }

    @Override
    @SuppressWarnings("nullness") // unsafe: see supertype
    public <E> ImmutableList<E> immutableSortedCopy(Iterable<E> iterable) {
        return ImmutableList.copyOf(iterable);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <S> Ordering<S> reverse() {
        return (Ordering<S>) this;
    }

    @Override
    public String toString() {
        return "Ordering.allEqual()";
    }
}
