⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minmax.java

📁 java 的源代码
💻 JAVA
字号:
package com.reddragon2046.base.utilities.data.algorithms;

import com.reddragon2046.base.utilities.data.BinaryPredicate;
import com.reddragon2046.base.utilities.data.InputIterator;
import com.reddragon2046.base.utilities.data.util.IteratorFactory;
import java.util.Collection;

// Referenced classes of package com.reddragon2046.base.utilities.data.algorithms:
//            Predicates

public final class MinMax
{

    private MinMax()
    {
    }

    private static Object maxElement(InputIterator first, InputIterator last)
    {
        return maxElement(first, last, ((BinaryPredicate) (new Predicates.HashComparator())));
    }

    public static Object maxElement(Collection collection)
    {
        return maxElement(IteratorFactory.start(collection), IteratorFactory.finish(collection), ((BinaryPredicate) (new Predicates.HashComparator())));
    }

    private static Object maxElement(InputIterator first, InputIterator last, BinaryPredicate comparator)
    {
        if(!first.isCompatibleWith(last))
            throw new IllegalArgumentException("iterators not compatible");
        InputIterator firstx = (InputIterator)first.clone();
        if(firstx.equals(last))
            return firstx;
        InputIterator result = (InputIterator)firstx.clone();
        firstx.advance();
        int i = 0;
        for(; !firstx.equals(last); firstx.advance())
            if(comparator.execute(result.get(), firstx.get()))
                result = (InputIterator)firstx.clone();

        return result.get();
    }

    public static Object maxElement(Collection collection, BinaryPredicate comparator)
    {
        return maxElement(IteratorFactory.start(collection), IteratorFactory.finish(collection), comparator);
    }

    private static Object minElement(InputIterator first, InputIterator last)
    {
        return minElement(first, last, ((BinaryPredicate) (new Predicates.HashComparator())));
    }

    public static Object minElement(Collection collection)
    {
        return minElement(IteratorFactory.start(collection), IteratorFactory.finish(collection), ((BinaryPredicate) (new Predicates.HashComparator())));
    }

    private static Object minElement(InputIterator first, InputIterator last, BinaryPredicate comparator)
    {
        if(!first.isCompatibleWith(last))
            throw new IllegalArgumentException("iterators not compatible");
        InputIterator firstx = (InputIterator)first.clone();
        if(firstx.equals(last))
            return firstx;
        InputIterator result = (InputIterator)firstx.clone();
        firstx.advance();
        for(; !firstx.equals(last); firstx.advance())
            if(comparator.execute(firstx.get(), result.get()))
                result = (InputIterator)firstx.clone();

        return result.get();
    }

    public static Object minElement(Collection collection, BinaryPredicate comparator)
    {
        return minElement(IteratorFactory.start(collection), IteratorFactory.finish(collection), comparator);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -