001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.legacy.exception;
018
019import org.apache.commons.math4.legacy.exception.util.Localizable;
020
021/**
022 * Base class for exceptions raised by a wrong number.
023 * This class is not intended to be instantiated directly: it should serve
024 * as a base class to create all the exceptions that are raised because some
025 * precondition is violated by a number argument.
026 *
027 * @since 2.2
028 */
029public class MathIllegalNumberException extends MathIllegalArgumentException {
030
031    /** Helper to avoid boxing warnings. @since 3.3 */
032    protected static final Integer INTEGER_ZERO = Integer.valueOf(0);
033
034    /** Serializable version Id. */
035    private static final long serialVersionUID = -7447085893598031110L;
036
037    /** Requested. */
038    private final Number argument;
039
040    /**
041     * Construct an exception.
042     *
043     * @param pattern Localizable pattern.
044     * @param wrong Wrong number.
045     * @param arguments Arguments.
046     */
047    protected MathIllegalNumberException(Localizable pattern,
048                                         Number wrong,
049                                         Object... arguments) {
050        super(pattern, wrong, arguments);
051        argument = wrong;
052    }
053
054    /**
055     * @return the requested value.
056     */
057    public Number getArgument() {
058        return argument;
059    }
060}