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

📄 removing.java

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

import com.reddragon2046.base.utilities.data.*;
import com.reddragon2046.base.utilities.data.predicates.ConstantPredicate;
import com.reddragon2046.base.utilities.data.util.InsertIterator;
import com.reddragon2046.base.utilities.data.util.IteratorFactory;
import java.util.Collection;
import java.util.List;

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

public final class Removing
{

    private Removing()
    {
    }

    private static ForwardIterator remove(ForwardIterator first, ForwardIterator last, Object object)
    {
        if(!first.isCompatibleWith(last))
            throw new IllegalArgumentException("iterators not compatible");
        if(!(first.getContainer() instanceof Sequence))
            throw new IllegalArgumentException("iterator containers must be a Sequence");
        first = (ForwardIterator)Finding.find(first, last, object);
        ForwardIterator i = (ForwardIterator)first.clone();
        if(i.equals(last))
        {
            return i;
        } else
        {
            i.advance();
            return (ForwardIterator)removeCopy(i, last, first, object);
        }
    }

    public static ForwardIterator removeMatching(List list, Object object)
    {
        return remove(IteratorFactory.start(list), IteratorFactory.finish(list), object);
    }

    public static ForwardIterator removeIf(ForwardIterator first, ForwardIterator last, UnaryPredicate predicate)
    {
        if(!first.isCompatibleWith(last))
            throw new IllegalArgumentException("iterators not compatible");
        first = (ForwardIterator)Finding.findIf(first, last, predicate);
        if(first.equals(last))
        {
            return first;
        } else
        {
            ForwardIterator i = (ForwardIterator)first.clone();
            i.advance();
            return (ForwardIterator)removeCopyIf(i, last, first, predicate);
        }
    }

    public static ForwardIterator removeIf(List list, UnaryPredicate predicate)
    {
        return removeIf(((ForwardIterator) (IteratorFactory.start(list))), ((ForwardIterator) (IteratorFactory.finish(list))), predicate);
    }

    public static ForwardIterator remove(List list)
    {
        return removeIf(list, new ConstantPredicate(true));
    }

    public static OutputIterator removeCopy(InputIterator first, InputIterator last, OutputIterator result, Object object)
    {
        if(!first.isCompatibleWith(last))
            throw new IllegalArgumentException("iterators not compatible");
        InputIterator firstx = (InputIterator)first.clone();
        OutputIterator resultx = (OutputIterator)result.clone();
        for(; !firstx.equals(last); firstx.advance())
        {
            Object one = firstx.get();
            if(one != null ? !one.equals(object) : object != null)
            {
                resultx.put(one);
                resultx.advance();
            }
        }

        return resultx;
    }

    public static OutputIterator removeCopy(Collection collection, OutputIterator result, Object object)
    {
        return removeCopy(IteratorFactory.start(collection), IteratorFactory.finish(collection), result, object);
    }

    public static void removeCopy(Collection source, Collection destination, Object object)
    {
        removeCopy(IteratorFactory.start(source), IteratorFactory.finish(source), ((OutputIterator) (new InsertIterator(destination))), object);
    }

    public static OutputIterator removeCopyIf(InputIterator first, InputIterator last, OutputIterator result, UnaryPredicate predicate)
    {
        if(!first.isCompatibleWith(last))
            throw new IllegalArgumentException("iterators not compatible");
        InputIterator firstx = (InputIterator)first.clone();
        OutputIterator resultx = (OutputIterator)result.clone();
        for(; !firstx.equals(last); firstx.advance())
            if(!predicate.execute(firstx.get()))
            {
                resultx.put(firstx.get());
                resultx.advance();
            }

        return resultx;
    }

    public static OutputIterator removeCopyIf(Collection collection, OutputIterator result, UnaryPredicate predicate)
    {
        return removeCopyIf(IteratorFactory.start(collection), IteratorFactory.finish(collection), result, predicate);
    }

    public static void removeCopyIf(Collection source, Collection destination, UnaryPredicate predicate)
    {
        removeCopyIf(IteratorFactory.start(source), IteratorFactory.finish(source), ((OutputIterator) (new InsertIterator(destination))), predicate);
    }
}

⌨️ 快捷键说明

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