All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bestvike.linq.enumerable.OrderBy Maven / Gradle / Ivy

The newest version!
package com.bestvike.linq.enumerable;

import com.bestvike.function.Func1;
import com.bestvike.linq.IEnumerable;
import com.bestvike.linq.IOrderedEnumerable;
import com.bestvike.linq.exception.ExceptionArgument;
import com.bestvike.linq.exception.ThrowHelper;

import java.util.Comparator;

/**
 * Created by 许崇雷 on 2018-05-03.
 */
public final class OrderBy {
    private OrderBy() {
    }

    public static  IOrderedEnumerable orderBy(IEnumerable source, Func1 keySelector) {
        return new OrderedEnumerable<>(source, keySelector, null, false, null);
    }

    public static  IOrderedEnumerable orderBy(IEnumerable source, Func1 keySelector, Comparator comparer) {
        return new OrderedEnumerable<>(source, keySelector, comparer, false, null);
    }

    public static  IOrderedEnumerable orderByDescending(IEnumerable source, Func1 keySelector) {
        return new OrderedEnumerable<>(source, keySelector, null, true, null);
    }

    public static  IOrderedEnumerable orderByDescending(IEnumerable source, Func1 keySelector, Comparator comparer) {
        return new OrderedEnumerable<>(source, keySelector, comparer, true, null);
    }

    public static  IOrderedEnumerable thenBy(IOrderedEnumerable source, Func1 keySelector) {
        if (source == null)
            ThrowHelper.throwArgumentNullException(ExceptionArgument.source);

        return source.createOrderedEnumerable(keySelector, null, false);
    }

    public static  IOrderedEnumerable thenBy(IOrderedEnumerable source, Func1 keySelector, Comparator comparer) {
        if (source == null)
            ThrowHelper.throwArgumentNullException(ExceptionArgument.source);

        return source.createOrderedEnumerable(keySelector, comparer, false);
    }

    public static  IOrderedEnumerable thenByDescending(IOrderedEnumerable source, Func1 keySelector) {
        if (source == null)
            ThrowHelper.throwArgumentNullException(ExceptionArgument.source);

        return source.createOrderedEnumerable(keySelector, null, true);
    }

    public static  IOrderedEnumerable thenByDescending(IOrderedEnumerable source, Func1 keySelector, Comparator comparer) {
        if (source == null)
            ThrowHelper.throwArgumentNullException(ExceptionArgument.source);

        return source.createOrderedEnumerable(keySelector, comparer, true);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy