<commit_before>/*
 * Copyright 2016 <NAME> <<EMAIL>>.
 *
 * This file is part of business-flows.
 *
 * 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 io.github.theangrydev.businessflows;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static java.lang.String.format;

/**
 * This class provides convenience methods for accessing an {@link Optional} that would otherwise be obtained by calling
 * the {@link WithOptional#toOptional()} method.
 *
 * @param <Content> The type of content that may be held
 */
public interface WithOptional<Content> {

    /**
     * @return The {@link Optional} {@link Content}
     */
    Optional<Content> toOptional();

    /**
     * @return If the {@link Content} is present then the {@link Content}, else an {@link IllegalStateException}
     * @throws IllegalStateException If the underlying {@link Content} is not present
     */
    default Content get() {
        return orElseThrow(() -> new IllegalStateException(format("Not present. This is: '%s'.", this)));
    }

    /**
     * @param alternative The result if the {@link Content} is not present
     * @return If {@link Content} is present then the {@link Content}, else the given alternative
     */
    default Content orElse(Content alternative) {
        return toOptional().orElse(alternative);
    }

    /**
     * @param alternativeSupplier The supplier of the alternative result if the {@link Content} is not present
     * @return If the {@link Content} is present then the {@link Content}, else the given alternative
     */
    default Content orElseGet(Supplier<Content> alternativeSupplier) {
        return toOptional().orElseGet(alternativeSupplier);<commit_msg>Annotate WithOptional with @FunctionalInterface since it has a single abstract method<commit_after>/*
 * Copyright 2016 <NAME> <<EMAIL>>.
 *
 * This file is part of business-flows.
 *
 * 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 io.github.theangrydev.businessflows;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static java.lang.String.format;

/**
 * This class provides convenience methods for accessing an {@link Optional} that would otherwise be obtained by calling
 * the {@link WithOptional#toOptional()} method.
 *
 * @param <Content> The type of content that may be held
 */
@FunctionalInterface
public interface WithOptional<Content> {

    /**
     * @return The {@link Optional} {@link Content}
     */
    Optional<Content> toOptional();

    /**
     * @return If the {@link Content} is present then the {@link Content}, else an {@link IllegalStateException}
     * @throws IllegalStateException If the underlying {@link Content} is not present
     */
    default Content get() {
        return orElseThrow(() -> new IllegalStateException(format("Not present. This is: '%s'.", this)));
    }

    /**
     * @param alternative The result if the {@link Content} is not present
     * @return If {@link Content} is present then the {@link Content}, else the given alternative
     */
    default Content orElse(Content alternative) {
        return toOptional().orElse(alternative);
    }

    /**
     * @param alternativeSupplier The supplier of the alternative result if the {@link Content} is not present
     * @return If the {@link Content} is present then the {@link Content}, else the given alternative
     */
    default Content orElseGet(Supplier<Content> alternativeSupplier) {
        return toOptional().orElseGet(alternativeSupplier);
{'fraction_non_alphanumeric': 0.09714659115661076, 'fraction_numerical': 0.003485079503376171, 'mean_word_length': 3.6857142857142855, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '4627579', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1149, 'n_words': 502}