<commit_before>/*
 * ******************************************************************************
 *  Copyright 2011-2015 CovertJaguar
 *
 *  This work (the API) is licensed under the "MIT" License, see LICENSE.md for details.
 * ***************************************************************************
 */

package mods.railcraft.api.core.items;

import com.google.common.base.Predicate;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * This class is used to provide a convenient means of dealing with entire classes of items without having to specify each item individually.
 *
 * @author CovertJaguar <http://www.railcraft.info>
 */
@SuppressWarnings("unused")
public class StackFilter implements IStackFilter {
    /**
     * Railcraft adds the following IItemTypes during preInit: ALL, FUEL, TRACK, MINECART, BALLAST, FEED
     * <p/>
     * Feel free to grab them from here or define your own.
     */
    public static final Map<String, IStackFilter> standardFilters = new HashMap<String, IStackFilter>();

    @Override
    public boolean apply(@Nullable final ItemStack input) {
        return true;
    }

    @Override
    public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
        Objects.requireNonNull(other);
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                for (Predicate<? super ItemStack> filter : other) {
                    if (!filter.apply(stack))
                        return false;
                }
                return StackFilter.this.apply(stack);
            }
        };
    }

    @Override
    public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
        Objects.requireNonNull(other);
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                for (Predicate<? super ItemStack> filter : other) {
                    if (filter.apply(stack))
                        return true;
                }
                return StackFilter.this.apply(stack);
            }
        };
    }

    @Override
    public final StackFilter negate() {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                return !StackFilter.this.apply(stack);
            }
        };
    }

    public static StackFilter buildAnd(@Nonnull final Predicate<? super ItemStack>... filters) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                Objects.requireNonNull(stack);
                for (Predicate<? super ItemStack> filter : filters) {
                    if (!filter.apply(stack))
                        return false;
                }
                return true;
            }
        };
    }

    public static StackFilter buildOr(@Nonnull final Predicate<? super ItemStack>... filters) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                Objects.requireNonNull(stack);
                for (Predicate<? super ItemStack> filter : filters) {
                    if (filter.apply(stack))
                        return true;
                }
                return false;
            }
        };
    }

    public static StackFilter invert(@Nonnull final Predicate<? super ItemStack> filter) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                return !filter.apply(stack);
            }
        };
    }

}<commit_msg>Update stack filter to add an "anyOf" option, for multiple phantom slots in inventories.<commit_after>/*
 * ******************************************************************************
 *  Copyright 2011-2015 CovertJaguar
 *
 *  This work (the API) is licensed under the "MIT" License, see LICENSE.md for details.
 * ***************************************************************************
 */

package mods.railcraft.api.core.items;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;

import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * This class is used to provide a convenient means of dealing with entire classes of items without having to specify each item individually.
 *
 * @author CovertJaguar <http://www.railcraft.info>
 */
@SuppressWarnings("unused")
public class StackFilter implements IStackFilter {
    /**
     * Railcraft adds the following IItemTypes during preInit: ALL, FUEL, TRACK, MINECART, BALLAST, FEED
     * <p/>
     * Feel free to grab them from here or define your own.
     */
    public static final Map<String, IStackFilter> standardFilters = new HashMap<String, IStackFilter>();

    @Override
    public boolean apply(@Nullable final ItemStack input) {
        return true;
    }

    @Override
    public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
        Objects.requireNonNull(other);
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                for (Predicate<? super ItemStack> filter : other) {
                    if (!filter.apply(stack))
                        return false;
                }
                return StackFilter.this.apply(stack);
            }
        };
    }

    @Override
    public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
        Objects.requireNonNull(other);
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                for (Predicate<? super ItemStack> filter : other) {
                    if (filter.apply(stack))
                        return true;
                }
                return StackFilter.this.apply(stack);
            }
        };
    }

    @Override
    public final StackFilter negate() {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                return !StackFilter.this.apply(stack);
            }
        };
    }

    public static StackFilter buildAnd(@Nonnull final Predicate<? super ItemStack>... filters) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                Objects.requireNonNull(stack);
                for (Predicate<? super ItemStack> filter : filters) {
                    if (!filter.apply(stack))
                        return false;
                }
                return true;
            }
        };
    }

    public static StackFilter buildOr(@Nonnull final Predicate<? super ItemStack>... filters) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                Objects.requireNonNull(stack);
                for (Predicate<? super ItemStack> filter : filters) {
                    if (filter.apply(stack))
                        return true;
                }
                return false;
            }
        };
    }

    public static StackFilter invert(@Nonnull final Predicate<? super ItemStack> filter) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack stack) {
                return !filter.apply(stack);
            }
        };
    }

    public static StackFilter anyOf(@Nonnull final ItemStack[] stacks) {
        return new StackFilter() {
            @Override
            public boolean apply(ItemStack input) {
                for (ItemStack stack : stacks) {
                    if (ItemStack.areItemStacksEqual(stack, input)) return true;
                }
                return false;
            }
        };
    }
}
{'fraction_non_alphanumeric': 0.12298736685657667, 'fraction_numerical': 0.0019816695566014365, 'mean_word_length': 1.9172687861271676, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '405939', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1898, 'n_words': 571}