<commit_before>/*
 * jlib - The Free Java Library
 * 
 * http://www.jlib.org
 * 
 * Copyright (c) 2006-2008 <NAME>
 * 
 * jlib is distributed under the
 * 
 * COMMON PUBLIC LICENSE VERSION 1.0
 * 
 * http://www.opensource.org/licenses/cpl1.0.php
 */

package org.jlib.container;

import java.util.Collection;
import java.util.Set;

import org.jlib.container.collection.CollectionUtility;
import org.jlib.core.traverser.RemoveTraverser;

/**
 * Utility class providing methods operating on {@link Container Containers}.
 * 
 * @author <NAME>
 */
public final class ContainerUtility {

    /** No visible constructor. */
    private ContainerUtility() {}

    /**
     * Adds all Items provided by the specified {@link Iterable} to the
     * specified {@link AddContainer}.
     * 
     * @param container
     *        {@link AddContainer} to which the Items are added
     * 
     * @param items
     *        {@link Iterable} providing the Items to add
     */
    public static <Item> void addAll(final AddContainer<Item> container, final Iterable<? extends Item> items) {
        for (final Item item : items)
            container.add(item);
    }

    /**
     * Removes all Items provided by the specified {@link Iterable} from the
     * specified {@link AddContainer}.
     * 
     * @param container
     *        {@link AddContainer} containing the Items
     * 
     * @param items
     *        {@link Iterable} providing the Items to remove
     */
    public static <Item> void removeAll(final RemoveContainer<Item> container, final Iterable<? extends Item> items) {
        for (final Item item : items)
            container.remove(item);
    }

    /**
     * Removes all Items from the specified {@link AddContainer} <i>except</i>
     * the Items provided by the specified {@link Iterable}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items to remove
     * 
     * @param items
     *        {@link Iterable} providing the Items to retain
     */
    public static <Item> void retainAll(final RemoveContainer<Item> container, final Iterable<? extends Item> items) {
        final Set<Item> retainedItemsSet = CollectionUtility.toSet(items);

        final RemoveTraverser<Item> containerTraverser = container.createTraverser();
        while (containerTraverser.isNextItemAccessible())
            if (!retainedItemsSet.contains(containerTraverser.getNextItem()))
                containerTraverser.remove();
    }

    /**
     * Removes all Items from the specified {@link AddContainer} <i>except</i>
     * for the Items contained by the specified {@link Collection}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items to remove
     * 
     * @param items
     *        {@link Collection} containing the Items to retain
     */
    public static <Item> void retainAll(final RemoveContainer<Item> container, final Collection<? extends Item> items) {
        final RemoveTraverser<Item> itemsTraverser = container.createTraverser();
        while (itemsTraverser.isNextItemAccessible())
            if (!items.contains(itemsTraverser.getNextItem()))
                itemsTraverser.remove();
    }

    /**
     * Removes all Items from the specified {@link AddContainer} <i>except</i>
     * for the Items contained by the specified {@link Collection}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items to remove
     * 
     * @param items
     *        {@link Collection} containing the Items to retain
     */
    public static <Item, RetainedItem extends Item> void retainAll(final RemoveContainer<Item> container,
                                                                   @SuppressWarnings({ "unchecked", /* "varargs" */}) final RetainedItem... items) {
        // necessary as we need the contains() method fot the items sequence
        retainAll(container, CollectionUtility.toSet(items));
    }
}<commit_msg>ContainerUtility: ... methods added<commit_after>/*
 * jlib - The Free Java Library
 * 
 * http://www.jlib.org
 * 
 * Copyright (c) 2006-2008 <NAME>
 * 
 * jlib is distributed under the
 * 
 * COMMON PUBLIC LICENSE VERSION 1.0
 * 
 * http://www.opensource.org/licenses/cpl1.0.php
 */

package org.jlib.container;

import java.util.Collection;
import java.util.Set;

import org.jlib.container.collection.CollectionUtility;
import org.jlib.core.traverser.RemoveTraverser;

/**
 * Utility class providing methods operating on {@link Container Containers}.
 * 
 * @author <NAME>
 */
public final class ContainerUtility {

    /** No visible constructor. */
    private ContainerUtility() {}

    /**
     * Adds all Items provided by the specified {@link Iterable} to the
     * specified {@link AddContainer}.
     * 
     * @param container
     *        {@link AddContainer} to which the Items are added
     * 
     * @param newItems
     *        {@link Iterable} providing the Items to add
     */
    public static <Item> void addAll(final AddContainer<Item> container, final Iterable<? extends Item> newItems) {
        for (final Item newItem : newItems)
            container.add(newItem);
    }

    /**
     * Adds all Items in the specified comma separated sequence to the specified
     * {@link AddContainer}.
     * 
     * @param container
     *        {@link AddContainer} to which the Items are added
     * 
     * @param newItems
     *        {@link Iterable} providing the Items to add
     */
    @SafeVarargs
    public static <Item> void addAll(final AddContainer<Item> container, final Item... newItems) {
        for (final Item newItem : newItems)
            container.add(newItem);
    }

    /**
     * Removes all Items provided by the specified {@link Iterable} from the
     * specified {@link RemoveContainer}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items
     * 
     * @param items
     *        {@link Iterable} providing the Items to remove
     */
    public static <Item> void removeAll(final RemoveContainer<Item> container, final Iterable<? extends Item> items) {
        for (final Item item : items)
            container.remove(item);
    }

    /**
     * Removes all Items in the specified comma separated sequence from the
     * specified {@link RemoveContainer}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items
     * 
     * @param items
     *        {@link Iterable} providing the Items to remove
     */
    @SafeVarargs
    public static <Item> void removeAll(final RemoveContainer<Item> container, final Item... items) {
        for (final Item item : items)
            container.remove(item);
    }

    /**
     * Removes all Items from the specified {@link AddContainer} <i>except</i>
     * the Items provided by the specified {@link Iterable}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items to remove
     * 
     * @param items
     *        {@link Iterable} providing the Items to retain
     */
    public static <Item> void retainAll(final RemoveContainer<Item> container, final Iterable<? extends Item> items) {
        final Set<Item> retainedItemsSet = CollectionUtility.toSet(items);

        final RemoveTraverser<Item> containerTraverser = container.createTraverser();
        while (containerTraverser.isNextItemAccessible())
            if (!retainedItemsSet.contains(containerTraverser.getNextItem()))
                containerTraverser.remove();
    }

    /**
     * Removes all Items from the specified {@link AddContainer} <i>except</i>
     * for the Items contained by the specified {@link Collection}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items to remove
     * 
     * @param items
     *        {@link Collection} containing the Items to retain
     */
    public static <Item> void retainAll(final RemoveContainer<Item> container, final Collection<? extends Item> items) {
        final RemoveTraverser<Item> itemsTraverser = container.createTraverser();
        while (itemsTraverser.isNextItemAccessible())
            if (!items.contains(itemsTraverser.getNextItem()))
                itemsTraverser.remove();
    }

    /**
     * Removes all Items from the specified {@link AddContainer} <i>except</i>
     * for the Items contained by the specified {@link Collection}.
     * 
     * @param container
     *        {@link RemoveContainer} containing the Items to remove
     * 
     * @param items
     *        {@link Collection} containing the Items to retain
     */
    @SafeVarargs
    public static <Item, RetainedItem extends Item> void retainAll(final RemoveContainer<Item> container,
                                                                   final RetainedItem... items) {
        // necessary as we need the contains() method fot the items sequence
        retainAll(container, CollectionUtility.toSet(items));
    }
}
{'fraction_non_alphanumeric': 0.09744960463303264, 'fraction_numerical': 0.0026729034413631807, 'mean_word_length': 2.4725444702242845, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3634308', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2333, 'n_words': 763}