<commit_before>// Copyright 2014 takahashikzn
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jp.root42.indolently;

import java.util.Collection;
import java.util.Comparator;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import jp.root42.indolently.ref.IntRef;
import jp.root42.indolently.trait.EdgeAwareIterable;
import jp.root42.indolently.trait.Filterable;
import jp.root42.indolently.trait.Freezable;
import jp.root42.indolently.trait.Identical;
import jp.root42.indolently.trait.Loopable;
import jp.root42.indolently.trait.Matchable;
import jp.root42.indolently.trait.ReducibleIterable;

import static jp.root42.indolently.Indolently.*;


/**
 * common method definition for {@link SSet} / {@link SList}.
 * The name is came from "Sugared Collection".
 *
 * @param <T> value type
 * @param <SELF> self type
 * @author takahashikzn
 * @see SList
 * @see SSet
 */
public interface SCol<T, SELF extends SCol<T, SELF>>
    extends Collection<T>, EdgeAwareIterable<T>, ReducibleIterable<T>, Freezable<SELF>, Identical<SELF>,
    Loopable<T, SELF>, Filterable<T, SELF>, Matchable<T> {

    /**
     * add value then return this instance.
     *
     * @param value value to add
     * @return {@code this} instance
     */
    @Destructive
    default SELF push(final T value) {
        this.add(value);
        return this.identity();
    }

    /**
     * add all values then return this instance.
     *
     * @param values values to add
     * @return {@code this} instance
     */
    @Destructive
    default SELF pushAll(final Iterable<? extends T> values) {
        for (final T val : values) {
            this.add(val);<commit_msg>add put(T, Predicate<T>), putAll(Iterable<T>, Predicate<Iterable<T>>)<commit_after>// Copyright 2014 takahashikzn
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jp.root42.indolently;

import java.util.Collection;
import java.util.Comparator;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import jp.root42.indolently.ref.IntRef;
import jp.root42.indolently.trait.EdgeAwareIterable;
import jp.root42.indolently.trait.Filterable;
import jp.root42.indolently.trait.Freezable;
import jp.root42.indolently.trait.Identical;
import jp.root42.indolently.trait.Loopable;
import jp.root42.indolently.trait.Matchable;
import jp.root42.indolently.trait.ReducibleIterable;

import static jp.root42.indolently.Indolently.*;


/**
 * common method definition for {@link SSet} / {@link SList}.
 * The name is came from "Sugared Collection".
 *
 * @param <T> value type
 * @param <SELF> self type
 * @author takahashikzn
 * @see SList
 * @see SSet
 */
public interface SCol<T, SELF extends SCol<T, SELF>>
    extends Collection<T>, EdgeAwareIterable<T>, ReducibleIterable<T>, Freezable<SELF>, Identical<SELF>,
    Loopable<T, SELF>, Filterable<T, SELF>, Matchable<T> {

    /**
     * add value then return this instance.
     *
     * @param value value to add
     * @return {@code this} instance
     */
    @Destructive
    default SELF push(final T value) {
        return this.push(value, x -> true);
    }

    /**
     * add all values then return this instance.
     *
     * @param values values to add
     * @return {@code this} instance
     */
    @Destructive
    default SELF pushAll(final Iterable<? extends T> values) {
        return this.pushAll(values, x -> true);
    }

    /**
     * add value then return this instance only if condition satisfied.
     *
     * @param value value to add
     * @param f condition
     * @return {@code this} instance
     */
    @Destructive
    default SELF push(final T value, final Predicate<? super T> f) {
        if (f.test(value)) {
            this.add(value);
        }

        return this.identity();
    }

    /**
     * add all values then return this instance only if condition satisfied.
     *
     * @param values values to add
     * @param f condition
     * @return {@code this} instance
     */
    @Destructive
    default SELF pushAll(final Iterable<? extends T> values, final Predicate<? super Iterable<? extends T>> f) {
        if (f.test(values)) {
            for (final T val : values) {
                this.add(val);
            }
{'fraction_non_alphanumeric': 0.11054637865311309, 'fraction_numerical': 0.010165184243964422, 'mean_word_length': 3.2352036894696385, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, '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': '5926927', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1704, 'n_words': 526}