<commit_before>/*****************************************************************************
 * Copyright (C) mu.org                                                *
 * ------------------------------------------------------------------------- *
 * 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 org.mu.util;

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * Configures an abstract plan based on exceptions.
 * 
 * This class is immutable.
 *
 * Each exceptional rule is configured with a list of abstract strategies.
 * Users are expected to use the continuation returned by {@link #execute} upon any exception.
 *
 * The returned {@link Execution} includes both the current strategy for the exception in
 * question, and a new {@code ExeceptionPlan} object for upcoming exceptions in the same logical
 * group (such as exceptions thrown by the same method invocation in a retry).
 *
 * <p>For {@link Retryer}, {@code T} can be {@link java.time.Duration} of delay between retries.
 * But other users can potentially use any strategy type.
 * 
 * <p>Strategies specified through {@link #upon} are picked with
 * respect to the order they are added. Think of them as a bunch of
 * {@code if ... else if ...}. That is, <em>always specify the more specific exception first</em>.
 * The following code is wrong because the {@code IOException} strategies will always be
 * overshadowed by the {@code Exception} strategies.
 * <pre>{@code
 * ExceptionPlan<Duration> = new ExceptionPlan<Duration>()
 *     .upon(Exception.class, exponentialBackoff(...))
 *     .upon(IOException.class, uniformDelay(...));
 * }</pre>
 */
final class ExceptionPlan<T> {
<commit_msg>Update ExceptionPlan doc<commit_after>/*****************************************************************************
 * Copyright (C) mu.org                                                *
 * ------------------------------------------------------------------------- *
 * 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 org.mu.util;

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * Configures an abstract plan based on exceptions.
 * 
 * This class is immutable.
 *
 * Each exceptional rule is configured with a list of abstract strategies.
 * Users are expected to use the continuation returned by {@link #execute} upon any exception.
 *
 * The returned {@link Execution} includes both the current strategy for the exception in
 * question, and a new {@code ExeceptionPlan} object for upcoming exceptions in the same logical
 * group (such as exceptions thrown by the same method invocation in a retry).
 *
 * <p>For {@link Retryer}, {@code T} can be {@link Delay} between retries. But any strategy types
 * work too.
 * 
 * <p>Strategies specified through {@link #upon} are picked with
 * respect to the order they are added. Think of them as a bunch of
 * {@code if ... else if ...}. That is, <em>always specify the more specific exception first</em>.
 * The following code is wrong because the {@code IOException} strategies will always be
 * overshadowed by the {@code Exception} strategies.
 * <pre>{@code
 * ExceptionPlan<Duration> = new ExceptionPlan<Duration>()
 *     .upon(Exception.class, exponentialBackoff(...))
 *     .upon(IOException.class, uniformDelay(...));
 * }</pre>
 */
final class ExceptionPlan<T> {

{'fraction_non_alphanumeric': 0.1629327902240326, 'fraction_numerical': 0.0014812071838548417, 'mean_word_length': 2.181389870435807, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '128484', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1137, 'n_words': 519}