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.math3.exception;
018
019import org.apache.commons.math3.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 * @version $Id: MathIllegalNumberException.java 1505931 2013-07-23 08:37:39Z luc $
029 */
030public class MathIllegalNumberException extends MathIllegalArgumentException {
031
032    /** Helper to avoid boxing warnings. @since 3.3 */
033    protected static final Integer INTEGER_ZERO = Integer.valueOf(0);
034
035    /** Serializable version Id. */
036    private static final long serialVersionUID = -7447085893598031110L;
037
038    /** Requested. */
039    private final Number argument;
040
041    /**
042     * Construct an exception.
043     *
044     * @param pattern Localizable pattern.
045     * @param wrong Wrong number.
046     * @param arguments Arguments.
047     */
048    protected MathIllegalNumberException(Localizable pattern,
049                                         Number wrong,
050                                         Object ... arguments) {
051        super(pattern, wrong, arguments);
052        argument = wrong;
053    }
054
055    /**
056     * @return the requested value.
057     */
058    public Number getArgument() {
059        return argument;
060    }
061}