001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2023–2025 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
006 * the License. You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
012 * specific language governing permissions and limitations under the License.
013 */
014package org.microbean.bean;
015
016/**
017 * A {@link BeanException} concerning problematic <dfn>reductions</dfn>.
018 *
019 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
020 *
021 * @see Reducible
022 *
023 * @see Reducer
024 */
025public class ReductionException extends BeanException {
026
027  private static final long serialVersionUID = 1L;
028
029  private final transient Object criteria;
030
031  /**
032   * Creates a new {@link ReductionException}.
033   *
034   * @param criteria an {@link Object} representing reduction criteria; may be {@code null}
035   *
036   * @param message a detail message; may be {@code null}
037   *
038   * @param cause a {@link Throwable} that caused this {@link ReductionException} to be created; may be {@code null}
039   */
040  public ReductionException(final Object criteria, final String message, final Throwable cause) {
041    super(message, cause);
042    this.criteria = criteria;
043  }
044
045  /**
046   * Returns this {@link ReductionException}'s criteria object, which may be {@code null}.
047   *
048   * @return this {@link ReductionException}'s criteria object, which may be {@code null}
049   */
050  public final Object criteria() {
051    return this.criteria;
052  }
053
054  /**
055   * Returns a {@link String} reprsentation of this {@link ReductionException}.
056   *
057   * @return a {@link String} reprsentation of this {@link ReductionException}; never {@code null}
058   */
059  @Override
060  public String toString() {
061    final Object criteria = this.criteria();
062    return criteria == null ? super.toString() : super.toString() + ": criteria: " + criteria;
063  }
064
065}